summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2013-05-16 14:59:04 +0200
committerStephen Kelly <steveire@gmail.com>2013-06-02 11:56:36 +0200
commit35496761a58956bd8c5ad65a3ed9ee78d09af56b (patch)
treef02c889f4da5c1da5d9a6eef5d9ea73fbc0f1a16
parentf3ad863ae6f0487bbf80d95b0d3f622840187a6a (diff)
downloadcmake-35496761a58956bd8c5ad65a3ed9ee78d09af56b.tar.gz
Add cmLocalGenerator::GetCompileOptions.
Currently it only adds the contents of the COMPILE_FLAGS target property, but it can be extended to handle a new COMPILE_OPTIONS generator expression enabled property.
-rw-r--r--Source/cmExtraSublimeTextGenerator.cxx8
-rw-r--r--Source/cmGlobalXCodeGenerator.cxx6
-rw-r--r--Source/cmLocalGenerator.cxx12
-rw-r--r--Source/cmLocalGenerator.h3
-rw-r--r--Source/cmLocalVisualStudio6Generator.cxx21
-rw-r--r--Source/cmLocalVisualStudio7Generator.cxx4
-rw-r--r--Source/cmMakefileTargetGenerator.cxx32
-rw-r--r--Source/cmNinjaTargetGenerator.cxx10
-rw-r--r--Source/cmVisualStudio10TargetGenerator.cxx6
9 files changed, 77 insertions, 25 deletions
diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx
index 62e9194e98..29d86a61e1 100644
--- a/Source/cmExtraSublimeTextGenerator.cxx
+++ b/Source/cmExtraSublimeTextGenerator.cxx
@@ -429,7 +429,9 @@ cmExtraSublimeTextGenerator::ComputeFlagsForObject(cmSourceFile* source,
lg->AppendFlags(flags, makefile->GetDefineFlags());
// Add target-specific flags.
- if(target->GetProperty("COMPILE_FLAGS"))
+ std::string targetFlags;
+ lg->GetCompileOptions(targetFlags, target, config);
+ if (!targetFlags.empty())
{
std::string langIncludeExpr = "CMAKE_";
langIncludeExpr += language;
@@ -440,7 +442,7 @@ cmExtraSublimeTextGenerator::ComputeFlagsForObject(cmSourceFile* source,
cmsys::RegularExpression r(regex);
std::vector<std::string> args;
cmSystemTools::
- ParseWindowsCommandLine(target->GetProperty("COMPILE_FLAGS"), args);
+ ParseWindowsCommandLine(targetFlags.c_str(), args);
for(std::vector<std::string>::iterator i = args.begin();
i != args.end(); ++i)
{
@@ -452,7 +454,7 @@ cmExtraSublimeTextGenerator::ComputeFlagsForObject(cmSourceFile* source,
}
else
{
- lg->AppendFlags(flags, target->GetProperty("COMPILE_FLAGS"));
+ lg->AppendFlags(flags, targetFlags.c_str());
}
}
diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx
index bb1e792851..10de35ac8d 100644
--- a/Source/cmGlobalXCodeGenerator.cxx
+++ b/Source/cmGlobalXCodeGenerator.cxx
@@ -681,9 +681,11 @@ cmGlobalXCodeGenerator::CreateXCodeSourceFile(cmLocalGenerator* lg,
{
// Add flags from target and source file properties.
std::string flags;
- if(cmtarget.GetProperty("COMPILE_FLAGS"))
+ std::string targetFlags;
+ lg->GetCompileOptions(targetFlags, &cmtarget, 0); // TODO: Config?
+ if(!targetFlags.empty())
{
- lg->AppendFlags(flags, cmtarget.GetProperty("COMPILE_FLAGS"));
+ lg->AppendFlags(flags, targetFlags.c_str());
}
const char* srcfmt = sf->GetProperty("Fortran_FORMAT");
switch(this->CurrentLocalGenerator->GetFortranFormat(srcfmt))
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index d346f16635..9429450e4f 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -1325,6 +1325,18 @@ std::string cmLocalGenerator::GetIncludeFlags(
}
//----------------------------------------------------------------------------
+void cmLocalGenerator::GetCompileOptions(std::string& flags,
+ cmTarget* target,
+ const char *config)
+{
+ // Add target-specific flags.
+ if(const char *prop = target->GetProperty("COMPILE_FLAGS"))
+ {
+ this->AppendFlags(flags, prop);
+ }
+}
+
+//----------------------------------------------------------------------------
void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs,
cmGeneratorTarget* target,
const char* lang,
diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h
index a1c34f076d..28c88e6849 100644
--- a/Source/cmLocalGenerator.h
+++ b/Source/cmLocalGenerator.h
@@ -215,6 +215,9 @@ public:
cmGeneratorTarget* target,
const char* lang = "C", const char *config = 0,
bool stripImplicitInclDirs = true);
+ void GetCompileOptions(std::string& flags,
+ cmTarget* target,
+ const char *config);
/** Compute the language used to compile the given source file. */
const char* GetSourceFileLanguage(const cmSourceFile& source);
diff --git a/Source/cmLocalVisualStudio6Generator.cxx b/Source/cmLocalVisualStudio6Generator.cxx
index 0a3728b7ec..4c78f7fd84 100644
--- a/Source/cmLocalVisualStudio6Generator.cxx
+++ b/Source/cmLocalVisualStudio6Generator.cxx
@@ -1686,12 +1686,31 @@ void cmLocalVisualStudio6Generator
flags += " /D \"_MBCS\"";
}
+ {
+ std::string targetFlags;
+ this->GetCompileOptions(targetFlags, &target, 0);
// Add per-target flags.
- if(const char* targetFlags = target.GetProperty("COMPILE_FLAGS"))
+ if(!targetFlags.empty())
{
flags += " ";
flags += targetFlags;
}
+ }
+#define ADD_FLAGS(CONFIG) \
+ { \
+ std::string targetFlags; \
+ this->GetCompileOptions(targetFlags, &target, #CONFIG); \
+ if(!targetFlags.empty()) \
+ { \
+ flags ## CONFIG += " "; \
+ flags ## CONFIG += targetFlags; \
+ } \
+ }
+
+ ADD_FLAGS(Debug)
+ ADD_FLAGS(Release)
+ ADD_FLAGS(MinSizeRel)
+ ADD_FLAGS(RelWithDebInfo)
// Add per-target and per-configuration preprocessor definitions.
std::set<std::string> definesSet;
diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx
index 58d28da02f..e7badf05f4 100644
--- a/Source/cmLocalVisualStudio7Generator.cxx
+++ b/Source/cmLocalVisualStudio7Generator.cxx
@@ -723,8 +723,10 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
}
}
+ std::string targetFlags;
+ this->GetCompileOptions(targetFlags, &target, configName);
// Add the target-specific flags.
- if(const char* targetFlags = target.GetProperty("COMPILE_FLAGS"))
+ if(!targetFlags.empty())
{
flags += " ";
flags += targetFlags;
diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx
index 4220ae1486..d83d72221b 100644
--- a/Source/cmMakefileTargetGenerator.cxx
+++ b/Source/cmMakefileTargetGenerator.cxx
@@ -332,21 +332,25 @@ void cmMakefileTargetGenerator::WriteTargetLanguageFlags()
this->Makefile->GetSafeDefinition(compiler.c_str()) << "\n";
}
+ std::string targetFlags;
for(std::set<cmStdString>::const_iterator l = languages.begin();
l != languages.end(); ++l)
{
*this->FlagFileStream << *l << "_FLAGS = " << this->GetFlags(*l) << "\n\n";
*this->FlagFileStream << *l << "_DEFINES = " << this->GetDefines(*l) <<
"\n\n";
+ std::string targetLangFlags;
+ this->LocalGenerator->GetCompileOptions(targetLangFlags, this->Target,
+ this->LocalGenerator->ConfigurationName.c_str());
+ if (!targetFlags.empty() && targetFlags != targetLangFlags)
+ {
+ targetFlags += " " + targetLangFlags;
+ }
}
- // Add target-specific flags.
- if(this->Target->GetProperty("COMPILE_FLAGS"))
+ if (!targetFlags.empty())
{
- std::string flags;
- this->LocalGenerator->AppendFlags
- (flags, this->Target->GetProperty("COMPILE_FLAGS"));
- *this->FlagFileStream << "# TARGET_FLAGS = " << flags << "\n\n";
+ *this->FlagFileStream << "# TARGET_FLAGS = " << targetFlags << "\n\n";
}
}
@@ -532,8 +536,13 @@ cmMakefileTargetGenerator
langFlags += "_FLAGS)";
this->LocalGenerator->AppendFlags(flags, langFlags.c_str());
- // Add target-specific flags.
- if(this->Target->GetProperty("COMPILE_FLAGS"))
+ std::string configUpper =
+ cmSystemTools::UpperCase(this->LocalGenerator->ConfigurationName);
+
+ std::string targetFlags;
+ this->LocalGenerator->GetCompileOptions(targetFlags, this->Target,
+ configUpper.c_str());
+ if (!targetFlags.empty())
{
std::string langIncludeExpr = "CMAKE_";
langIncludeExpr += lang;
@@ -545,7 +554,7 @@ cmMakefileTargetGenerator
cmsys::RegularExpression r(regex);
std::vector<std::string> args;
cmSystemTools::ParseWindowsCommandLine(
- this->Target->GetProperty("COMPILE_FLAGS"),
+ targetFlags.c_str(),
args);
for(std::vector<std::string>::iterator i = args.begin();
i != args.end(); ++i)
@@ -559,8 +568,7 @@ cmMakefileTargetGenerator
}
else
{
- this->LocalGenerator->AppendFlags
- (flags, this->Target->GetProperty("COMPILE_FLAGS"));
+ this->LocalGenerator->AppendFlags(flags, targetFlags.c_str());
}
}
@@ -594,8 +602,6 @@ cmMakefileTargetGenerator
<< compile_defs << "\n"
<< "\n";
}
- std::string configUpper =
- cmSystemTools::UpperCase(this->LocalGenerator->ConfigurationName);
std::string defPropName = "COMPILE_DEFINITIONS_";
defPropName += configUpper;
if(const char* config_compile_defs =
diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx
index 850e5ea11e..141e014cc1 100644
--- a/Source/cmNinjaTargetGenerator.cxx
+++ b/Source/cmNinjaTargetGenerator.cxx
@@ -151,9 +151,9 @@ cmNinjaTargetGenerator::ComputeFlagsForObject(cmSourceFile *source,
this->GetConfigName());
// Add include directory flags.
+ const char *config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE");
{
std::vector<std::string> includes;
- const char *config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE");
this->LocalGenerator->GetIncludeDirectories(includes,
this->GeneratorTarget,
language.c_str(), config);
@@ -171,7 +171,9 @@ cmNinjaTargetGenerator::ComputeFlagsForObject(cmSourceFile *source,
this->LocalGenerator->AppendFlags(flags, this->Makefile->GetDefineFlags());
// Add target-specific flags.
- if(this->Target->GetProperty("COMPILE_FLAGS"))
+ std::string targetFlags;
+ this->LocalGenerator->GetCompileOptions(targetFlags, this->Target, config);
+ if(!targetFlags.empty())
{
std::string langIncludeExpr = "CMAKE_";
langIncludeExpr += language;
@@ -183,7 +185,7 @@ cmNinjaTargetGenerator::ComputeFlagsForObject(cmSourceFile *source,
cmsys::RegularExpression r(regex);
std::vector<std::string> args;
cmSystemTools::ParseWindowsCommandLine(
- this->Target->GetProperty("COMPILE_FLAGS"),
+ targetFlags.c_str(),
args);
for(std::vector<std::string>::iterator i = args.begin();
i != args.end(); ++i)
@@ -198,7 +200,7 @@ cmNinjaTargetGenerator::ComputeFlagsForObject(cmSourceFile *source,
else
{
this->LocalGenerator->AppendFlags
- (flags, this->Target->GetProperty("COMPILE_FLAGS"));
+ (flags, targetFlags.c_str());
}
}
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx
index 88c4deb54b..341ef45878 100644
--- a/Source/cmVisualStudio10TargetGenerator.cxx
+++ b/Source/cmVisualStudio10TargetGenerator.cxx
@@ -1261,8 +1261,12 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
flags += " /TP ";
}
}
+
+ std::string targetFlags;
+ this->LocalGenerator->GetCompileOptions(targetFlags, this->Target,
+ configName.c_str());
// Add the target-specific flags.
- if(const char* targetFlags = this->Target->GetProperty("COMPILE_FLAGS"))
+ if(!targetFlags.empty())
{
flags += " ";
flags += targetFlags;