From a7f5d70dde50ac74726f3c23d276d2fdac70d659 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 5 Aug 2015 00:00:53 +0200 Subject: [PATCH] cmGeneratorTarget: Move compile defintions processing from cmTarget. --- Source/cmExtraCodeBlocksGenerator.cxx | 2 +- Source/cmGeneratorTarget.cxx | 111 ++++++++++++- Source/cmGeneratorTarget.h | 6 + Source/cmGhsMultiTargetGenerator.cxx | 3 +- Source/cmGlobalGenerator.cxx | 1 - Source/cmGlobalVisualStudio8Generator.cxx | 2 +- Source/cmGlobalVisualStudioGenerator.cxx | 2 +- Source/cmGlobalXCodeGenerator.cxx | 6 +- Source/cmLocalGenerator.cxx | 3 +- Source/cmLocalVisualStudio7Generator.cxx | 2 +- Source/cmQtAutoGenerators.cxx | 2 - Source/cmTarget.cxx | 171 ++------------------- Source/cmTarget.h | 10 +- Source/cmVisualStudio10TargetGenerator.cxx | 2 +- 14 files changed, 141 insertions(+), 182 deletions(-) diff --git a/Source/cmExtraCodeBlocksGenerator.cxx b/Source/cmExtraCodeBlocksGenerator.cxx index 933a256af..dfd51c754 100644 --- a/Source/cmExtraCodeBlocksGenerator.cxx +++ b/Source/cmExtraCodeBlocksGenerator.cxx @@ -609,7 +609,7 @@ void cmExtraCodeBlocksGenerator::AppendTarget(cmGeneratedFileStream& fout, // the compilerdefines for this target std::vector cdefs; - target->GetCompileDefinitions(cdefs, buildType, "C"); + gtgt->GetCompileDefinitions(cdefs, buildType, "C"); // Expand the list. for(std::vector::const_iterator di = cdefs.begin(); diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 5a67c1590..c499cd9d0 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -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 &result, cmDeleteAll(linkInterfaceCompileFeaturesEntries); } +//---------------------------------------------------------------------------- +static void processCompileDefinitions(cmGeneratorTarget const* tgt, + const std::vector &entries, + std::vector &options, + UNORDERED_SET &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 &list, + const std::string& config, + const std::string& language) const +{ + UNORDERED_SET uniqueOptions; + + cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), + "COMPILE_DEFINITIONS", 0, 0); + + std::vector 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 + 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 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 diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 7e718af7d..557eb1782 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -224,6 +224,10 @@ public: void GetCompileFeatures(std::vector &features, const std::string& config) const; + void GetCompileDefinitions(std::vector &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 IncludeDirectoriesEntries; std::vector CompileOptionsEntries; std::vector CompileFeaturesEntries; + std::vector 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 const& diff --git a/Source/cmGhsMultiTargetGenerator.cxx b/Source/cmGhsMultiTargetGenerator.cxx index 790e68b2a..846b6e2f8 100644 --- a/Source/cmGhsMultiTargetGenerator.cxx +++ b/Source/cmGhsMultiTargetGenerator.cxx @@ -330,7 +330,8 @@ void cmGhsMultiTargetGenerator::WriteCompilerDefinitions( const std::string &config, const std::string &language) { std::vector compileDefinitions; - this->Target->GetCompileDefinitions(compileDefinitions, config, language); + this->GeneratorTarget->GetCompileDefinitions(compileDefinitions, + config, language); for (std::vector::const_iterator cdI = compileDefinitions.begin(); cdI != compileDefinitions.end(); ++cdI) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 503c455f9..c0f1817a5 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -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; diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx index 51dcab06b..28f0425d0 100644 --- a/Source/cmGlobalVisualStudio8Generator.cxx +++ b/Source/cmGlobalVisualStudio8Generator.cxx @@ -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); diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx index b0aa243dc..634366e12 100644 --- a/Source/cmGlobalVisualStudioGenerator.cxx +++ b/Source/cmGlobalVisualStudioGenerator.cxx @@ -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); diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 4ba29f50f..87c61dd25 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -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 targetDefines; - target.GetCompileDefinitions(targetDefines, configName, "C"); + gtgt->GetCompileDefinitions(targetDefines, configName, "C"); this->AppendDefines(ppDefs, targetDefines); buildSettings->AddAttribute ("GCC_PREPROCESSOR_DEFINITIONS", ppDefs.CreateList()); diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index a7e41912a..c1cc241d1 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1083,7 +1083,8 @@ void cmLocalGenerator::AddCompileDefinitions(std::set& defines, const std::string& lang) { std::vector targetDefines; - target->GetCompileDefinitions(targetDefines, config, lang); + cmGeneratorTarget* gtgt = this->GlobalGenerator->GetGeneratorTarget(target); + gtgt->GetCompileDefinitions(targetDefines, config, lang); this->AppendDefines(defines, targetDefines); } diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 5de6d37a2..f17c9a4c6 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -763,7 +763,7 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout, targetOptions.Parse(defineFlags.c_str()); targetOptions.ParseFinish(); std::vector targetDefines; - target.GetCompileDefinitions(targetDefines, configName, "CXX"); + gt->GetCompileDefinitions(targetDefines, configName, "CXX"); targetOptions.AddDefines(targetDefines); targetOptions.SetVerboseMakefile( this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE")); diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index f85e70e64..c58e7e4f3 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -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); diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 4ddbcb368..ea03ffe20 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -145,7 +145,6 @@ public: std::vector CompileFeaturesBacktraces; std::vector CompileDefinitionsEntries; std::vector CompileDefinitionsBacktraces; - std::vector CompileDefinitionsItems; std::vector SourceEntries; std::vector 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 &entries, - std::vector &options, - UNORDERED_SET &uniqueOptions, - cmGeneratorExpressionDAGChecker *dagChecker, - const std::string& config, bool debugOptions, const char *logName, - std::string const& language) -{ - cmMakefile *mf = tgt->GetMakefile(); - - for (std::vector::const_iterator - it = entries.begin(), end = entries.end(); it != end; ++it) - { - std::vector entryOptions; - cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf, - config, - false, - tgt, - dagChecker, - language), - entryOptions); - std::string usedOptions; - for(std::vector::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 &entries, - std::vector &options, - UNORDERED_SET &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 &list, - const std::string& config, - const std::string& language) const -{ - UNORDERED_SET uniqueOptions; - - cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), - "COMPILE_DEFINITIONS", 0, 0); - - std::vector 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 - 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 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; } diff --git a/Source/cmTarget.h b/Source/cmTarget.h index aae558e74..34a75eac8 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -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 &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__) diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 823b550ad..464a83a19 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -1934,7 +1934,7 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( clOptions.Parse(flags.c_str()); clOptions.Parse(defineFlags.c_str()); std::vector targetDefines; - this->Target->GetCompileDefinitions(targetDefines, + this->GeneratorTarget->GetCompileDefinitions(targetDefines, configName.c_str(), "CXX"); clOptions.AddDefines(targetDefines); if(this->MSTools)