浏览代码

Fix the evaluation of per-config COMPILE_DEFINITIONS (#14037)

The API for retrieving per-config COMPILE_DEFINITIONS has long
existed because of the COMPILE_DEFINITIONS_<CONFIG> style
properties. Ensure that the provided configuration being generated
is also used to evaluate the generator expressions
in cmTarget::GetCompileDefinitions.

Both the generic COMPILE_DEFINITIONS and the config-specific
variant need to be evaluated with the requested configuration. This
has the side-effect that the COMPILE_DEFINITIONS does not need to
be additionally evaluated with no configuration, so the callers can
be cleaned up a bit too.
Stephen Kelly 12 年之前
父节点
当前提交
a6286e92c9

+ 2 - 4
Source/cmExtraCodeBlocksGenerator.cxx

@@ -621,7 +621,7 @@ void cmExtraCodeBlocksGenerator::AppendTarget(cmGeneratedFileStream& fout,
                                   ->GetGeneratorTarget(target);
                                   ->GetGeneratorTarget(target);
 
 
     // the compilerdefines for this target
     // the compilerdefines for this target
-    std::string cdefs = target->GetCompileDefinitions();
+    std::string cdefs = target->GetCompileDefinitions(buildType);
 
 
     if(!cdefs.empty())
     if(!cdefs.empty())
       {
       {
@@ -640,10 +640,8 @@ void cmExtraCodeBlocksGenerator::AppendTarget(cmGeneratedFileStream& fout,
     std::set<std::string> uniqIncludeDirs;
     std::set<std::string> uniqIncludeDirs;
 
 
     std::vector<std::string> includes;
     std::vector<std::string> includes;
-    const char *config = target->GetMakefile()
-                               ->GetDefinition("CMAKE_BUILD_TYPE");
     target->GetMakefile()->GetLocalGenerator()->
     target->GetMakefile()->GetLocalGenerator()->
-      GetIncludeDirectories(includes, gtgt, "C", config);
+      GetIncludeDirectories(includes, gtgt, "C", buildType);
     for(std::vector<std::string>::const_iterator dirIt=includes.begin();
     for(std::vector<std::string>::const_iterator dirIt=includes.begin();
         dirIt != includes.end();
         dirIt != includes.end();
         ++dirIt)
         ++dirIt)

+ 1 - 2
Source/cmExtraSublimeTextGenerator.cxx

@@ -488,12 +488,11 @@ ComputeDefines(cmSourceFile *source, cmLocalGenerator* lg, cmTarget *target,
     }
     }
 
 
   // Add preprocessor definitions for this target and configuration.
   // Add preprocessor definitions for this target and configuration.
-  lg->AppendDefines(defines, target->GetCompileDefinitions());
+  lg->AppendDefines(defines, target->GetCompileDefinitions(config));
   lg->AppendDefines(defines, source->GetProperty("COMPILE_DEFINITIONS"));
   lg->AppendDefines(defines, source->GetProperty("COMPILE_DEFINITIONS"));
   {
   {
   std::string defPropName = "COMPILE_DEFINITIONS_";
   std::string defPropName = "COMPILE_DEFINITIONS_";
   defPropName += cmSystemTools::UpperCase(config);
   defPropName += cmSystemTools::UpperCase(config);
-  lg->AppendDefines(defines, target->GetCompileDefinitions(config));
   lg->AppendDefines(defines, source->GetProperty(defPropName.c_str()));
   lg->AppendDefines(defines, source->GetProperty(defPropName.c_str()));
   }
   }
 
 

+ 2 - 6
Source/cmGlobalXCodeGenerator.cxx

@@ -1709,12 +1709,8 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
     this->AppendDefines(ppDefs, exportMacro);
     this->AppendDefines(ppDefs, exportMacro);
     }
     }
   cmGeneratorTarget *gtgt = this->GetGeneratorTarget(&target);
   cmGeneratorTarget *gtgt = this->GetGeneratorTarget(&target);
-  this->AppendDefines(ppDefs, target.GetCompileDefinitions().c_str());
-  if(configName)
-    {
-    this->AppendDefines(ppDefs,
-                        target.GetCompileDefinitions(configName).c_str());
-    }
+  this->AppendDefines(ppDefs,
+                      target.GetCompileDefinitions(configName).c_str());
   buildSettings->AddAttribute
   buildSettings->AddAttribute
     ("GCC_PREPROCESSOR_DEFINITIONS", ppDefs.CreateList());
     ("GCC_PREPROCESSOR_DEFINITIONS", ppDefs.CreateList());
 
 

+ 0 - 1
Source/cmLocalUnixMakefileGenerator3.cxx

@@ -1962,7 +1962,6 @@ void cmLocalUnixMakefileGenerator3
 
 
   // Build a list of preprocessor definitions for the target.
   // Build a list of preprocessor definitions for the target.
   std::set<std::string> defines;
   std::set<std::string> defines;
-  this->AppendDefines(defines, target.GetCompileDefinitions());
   this->AppendDefines(defines, target.GetCompileDefinitions(
   this->AppendDefines(defines, target.GetCompileDefinitions(
                                             this->ConfigurationName.c_str()));
                                             this->ConfigurationName.c_str()));
   if(!defines.empty())
   if(!defines.empty())

+ 1 - 1
Source/cmLocalVisualStudio6Generator.cxx

@@ -1702,7 +1702,7 @@ void cmLocalVisualStudio6Generator
 
 
     this->AppendDefines(
     this->AppendDefines(
       definesSet,
       definesSet,
-      target.GetCompileDefinitions());
+      target.GetCompileDefinitions(0));
     this->AppendDefines(
     this->AppendDefines(
       debugDefinesSet,
       debugDefinesSet,
       target.GetCompileDefinitions("DEBUG"));
       target.GetCompileDefinitions("DEBUG"));

+ 0 - 1
Source/cmLocalVisualStudio7Generator.cxx

@@ -745,7 +745,6 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
   targetOptions.ParseFinish();
   targetOptions.ParseFinish();
   cmGeneratorTarget* gt =
   cmGeneratorTarget* gt =
     this->GlobalGenerator->GetGeneratorTarget(&target);
     this->GlobalGenerator->GetGeneratorTarget(&target);
-  targetOptions.AddDefines(target.GetCompileDefinitions().c_str());
   targetOptions.AddDefines(target.GetCompileDefinitions(configName).c_str());
   targetOptions.AddDefines(target.GetCompileDefinitions(configName).c_str());
   targetOptions.SetVerboseMakefile(
   targetOptions.SetVerboseMakefile(
     this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
     this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));

+ 0 - 3
Source/cmMakefileTargetGenerator.cxx

@@ -302,9 +302,6 @@ std::string cmMakefileTargetGenerator::GetDefines(const std::string &l)
       }
       }
 
 
     // Add preprocessor definitions for this target and configuration.
     // Add preprocessor definitions for this target and configuration.
-    this->LocalGenerator->AppendDefines
-      (defines, this->Target->GetCompileDefinitions());
-
     this->LocalGenerator->AppendDefines
     this->LocalGenerator->AppendDefines
       (defines, this->Target->GetCompileDefinitions(
       (defines, this->Target->GetCompileDefinitions(
                             this->LocalGenerator->ConfigurationName.c_str()));
                             this->LocalGenerator->ConfigurationName.c_str()));

+ 1 - 4
Source/cmNinjaTargetGenerator.cxx

@@ -228,16 +228,13 @@ ComputeDefines(cmSourceFile *source, const std::string& language)
   // Add preprocessor definitions for this target and configuration.
   // Add preprocessor definitions for this target and configuration.
   this->LocalGenerator->AppendDefines
   this->LocalGenerator->AppendDefines
     (defines,
     (defines,
-     this->Target->GetCompileDefinitions());
+     this->Target->GetCompileDefinitions(this->GetConfigName()));
   this->LocalGenerator->AppendDefines
   this->LocalGenerator->AppendDefines
     (defines,
     (defines,
      source->GetProperty("COMPILE_DEFINITIONS"));
      source->GetProperty("COMPILE_DEFINITIONS"));
   {
   {
   std::string defPropName = "COMPILE_DEFINITIONS_";
   std::string defPropName = "COMPILE_DEFINITIONS_";
   defPropName += cmSystemTools::UpperCase(this->GetConfigName());
   defPropName += cmSystemTools::UpperCase(this->GetConfigName());
-  this->LocalGenerator->AppendDefines
-    (defines,
-     this->Target->GetCompileDefinitions(this->GetConfigName()));
   this->LocalGenerator->AppendDefines
   this->LocalGenerator->AppendDefines
     (defines,
     (defines,
      source->GetProperty(defPropName.c_str()));
      source->GetProperty(defPropName.c_str()));

+ 1 - 1
Source/cmQtAutomoc.cxx

@@ -250,7 +250,7 @@ void cmQtAutomoc::SetupAutomocTarget(cmTarget* target)
   std::string _moc_compile_defs;
   std::string _moc_compile_defs;
   if (tmp)
   if (tmp)
     {
     {
-    _moc_compile_defs = target->GetCompileDefinitions();
+    _moc_compile_defs = target->GetCompileDefinitions(0);
     }
     }
   tmp = makefile->GetProperty("COMPILE_DEFINITIONS");
   tmp = makefile->GetProperty("COMPILE_DEFINITIONS");
   if (tmp)
   if (tmp)

+ 17 - 13
Source/cmTarget.cxx

@@ -2942,29 +2942,33 @@ std::vector<std::string> cmTarget::GetIncludeDirectories(const char *config)
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
 std::string cmTarget::GetCompileDefinitions(const char *config)
 std::string cmTarget::GetCompileDefinitions(const char *config)
 {
 {
-  std::string defPropName = "COMPILE_DEFINITIONS";
+  const char *configProp = 0;
   if (config)
   if (config)
     {
     {
-    defPropName += "_" + cmSystemTools::UpperCase(config);
+    std::string configPropName;
+    configPropName = "COMPILE_DEFINITIONS_" + cmSystemTools::UpperCase(config);
+    configProp = this->GetProperty(configPropName.c_str());
     }
     }
 
 
-  const char *prop = this->GetProperty(defPropName.c_str());
+  const char *noconfigProp = this->GetProperty("COMPILE_DEFINITIONS");
   cmListFileBacktrace lfbt;
   cmListFileBacktrace lfbt;
   cmGeneratorExpressionDAGChecker dagChecker(lfbt,
   cmGeneratorExpressionDAGChecker dagChecker(lfbt,
                                             this->GetName(),
                                             this->GetName(),
-                                            defPropName, 0, 0);
+                                            "COMPILE_DEFINITIONS", 0, 0);
 
 
-  std::string result;
-  if (prop)
+  std::string defsString = (noconfigProp ? noconfigProp : "");
+  if (configProp && noconfigProp)
     {
     {
-    cmGeneratorExpression ge(lfbt);
-
-    result = ge.Parse(prop)->Evaluate(this->Makefile,
-                                  config,
-                                  false,
-                                  this,
-                                  &dagChecker);
+    defsString += ";";
     }
     }
+  defsString += (configProp ? configProp : "");
+
+  cmGeneratorExpression ge(lfbt);
+  std::string result = ge.Parse(defsString.c_str())->Evaluate(this->Makefile,
+                                config,
+                                false,
+                                this,
+                                &dagChecker);
 
 
   std::vector<std::string> libs;
   std::vector<std::string> libs;
   this->GetDirectLinkLibraries(config, libs, this);
   this->GetDirectLinkLibraries(config, libs, this);

+ 1 - 1
Source/cmTarget.h

@@ -430,7 +430,7 @@ public:
       If no macro should be defined null is returned.  */
       If no macro should be defined null is returned.  */
   const char* GetExportMacro();
   const char* GetExportMacro();
 
 
-  std::string GetCompileDefinitions(const char *config = 0);
+  std::string GetCompileDefinitions(const char *config);
 
 
   // Compute the set of languages compiled by the target.  This is
   // Compute the set of languages compiled by the target.  This is
   // computed every time it is called because the languages can change
   // computed every time it is called because the languages can change

+ 0 - 2
Source/cmVisualStudio10TargetGenerator.cxx

@@ -1220,8 +1220,6 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
   clOptions.AddFlag("PrecompiledHeader", "NotUsing");
   clOptions.AddFlag("PrecompiledHeader", "NotUsing");
   clOptions.Parse(flags.c_str());
   clOptions.Parse(flags.c_str());
   clOptions.Parse(defineFlags.c_str());
   clOptions.Parse(defineFlags.c_str());
-  clOptions.AddDefines(
-                     this->Target->GetCompileDefinitions().c_str());
   clOptions.AddDefines(this->Target->GetCompileDefinitions(
   clOptions.AddDefines(this->Target->GetCompileDefinitions(
                                                 configName.c_str()).c_str());
                                                 configName.c_str()).c_str());
   clOptions.SetVerboseMakefile(
   clOptions.SetVerboseMakefile(