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

Refactor to create AddCompileDefinitions.
This commit is contained in:
Stephen Kelly 2013-06-06 18:13:35 +02:00
parent afc9243c32
commit 184121538c
14 changed files with 54 additions and 48 deletions

View File

@ -621,20 +621,16 @@ void cmExtraCodeBlocksGenerator::AppendTarget(cmGeneratedFileStream& fout,
->GetGeneratorTarget(target); ->GetGeneratorTarget(target);
// the compilerdefines for this 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. // Expand the list.
std::vector<std::string> defs; for(std::vector<std::string>::const_iterator di = cdefs.begin();
cmSystemTools::ExpandListArgument(cdefs.c_str(), defs); di != cdefs.end(); ++di)
for(std::vector<std::string>::const_iterator di = defs.begin();
di != defs.end(); ++di)
{ {
cmXMLSafe safedef(di->c_str()); cmXMLSafe safedef(di->c_str());
fout <<" <Add option=\"-D" << safedef.str() << "\" />\n"; fout <<" <Add option=\"-D" << safedef.str() << "\" />\n";
} }
}
// the include directories for this target // the include directories for this target
std::set<std::string> uniqIncludeDirs; std::set<std::string> uniqIncludeDirs;

View File

@ -463,7 +463,7 @@ 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(config)); lg->AddCompileDefinitions(defines, target, 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_";

View File

@ -1741,8 +1741,9 @@ 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, std::vector<std::string> targetDefines;
target.GetCompileDefinitions(configName).c_str()); target.GetCompileDefinitions(targetDefines, configName);
this->AppendDefines(ppDefs, targetDefines);
buildSettings->AddAttribute buildSettings->AddAttribute
("GCC_PREPROCESSOR_DEFINITIONS", ppDefs.CreateList()); ("GCC_PREPROCESSOR_DEFINITIONS", ppDefs.CreateList());

View File

@ -1338,6 +1338,17 @@ std::string cmLocalGenerator::GetIncludeFlags(
return flags; 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( void cmLocalGenerator::AddCompileOptions(
std::string& flags, cmTarget* target, std::string& flags, cmTarget* target,

View File

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

View File

@ -1962,8 +1962,8 @@ 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->AddCompileDefinitions(defines, &target,
this->ConfigurationName.c_str())); this->ConfigurationName.c_str());
if(!defines.empty()) if(!defines.empty())
{ {
cmakefileStream cmakefileStream

View File

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

View File

@ -746,7 +746,9 @@ 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(configName).c_str()); std::vector<std::string> targetDefines;
target.GetCompileDefinitions(targetDefines, configName);
targetOptions.AddDefines(targetDefines);
targetOptions.SetVerboseMakefile( targetOptions.SetVerboseMakefile(
this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE")); this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));

View File

@ -309,9 +309,8 @@ 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 this->LocalGenerator->AddCompileDefinitions(defines, this->Target,
(defines, this->Target->GetCompileDefinitions( this->LocalGenerator->ConfigurationName.c_str());
this->LocalGenerator->ConfigurationName.c_str()));
std::string definesString; std::string definesString;
this->LocalGenerator->JoinDefines(defines, definesString, lang); this->LocalGenerator->JoinDefines(defines, definesString, lang);

View File

@ -201,9 +201,8 @@ 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->AddCompileDefinitions(defines, this->Target,
(defines, this->GetConfigName());
this->Target->GetCompileDefinitions(this->GetConfigName()));
this->LocalGenerator->AppendDefines this->LocalGenerator->AppendDefines
(defines, (defines,
source->GetProperty("COMPILE_DEFINITIONS")); source->GetProperty("COMPILE_DEFINITIONS"));

View File

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

View File

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

View File

@ -442,7 +442,8 @@ 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); void GetCompileDefinitions(std::vector<std::string> &result,
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

View File

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