summaryrefslogtreecommitdiffstats
path: root/Source/cmMakefile.cxx
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2013-06-04 08:30:24 (GMT)
committerStephen Kelly <steveire@gmail.com>2013-06-04 09:36:55 (GMT)
commita984f3257e95f29a72da6566859d4c6a8a5d749b (patch)
treef174238c2d4c5b582fd5f892ea1c64e2b8418c06 /Source/cmMakefile.cxx
parent00c3840cc8c36adea76c6e833a9e2069645aec8a (diff)
downloadCMake-a984f3257e95f29a72da6566859d4c6a8a5d749b.zip
CMake-a984f3257e95f29a72da6566859d4c6a8a5d749b.tar.gz
CMake-a984f3257e95f29a72da6566859d4c6a8a5d749b.tar.bz2
Introduce add_compile_options command.
This command is similar to add_definitions, in that it affects the compile options of all targets which follow it. The implementation is similar to the implementation of the include_directories command, in that it is based on populating a COMPILE_OPTIONS directory property and using that to initialize the same property on targets. Unlike the include_directories command however, the add_compile_options command does not affect previously defined targets. That is, in the following code, foo will not be compiled with -Wall, but bar will be: add_library(foo ...) add_compile_options(-Wall) add_library(bar ...)
Diffstat (limited to 'Source/cmMakefile.cxx')
-rw-r--r--Source/cmMakefile.cxx60
1 files changed, 60 insertions, 0 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 606ec93..e1c1241 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -21,6 +21,7 @@
#include "cmCacheManager.h"
#include "cmFunctionBlocker.h"
#include "cmListFileCache.h"
+#include "cmDocumentGeneratorExpressions.h"
#include "cmCommandArgumentParserHelper.h"
#include "cmDocumentCompileDefinitions.h"
#include "cmGeneratorExpression.h"
@@ -1270,6 +1271,11 @@ void cmMakefile::RemoveDefineFlag(const char* flag,
}
}
+void cmMakefile::AddCompileOption(const char* option)
+{
+ this->AppendProperty("COMPILE_OPTIONS", option);
+}
+
bool cmMakefile::ParseDefineFlag(std::string const& def, bool remove)
{
// Create a regular expression to match valid definitions.
@@ -1493,6 +1499,12 @@ void cmMakefile::InitializeFromParent()
parentIncludes.begin(),
parentIncludes.end());
+ const std::vector<cmValueWithOrigin> parentOptions =
+ parent->GetCompileOptionsEntries();
+ this->CompileOptionsEntries.insert(this->CompileOptionsEntries.end(),
+ parentOptions.begin(),
+ parentOptions.end());
+
this->SystemIncludeDirectories = parent->SystemIncludeDirectories;
// define flags
@@ -3468,6 +3480,18 @@ void cmMakefile::SetProperty(const char* prop, const char* value)
cmValueWithOrigin(value, lfbt));
return;
}
+ if (propname == "COMPILE_OPTIONS")
+ {
+ this->CompileOptionsEntries.clear();
+ if (!value)
+ {
+ return;
+ }
+ cmListFileBacktrace lfbt;
+ this->GetBacktrace(lfbt);
+ this->CompileOptionsEntries.push_back(cmValueWithOrigin(value, lfbt));
+ return;
+ }
if ( propname == "INCLUDE_REGULAR_EXPRESSION" )
{
@@ -3507,6 +3531,14 @@ void cmMakefile::AppendProperty(const char* prop, const char* value,
cmValueWithOrigin(value, lfbt));
return;
}
+ if (propname == "COMPILE_OPTIONS")
+ {
+ cmListFileBacktrace lfbt;
+ this->GetBacktrace(lfbt);
+ this->CompileOptionsEntries.push_back(
+ cmValueWithOrigin(value, lfbt));
+ return;
+ }
if ( propname == "LINK_DIRECTORIES" )
{
std::vector<std::string> varArgsExpanded;
@@ -3632,6 +3664,20 @@ const char *cmMakefile::GetProperty(const char* prop,
}
return output.c_str();
}
+ else if (!strcmp("COMPILE_OPTIONS",prop))
+ {
+ std::string sep;
+ for (std::vector<cmValueWithOrigin>::const_iterator
+ it = this->CompileOptionsEntries.begin(),
+ end = this->CompileOptionsEntries.end();
+ it != end; ++it)
+ {
+ output += sep;
+ output += it->Value;
+ sep = ";";
+ }
+ return output.c_str();
+ }
bool chain = false;
const char *retVal =
@@ -4003,6 +4049,20 @@ void cmMakefile::DefineProperties(cmake *cm)
"See also the include_directories command.");
cm->DefineProperty
+ ("COMPILE_OPTIONS", cmProperty::DIRECTORY,
+ "List of options to pass to the compiler.",
+ "This property specifies the list of directories given "
+ "so far for this property. "
+ "This property exists on directories and targets. "
+ "\n"
+ "The target property values are used by the generators to set "
+ "the options for the compiler.\n"
+ "Contents of COMPILE_OPTIONS may use \"generator expressions\" with "
+ "the syntax \"$<...>\". "
+ CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS
+ CM_DOCUMENT_LANGUAGE_GENERATOR_EXPRESSIONS);
+
+ cm->DefineProperty
("LINK_DIRECTORIES", cmProperty::DIRECTORY,
"List of linker search directories.",
"This read-only property specifies the list of directories given "