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,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

View File

@ -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_";

View File

@ -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());

View File

@ -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,

View File

@ -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);

View File

@ -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

View File

@ -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 = " ";

View File

@ -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"));

View File

@ -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);

View File

@ -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"));

View File

@ -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;
}
}

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;
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);
}
//----------------------------------------------------------------------------

View File

@ -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

View File

@ -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"));