Browse Source

Refactor cmTarget::GetCompileDefinitions to use an out-vector, not a string.

Refactor to create AddCompileDefinitions.
Stephen Kelly 12 years ago
parent
commit
184121538c

+ 7 - 11
Source/cmExtraCodeBlocksGenerator.cxx

@@ -621,19 +621,15 @@ void cmExtraCodeBlocksGenerator::AppendTarget(cmGeneratedFileStream& fout,
                                   ->GetGeneratorTarget(target);
 
     // the compilerdefines for this target
-    std::string cdefs = target->GetCompileDefinitions(buildType);
+    std::vector<std::string> cdefs;
+    target->GetCompileDefinitions(cdefs, buildType);
 
-    if(!cdefs.empty())
+    // Expand the list.
+    for(std::vector<std::string>::const_iterator di = cdefs.begin();
+        di != cdefs.end(); ++di)
       {
-      // Expand the list.
-      std::vector<std::string> defs;
-      cmSystemTools::ExpandListArgument(cdefs.c_str(), defs);
-      for(std::vector<std::string>::const_iterator di = defs.begin();
-          di != defs.end(); ++di)
-        {
-        cmXMLSafe safedef(di->c_str());
-        fout <<"            <Add option=\"-D" << safedef.str() << "\" />\n";
-        }
+      cmXMLSafe safedef(di->c_str());
+      fout <<"            <Add option=\"-D" << safedef.str() << "\" />\n";
       }
 
     // the include directories for this target

+ 1 - 1
Source/cmExtraSublimeTextGenerator.cxx

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

+ 3 - 2
Source/cmGlobalXCodeGenerator.cxx

@@ -1741,8 +1741,9 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
     this->AppendDefines(ppDefs, exportMacro);
     }
   cmGeneratorTarget *gtgt = this->GetGeneratorTarget(&target);
-  this->AppendDefines(ppDefs,
-                      target.GetCompileDefinitions(configName).c_str());
+  std::vector<std::string> targetDefines;
+  target.GetCompileDefinitions(targetDefines, configName);
+  this->AppendDefines(ppDefs, targetDefines);
   buildSettings->AddAttribute
     ("GCC_PREPROCESSOR_DEFINITIONS", ppDefs.CreateList());
 

+ 11 - 0
Source/cmLocalGenerator.cxx

@@ -1338,6 +1338,17 @@ std::string cmLocalGenerator::GetIncludeFlags(
   return flags;
 }
 
+//----------------------------------------------------------------------------
+void cmLocalGenerator::AddCompileDefinitions(std::set<std::string>& defines,
+                                             cmTarget* target,
+                                             const char* config)
+{
+  std::vector<std::string> targetDefines;
+  target->GetCompileDefinitions(targetDefines,
+                               config);
+  this->AppendDefines(defines, targetDefines);
+}
+
 //----------------------------------------------------------------------------
 void cmLocalGenerator::AddCompileOptions(
   std::string& flags, cmTarget* target,

+ 2 - 0
Source/cmLocalGenerator.h

@@ -223,6 +223,8 @@ public:
                              bool stripImplicitInclDirs = true);
   void AddCompileOptions(std::string& flags, cmTarget* target,
                          const char* lang, const char* config);
+  void AddCompileDefinitions(std::set<std::string>& defines, cmTarget* target,
+                         const char* config);
 
   /** Compute the language used to compile the given source file.  */
   const char* GetSourceFileLanguage(const cmSourceFile& source);

+ 2 - 2
Source/cmLocalUnixMakefileGenerator3.cxx

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

+ 5 - 15
Source/cmLocalVisualStudio6Generator.cxx

@@ -1701,21 +1701,11 @@ void cmLocalVisualStudio6Generator
     std::set<std::string> minsizeDefinesSet;
     std::set<std::string> debugrelDefinesSet;
 
-    this->AppendDefines(
-      definesSet,
-      target.GetCompileDefinitions(0));
-    this->AppendDefines(
-      debugDefinesSet,
-      target.GetCompileDefinitions("DEBUG"));
-    this->AppendDefines(
-      releaseDefinesSet,
-      target.GetCompileDefinitions("RELEASE"));
-    this->AppendDefines(
-      minsizeDefinesSet,
-      target.GetCompileDefinitions("MINSIZEREL"));
-    this->AppendDefines(
-      debugrelDefinesSet,
-      target.GetCompileDefinitions("RELWITHDEBINFO"));
+    this->AddCompileDefinitions(definesSet, &target, 0);
+    this->AddCompileDefinitions(debugDefinesSet, &target, "DEBUG");
+    this->AddCompileDefinitions(releaseDefinesSet, &target, "RELEASE");
+    this->AddCompileDefinitions(minsizeDefinesSet, &target, "MINSIZEREL");
+    this->AddCompileDefinitions(debugrelDefinesSet, &target, "RELWITHDEBINFO");
 
     std::string defines = " ";
     std::string debugDefines = " ";

+ 3 - 1
Source/cmLocalVisualStudio7Generator.cxx

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

+ 2 - 3
Source/cmMakefileTargetGenerator.cxx

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

+ 2 - 3
Source/cmNinjaTargetGenerator.cxx

@@ -201,9 +201,8 @@ ComputeDefines(cmSourceFile *source, const std::string& language)
     }
 
   // Add preprocessor definitions for this target and configuration.
-  this->LocalGenerator->AppendDefines
-    (defines,
-     this->Target->GetCompileDefinitions(this->GetConfigName()));
+  this->LocalGenerator->AddCompileDefinitions(defines, this->Target,
+                                             this->GetConfigName());
   this->LocalGenerator->AppendDefines
     (defines,
      source->GetProperty("COMPILE_DEFINITIONS"));

+ 6 - 4
Source/cmQtAutomoc.cxx

@@ -175,15 +175,17 @@ static void GetCompileDefinitionsAndDirectories(cmTarget *target,
     incs += *incDirIt;
     }
 
-  defs = target->GetCompileDefinitions(config);
+  std::set<std::string> defines;
+  localGen->AddCompileDefinitions(defines, target, config);
 
-  const char *tmp = makefile->GetProperty("COMPILE_DEFINITIONS");
   sep = "";
-  if (tmp)
+  for(std::set<std::string>::const_iterator defIt = defines.begin();
+      defIt != defines.end();
+      ++defIt)
     {
     defs += sep;
     sep = ";";
-    defs += tmp;
+    defs += *defIt;
     }
 }
 

+ 5 - 3
Source/cmTarget.cxx

@@ -3384,7 +3384,8 @@ void cmTarget::GetCompileOptions(std::vector<std::string> &result,
 }
 
 //----------------------------------------------------------------------------
-std::string cmTarget::GetCompileDefinitions(const char *config)
+void cmTarget::GetCompileDefinitions(std::vector<std::string> &list,
+                                            const char *config)
 {
   const char *configProp = 0;
   if (config)
@@ -3419,7 +3420,8 @@ std::string cmTarget::GetCompileDefinitions(const char *config)
 
   if (libs.empty())
     {
-    return result;
+    cmSystemTools::ExpandListArgument(result, list);
+    return;
     }
 
   std::string sep;
@@ -3467,7 +3469,7 @@ std::string cmTarget::GetCompileDefinitions(const char *config)
                                                                       = true;
     }
 
-  return result;
+  cmSystemTools::ExpandListArgument(result, list);
 }
 
 //----------------------------------------------------------------------------

+ 2 - 1
Source/cmTarget.h

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

+ 3 - 2
Source/cmVisualStudio10TargetGenerator.cxx

@@ -1337,8 +1337,9 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
   clOptions.AddFlag("AssemblerListingLocation", asmLocation.c_str());
   clOptions.Parse(flags.c_str());
   clOptions.Parse(defineFlags.c_str());
-  clOptions.AddDefines(this->Target->GetCompileDefinitions(
-                                                configName.c_str()).c_str());
+  std::vector<std::string> targetDefines;
+  this->Target->GetCompileDefinitions(targetDefines, configName.c_str());
+  clOptions.AddDefines(targetDefines);
   clOptions.SetVerboseMakefile(
     this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));