From 35496761a58956bd8c5ad65a3ed9ee78d09af56b Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 16 May 2013 14:59:04 +0200 Subject: [PATCH] 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. --- Source/cmExtraSublimeTextGenerator.cxx | 8 ++++-- Source/cmGlobalXCodeGenerator.cxx | 6 ++-- Source/cmLocalGenerator.cxx | 12 ++++++++ Source/cmLocalGenerator.h | 3 ++ Source/cmLocalVisualStudio6Generator.cxx | 21 +++++++++++++- Source/cmLocalVisualStudio7Generator.cxx | 4 ++- Source/cmMakefileTargetGenerator.cxx | 32 +++++++++++++--------- Source/cmNinjaTargetGenerator.cxx | 10 ++++--- Source/cmVisualStudio10TargetGenerator.cxx | 6 +++- 9 files changed, 77 insertions(+), 25 deletions(-) diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx index 62e9194e9..29d86a61e 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 args; cmSystemTools:: - ParseWindowsCommandLine(target->GetProperty("COMPILE_FLAGS"), args); + ParseWindowsCommandLine(targetFlags.c_str(), args); for(std::vector::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 bb1e79285..10de35ac8 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 d346f1663..9429450e4 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1324,6 +1324,18 @@ std::string cmLocalGenerator::GetIncludeFlags( return flags; } +//---------------------------------------------------------------------------- +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& dirs, cmGeneratorTarget* target, diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index a1c34f076..28c88e684 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 0a3728b7e..4c78f7fd8 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 definesSet; diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 58d28da02..e7badf05f 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 4220ae148..d83d72221 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::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 args; cmSystemTools::ParseWindowsCommandLine( - this->Target->GetProperty("COMPILE_FLAGS"), + targetFlags.c_str(), args); for(std::vector::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 850e5ea11..141e014cc 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 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 args; cmSystemTools::ParseWindowsCommandLine( - this->Target->GetProperty("COMPILE_FLAGS"), + targetFlags.c_str(), args); for(std::vector::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 88c4deb54..341ef4587 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;