cmGeneratorTarget: Move compile defintions processing from cmTarget.

This commit is contained in:
Stephen Kelly 2015-08-05 00:00:53 +02:00
parent d051086cce
commit a7f5d70dde
14 changed files with 141 additions and 182 deletions

View File

@ -609,7 +609,7 @@ void cmExtraCodeBlocksGenerator::AppendTarget(cmGeneratedFileStream& fout,
// the compilerdefines for this target
std::vector<std::string> cdefs;
target->GetCompileDefinitions(cdefs, buildType, "C");
gtgt->GetCompileDefinitions(cdefs, buildType, "C");
// Expand the list.
for(std::vector<std::string>::const_iterator di = cdefs.begin();

View File

@ -263,7 +263,8 @@ cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg)
PolicyWarnedCMP0022(false),
DebugIncludesDone(false),
DebugCompileOptionsDone(false),
DebugCompileFeaturesDone(false)
DebugCompileFeaturesDone(false),
DebugCompileDefinitionsDone(false)
{
this->Makefile = this->Target->GetMakefile();
this->LocalGenerator = lg;
@ -283,6 +284,11 @@ cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg)
t->GetCompileFeaturesEntries(),
t->GetCompileFeaturesBacktraces(),
this->CompileFeaturesEntries);
CreatePropertyGeneratorExpressions(
t->GetCompileDefinitionsEntries(),
t->GetCompileDefinitionsBacktraces(),
this->CompileDefinitionsEntries);
}
cmGeneratorTarget::~cmGeneratorTarget()
@ -290,6 +296,7 @@ cmGeneratorTarget::~cmGeneratorTarget()
cmDeleteAll(this->IncludeDirectoriesEntries);
cmDeleteAll(this->CompileOptionsEntries);
cmDeleteAll(this->CompileFeaturesEntries);
cmDeleteAll(this->CompileDefinitionsEntries);
cmDeleteAll(this->LinkInformation);
this->LinkInformation.clear();
}
@ -2444,6 +2451,108 @@ void cmGeneratorTarget::GetCompileFeatures(std::vector<std::string> &result,
cmDeleteAll(linkInterfaceCompileFeaturesEntries);
}
//----------------------------------------------------------------------------
static void processCompileDefinitions(cmGeneratorTarget const* tgt,
const std::vector<cmGeneratorTarget::TargetPropertyEntry*> &entries,
std::vector<std::string> &options,
UNORDERED_SET<std::string> &uniqueOptions,
cmGeneratorExpressionDAGChecker *dagChecker,
const std::string& config, bool debugOptions,
std::string const& language)
{
processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
dagChecker, config, debugOptions,
"definitions", language);
}
//----------------------------------------------------------------------------
void cmGeneratorTarget::GetCompileDefinitions(std::vector<std::string> &list,
const std::string& config,
const std::string& language) const
{
UNORDERED_SET<std::string> uniqueOptions;
cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
"COMPILE_DEFINITIONS", 0, 0);
std::vector<std::string> debugProperties;
const char *debugProp =
this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
if (debugProp)
{
cmSystemTools::ExpandListArgument(debugProp, debugProperties);
}
bool debugDefines = !this->DebugCompileDefinitionsDone
&& std::find(debugProperties.begin(),
debugProperties.end(),
"COMPILE_DEFINITIONS")
!= debugProperties.end();
if (this->Makefile->IsConfigured())
{
this->DebugCompileDefinitionsDone = true;
}
processCompileDefinitions(this,
this->CompileDefinitionsEntries,
list,
uniqueOptions,
&dagChecker,
config,
debugDefines,
language);
std::vector<cmGeneratorTarget::TargetPropertyEntry*>
linkInterfaceCompileDefinitionsEntries;
AddInterfaceEntries(
this, config, "INTERFACE_COMPILE_DEFINITIONS",
linkInterfaceCompileDefinitionsEntries);
if (!config.empty())
{
std::string configPropName = "COMPILE_DEFINITIONS_"
+ cmSystemTools::UpperCase(config);
const char *configProp = this->Target->GetProperty(configPropName);
if (configProp)
{
switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0043))
{
case cmPolicies::WARN:
{
std::ostringstream e;
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0043);
this->LocalGenerator->IssueMessage(cmake::AUTHOR_WARNING,
e.str());
}
case cmPolicies::OLD:
{
cmGeneratorExpression ge;
cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
ge.Parse(configProp);
linkInterfaceCompileDefinitionsEntries
.push_back(new cmGeneratorTarget::TargetPropertyEntry(cge));
}
break;
case cmPolicies::NEW:
case cmPolicies::REQUIRED_ALWAYS:
case cmPolicies::REQUIRED_IF_USED:
break;
}
}
}
processCompileDefinitions(this,
linkInterfaceCompileDefinitionsEntries,
list,
uniqueOptions,
&dagChecker,
config,
debugDefines,
language);
cmDeleteAll(linkInterfaceCompileDefinitionsEntries);
}
//----------------------------------------------------------------------------
void cmGeneratorTarget::GenerateTargetManifest(
const std::string& config) const

View File

@ -224,6 +224,10 @@ public:
void GetCompileFeatures(std::vector<std::string> &features,
const std::string& config) const;
void GetCompileDefinitions(std::vector<std::string> &result,
const std::string& config,
const std::string& language) const;
bool IsSystemIncludeDirectory(const std::string& dir,
const std::string& config) const;
@ -416,6 +420,7 @@ private:
std::vector<TargetPropertyEntry*> IncludeDirectoriesEntries;
std::vector<TargetPropertyEntry*> CompileOptionsEntries;
std::vector<TargetPropertyEntry*> CompileFeaturesEntries;
std::vector<TargetPropertyEntry*> CompileDefinitionsEntries;
void ExpandLinkItems(std::string const& prop, std::string const& value,
std::string const& config, cmTarget const* headTarget,
@ -432,6 +437,7 @@ private:
mutable bool DebugIncludesDone;
mutable bool DebugCompileOptionsDone;
mutable bool DebugCompileFeaturesDone;
mutable bool DebugCompileDefinitionsDone;
public:
std::vector<cmTarget const*> const&

View File

@ -330,7 +330,8 @@ void cmGhsMultiTargetGenerator::WriteCompilerDefinitions(
const std::string &config, const std::string &language)
{
std::vector<std::string> compileDefinitions;
this->Target->GetCompileDefinitions(compileDefinitions, config, language);
this->GeneratorTarget->GetCompileDefinitions(compileDefinitions,
config, language);
for (std::vector<std::string>::const_iterator cdI =
compileDefinitions.begin();
cdI != compileDefinitions.end(); ++cdI)

View File

@ -1550,7 +1550,6 @@ void cmGlobalGenerator::CreateGeneratorTargets(TargetTypes targetTypes,
ti != targets.end(); ++ti)
{
cmTarget* t = &ti->second;
t->Compute();
cmGeneratorTarget* gt = new cmGeneratorTarget(t, lg);
this->GeneratorTargets[t] = gt;
generatorTargets[t] = gt;

View File

@ -254,7 +254,7 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget()
mf->AddUtilityCommand(CMAKE_CHECK_BUILD_SYSTEM_TARGET, false,
no_working_directory, no_depends,
noCommandLines);
tgt->Compute();
cmGeneratorTarget* gt = new cmGeneratorTarget(tgt, lg);
mf->AddGeneratorTarget(tgt, gt);

View File

@ -90,7 +90,7 @@ bool cmGlobalVisualStudioGenerator::Compute()
AddUtilityCommand("ALL_BUILD", true, no_working_dir,
no_depends, no_commands, false,
"Build all projects");
allBuild->Compute();
cmGeneratorTarget* gt = new cmGeneratorTarget(allBuild, gen[0]);
allBuild->GetMakefile()->AddGeneratorTarget(allBuild, gt);

View File

@ -463,7 +463,7 @@ cmGlobalXCodeGenerator::AddExtraTargets(cmLocalGenerator* root,
cmTarget* allbuild = mf->AddUtilityCommand("ALL_BUILD", true, no_depends,
no_working_directory,
"echo", "Build all projects");
allbuild->Compute();
cmGeneratorTarget* allBuildGt = new cmGeneratorTarget(allbuild, root);
mf->AddGeneratorTarget(allbuild, allBuildGt);
@ -498,7 +498,7 @@ cmGlobalXCodeGenerator::AddExtraTargets(cmLocalGenerator* root,
true, no_depends,
no_working_directory,
"make", "-f", file.c_str());
check->Compute();
cmGeneratorTarget* checkGt = new cmGeneratorTarget(check, root);
mf->AddGeneratorTarget(check, checkGt);
}
@ -1855,7 +1855,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
this->AppendDefines(ppDefs, exportMacro);
}
std::vector<std::string> targetDefines;
target.GetCompileDefinitions(targetDefines, configName, "C");
gtgt->GetCompileDefinitions(targetDefines, configName, "C");
this->AppendDefines(ppDefs, targetDefines);
buildSettings->AddAttribute
("GCC_PREPROCESSOR_DEFINITIONS", ppDefs.CreateList());

View File

@ -1083,7 +1083,8 @@ void cmLocalGenerator::AddCompileDefinitions(std::set<std::string>& defines,
const std::string& lang)
{
std::vector<std::string> targetDefines;
target->GetCompileDefinitions(targetDefines, config, lang);
cmGeneratorTarget* gtgt = this->GlobalGenerator->GetGeneratorTarget(target);
gtgt->GetCompileDefinitions(targetDefines, config, lang);
this->AppendDefines(defines, targetDefines);
}

View File

@ -763,7 +763,7 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
targetOptions.Parse(defineFlags.c_str());
targetOptions.ParseFinish();
std::vector<std::string> targetDefines;
target.GetCompileDefinitions(targetDefines, configName, "CXX");
gt->GetCompileDefinitions(targetDefines, configName, "CXX");
targetOptions.AddDefines(targetDefines);
targetOptions.SetVerboseMakefile(
this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));

View File

@ -474,8 +474,6 @@ bool cmQtAutoGenerators::InitializeAutogenTarget(cmLocalGenerator* lg,
/*byproducts=*/rcc_output, depends,
commandLines, false, autogenComment.c_str());
autogenTarget->Compute();
cmGeneratorTarget* gt = new cmGeneratorTarget(autogenTarget, lg);
makefile->AddGeneratorTarget(autogenTarget, gt);

View File

@ -145,7 +145,6 @@ public:
std::vector<cmListFileBacktrace> CompileFeaturesBacktraces;
std::vector<std::string> CompileDefinitionsEntries;
std::vector<cmListFileBacktrace> CompileDefinitionsBacktraces;
std::vector<TargetPropertyEntry*> CompileDefinitionsItems;
std::vector<TargetPropertyEntry*> SourceEntries;
std::vector<cmValueWithOrigin> LinkImplementationPropertyEntries;
@ -174,7 +173,6 @@ cmTarget::cmTarget()
this->IsApple = false;
this->IsImportedTarget = false;
this->BuildInterfaceIncludesAppended = false;
this->DebugCompileDefinitionsDone = false;
this->DebugSourcesDone = false;
this->LinkImplementationLanguageIsContextDependent = true;
}
@ -417,14 +415,6 @@ void CreatePropertyGeneratorExpressions(
}
}
void cmTarget::Compute()
{
CreatePropertyGeneratorExpressions(
this->Internal->CompileDefinitionsEntries,
this->Internal->CompileDefinitionsBacktraces,
this->Internal->CompileDefinitionsItems);
}
//----------------------------------------------------------------------------
void cmTarget::AddUtility(const std::string& u, cmMakefile *makefile)
{
@ -1328,6 +1318,16 @@ cmBacktraceRange cmTarget::GetCompileFeaturesBacktraces() const
return cmMakeRange(this->Internal->CompileFeaturesBacktraces);
}
cmStringRange cmTarget::GetCompileDefinitionsEntries() const
{
return cmMakeRange(this->Internal->CompileDefinitionsEntries);
}
cmBacktraceRange cmTarget::GetCompileDefinitionsBacktraces() const
{
return cmMakeRange(this->Internal->CompileDefinitionsBacktraces);
}
#if defined(_WIN32) && !defined(__CYGWIN__)
//----------------------------------------------------------------------------
void
@ -1924,156 +1924,6 @@ void cmTarget::InsertCompileDefinition(std::string const& entry,
this->Internal->CompileDefinitionsBacktraces.push_back(bt);
}
//----------------------------------------------------------------------------
static void processCompileOptionsInternal(cmTarget const* tgt,
const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
std::vector<std::string> &options,
UNORDERED_SET<std::string> &uniqueOptions,
cmGeneratorExpressionDAGChecker *dagChecker,
const std::string& config, bool debugOptions, const char *logName,
std::string const& language)
{
cmMakefile *mf = tgt->GetMakefile();
for (std::vector<cmTargetInternals::TargetPropertyEntry*>::const_iterator
it = entries.begin(), end = entries.end(); it != end; ++it)
{
std::vector<std::string> entryOptions;
cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf,
config,
false,
tgt,
dagChecker,
language),
entryOptions);
std::string usedOptions;
for(std::vector<std::string>::iterator
li = entryOptions.begin(); li != entryOptions.end(); ++li)
{
std::string const& opt = *li;
if(uniqueOptions.insert(opt).second)
{
options.push_back(opt);
if (debugOptions)
{
usedOptions += " * " + opt + "\n";
}
}
}
if (!usedOptions.empty())
{
mf->GetCMakeInstance()->IssueMessage(cmake::LOG,
std::string("Used compile ") + logName
+ std::string(" for target ")
+ tgt->GetName() + ":\n"
+ usedOptions, (*it)->ge->GetBacktrace());
}
}
}
//----------------------------------------------------------------------------
static void processCompileDefinitions(cmTarget const* tgt,
const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
std::vector<std::string> &options,
UNORDERED_SET<std::string> &uniqueOptions,
cmGeneratorExpressionDAGChecker *dagChecker,
const std::string& config, bool debugOptions,
std::string const& language)
{
processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
dagChecker, config, debugOptions,
"definitions", language);
}
//----------------------------------------------------------------------------
void cmTarget::GetCompileDefinitions(std::vector<std::string> &list,
const std::string& config,
const std::string& language) const
{
UNORDERED_SET<std::string> uniqueOptions;
cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
"COMPILE_DEFINITIONS", 0, 0);
std::vector<std::string> debugProperties;
const char *debugProp =
this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
if (debugProp)
{
cmSystemTools::ExpandListArgument(debugProp, debugProperties);
}
bool debugDefines = !this->DebugCompileDefinitionsDone
&& std::find(debugProperties.begin(),
debugProperties.end(),
"COMPILE_DEFINITIONS")
!= debugProperties.end();
if (this->Makefile->IsConfigured())
{
this->DebugCompileDefinitionsDone = true;
}
processCompileDefinitions(this,
this->Internal->CompileDefinitionsItems,
list,
uniqueOptions,
&dagChecker,
config,
debugDefines,
language);
std::vector<cmTargetInternals::TargetPropertyEntry*>
linkInterfaceCompileDefinitionsEntries;
this->Internal->AddInterfaceEntries(
this, config, "INTERFACE_COMPILE_DEFINITIONS",
linkInterfaceCompileDefinitionsEntries);
if (!config.empty())
{
std::string configPropName = "COMPILE_DEFINITIONS_"
+ cmSystemTools::UpperCase(config);
const char *configProp = this->GetProperty(configPropName);
if (configProp)
{
switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0043))
{
case cmPolicies::WARN:
{
std::ostringstream e;
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0043);
this->Makefile->IssueMessage(cmake::AUTHOR_WARNING,
e.str());
}
case cmPolicies::OLD:
{
cmGeneratorExpression ge;
cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
ge.Parse(configProp);
linkInterfaceCompileDefinitionsEntries
.push_back(new cmTargetInternals::TargetPropertyEntry(cge));
}
break;
case cmPolicies::NEW:
case cmPolicies::REQUIRED_ALWAYS:
case cmPolicies::REQUIRED_IF_USED:
break;
}
}
}
processCompileDefinitions(this,
linkInterfaceCompileDefinitionsEntries,
list,
uniqueOptions,
&dagChecker,
config,
debugDefines,
language);
cmDeleteAll(linkInterfaceCompileDefinitionsEntries);
}
//----------------------------------------------------------------------------
void cmTarget::MaybeInvalidatePropertyCache(const std::string& prop)
{
@ -4034,7 +3884,6 @@ cmTargetInternalPointer
//----------------------------------------------------------------------------
cmTargetInternalPointer::~cmTargetInternalPointer()
{
cmDeleteAll(this->Pointer->CompileDefinitionsItems);
cmDeleteAll(this->Pointer->SourceEntries);
delete this->Pointer;
}

View File

@ -132,8 +132,6 @@ public:
void AddPostBuildCommand(cmCustomCommand const &cmd)
{this->PostBuildCommands.push_back(cmd);}
void Compute();
/**
* Get the list of the source files used by this target
*/
@ -309,10 +307,6 @@ public:
If no macro should be defined null is returned. */
const char* GetExportMacro() const;
void GetCompileDefinitions(std::vector<std::string> &result,
const std::string& config,
const std::string& language) const;
// Compute the set of languages compiled by the target. This is
// computed every time it is called because the languages can change
// when source file properties are changed and we do not have enough
@ -402,6 +396,9 @@ public:
cmStringRange GetCompileFeaturesEntries() const;
cmBacktraceRange GetCompileFeaturesBacktraces() const;
cmStringRange GetCompileDefinitionsEntries() const;
cmBacktraceRange GetCompileDefinitionsBacktraces() const;
#if defined(_WIN32) && !defined(__CYGWIN__)
const LinkLibraryVectorType &GetLinkLibrariesForVS6() const {
return this->LinkLibrariesForVS6;}
@ -516,7 +513,6 @@ private:
bool IsApple;
bool IsImportedTarget;
bool BuildInterfaceIncludesAppended;
mutable bool DebugCompileDefinitionsDone;
mutable bool DebugSourcesDone;
mutable bool LinkImplementationLanguageIsContextDependent;
#if defined(_WIN32) && !defined(__CYGWIN__)

View File

@ -1934,7 +1934,7 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
clOptions.Parse(flags.c_str());
clOptions.Parse(defineFlags.c_str());
std::vector<std::string> targetDefines;
this->Target->GetCompileDefinitions(targetDefines,
this->GeneratorTarget->GetCompileDefinitions(targetDefines,
configName.c_str(), "CXX");
clOptions.AddDefines(targetDefines);
if(this->MSTools)