From 80de856bb5cba20d424b91e4a49fe8fdb1f904a3 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 18 Oct 2015 23:13:50 +0200 Subject: Ninja: Port to cmGeneratorTarget. --- Source/cmGlobalNinjaGenerator.cxx | 23 +++++++++----------- Source/cmGlobalNinjaGenerator.h | 12 ++++++----- Source/cmLocalNinjaGenerator.cxx | 10 ++++----- Source/cmLocalNinjaGenerator.h | 9 ++++---- Source/cmNinjaNormalTargetGenerator.cxx | 36 ++++++++++++++++---------------- Source/cmNinjaTargetGenerator.cxx | 11 ++++++---- Source/cmNinjaTargetGenerator.h | 5 +---- Source/cmNinjaUtilityTargetGenerator.cxx | 16 +++++++------- 8 files changed, 62 insertions(+), 60 deletions(-) diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 6e650ce..2671f4d 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -886,7 +886,7 @@ void cmGlobalNinjaGenerator::WriteDisclaimer(std::ostream& os) << cmVersion::GetMinorVersion() << "\n\n"; } -void cmGlobalNinjaGenerator::AddDependencyToAll(cmTarget* target) +void cmGlobalNinjaGenerator::AddDependencyToAll(cmGeneratorTarget* target) { this->AppendTargetOutputs(target, this->AllDependencies); } @@ -912,18 +912,16 @@ void cmGlobalNinjaGenerator::WriteAssumedSourceDependencies() void cmGlobalNinjaGenerator -::AppendTargetOutputs(cmTarget const* target, cmNinjaDeps& outputs) +::AppendTargetOutputs(cmGeneratorTarget const* target, cmNinjaDeps& outputs) { std::string configName = - target->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE"); - - cmGeneratorTarget *gtgt = this->GetGeneratorTarget(target); + target->Target->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE"); // for frameworks, we want the real name, not smple name // frameworks always appear versioned, and the build.ninja // will always attempt to manage symbolic links instead // of letting cmOSXBundleGenerator do it. - bool realname = gtgt->IsFrameworkOnApple(); + bool realname = target->IsFrameworkOnApple(); switch (target->GetType()) { case cmState::EXECUTABLE: @@ -932,7 +930,7 @@ cmGlobalNinjaGenerator case cmState::MODULE_LIBRARY: { outputs.push_back(this->ConvertToNinjaPath( - gtgt->GetFullPath(configName, false, realname))); + target->GetFullPath(configName, false, realname))); break; } case cmState::OBJECT_LIBRARY: @@ -962,16 +960,15 @@ cmGlobalNinjaGenerator void cmGlobalNinjaGenerator -::AppendTargetDepends(cmTarget const* target, cmNinjaDeps& outputs) +::AppendTargetDepends(cmGeneratorTarget const* target, cmNinjaDeps& outputs) { if (target->GetType() == cmState::GLOBAL_TARGET) { // Global targets only depend on other utilities, which may not appear in // the TargetDepends set (e.g. "all"). - std::set const& utils = target->GetUtilities(); + std::set const& utils = target->Target->GetUtilities(); std::copy(utils.begin(), utils.end(), std::back_inserter(outputs)); } else { - cmGeneratorTarget* gt = this->GetGeneratorTarget(target); - cmTargetDependSet const& targetDeps = this->GetTargetDirectDepends(gt); + cmTargetDependSet const& targetDeps = this->GetTargetDirectDepends(target); for (cmTargetDependSet::const_iterator i = targetDeps.begin(); i != targetDeps.end(); ++i) { @@ -979,13 +976,13 @@ cmGlobalNinjaGenerator { continue; } - this->AppendTargetOutputs((*i)->Target, outputs); + this->AppendTargetOutputs(*i, outputs); } } } void cmGlobalNinjaGenerator::AddTargetAlias(const std::string& alias, - cmTarget* target) { + cmGeneratorTarget* target) { cmNinjaDeps outputs; this->AppendTargetOutputs(target, outputs); // Mark the target's outputs as ambiguous to ensure that no other target uses diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h index 292f7c7..7547f16 100644 --- a/Source/cmGlobalNinjaGenerator.h +++ b/Source/cmGlobalNinjaGenerator.h @@ -285,9 +285,11 @@ public: ASD.insert(deps.begin(), deps.end()); } - void AppendTargetOutputs(cmTarget const* target, cmNinjaDeps& outputs); - void AppendTargetDepends(cmTarget const* target, cmNinjaDeps& outputs); - void AddDependencyToAll(cmTarget* target); + void AppendTargetOutputs(cmGeneratorTarget const* target, + cmNinjaDeps& outputs); + void AppendTargetDepends(cmGeneratorTarget const* target, + cmNinjaDeps& outputs); + void AddDependencyToAll(cmGeneratorTarget* target); void AddDependencyToAll(const std::string& input); const std::vector& GetLocalGenerators() const { @@ -299,7 +301,7 @@ public: int GetRuleCmdLength(const std::string& name) { return RuleCmdLength[name]; } - void AddTargetAlias(const std::string& alias, cmTarget* target); + void AddTargetAlias(const std::string& alias, cmGeneratorTarget* target); virtual void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const; @@ -388,7 +390,7 @@ private: /// The mapping from source file to assumed dependencies. std::map > AssumedSourceDependencies; - typedef std::map TargetAliasMap; + typedef std::map TargetAliasMap; TargetAliasMap TargetAliases; }; diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index 3dd18bd..891c44e 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/Source/cmLocalNinjaGenerator.cxx @@ -89,7 +89,7 @@ void cmLocalNinjaGenerator::Generate() if (!this->GetGlobalNinjaGenerator()->IsExcluded( this->GetGlobalNinjaGenerator()->GetLocalGenerators()[0], *t)) - this->GetGlobalNinjaGenerator()->AddDependencyToAll((*t)->Target); + this->GetGlobalNinjaGenerator()->AddDependencyToAll(*t); delete tg; } } @@ -285,14 +285,14 @@ void cmLocalNinjaGenerator::WriteProcessedMakefile(std::ostream& os) void cmLocalNinjaGenerator -::AppendTargetOutputs(cmTarget* target, cmNinjaDeps& outputs) +::AppendTargetOutputs(cmGeneratorTarget* target, cmNinjaDeps& outputs) { this->GetGlobalNinjaGenerator()->AppendTargetOutputs(target, outputs); } void cmLocalNinjaGenerator -::AppendTargetDepends(cmTarget* target, cmNinjaDeps& outputs) +::AppendTargetDepends(cmGeneratorTarget* target, cmNinjaDeps& outputs) { this->GetGlobalNinjaGenerator()->AppendTargetDepends(target, outputs); } @@ -441,7 +441,7 @@ cmLocalNinjaGenerator::WriteCustomCommandBuildStatement( } void cmLocalNinjaGenerator::AddCustomCommandTarget(cmCustomCommand const* cc, - cmTarget* target) + cmGeneratorTarget* target) { this->CustomCommandTargets[cc].insert(target); } @@ -459,7 +459,7 @@ void cmLocalNinjaGenerator::WriteCustomCommandBuildStatements() // // FIXME: This won't work in certain obscure scenarios involving indirect // dependencies. - std::set::iterator j = i->second.begin(); + std::set::iterator j = i->second.begin(); assert(j != i->second.end()); std::vector ccTargetDeps; this->AppendTargetDepends(*j, ccTargetDeps); diff --git a/Source/cmLocalNinjaGenerator.h b/Source/cmLocalNinjaGenerator.h index ce5f82d..b6987ef 100644 --- a/Source/cmLocalNinjaGenerator.h +++ b/Source/cmLocalNinjaGenerator.h @@ -58,10 +58,11 @@ public: std::string BuildCommandLine(const std::vector &cmdLines); - void AppendTargetOutputs(cmTarget* target, cmNinjaDeps& outputs); - void AppendTargetDepends(cmTarget* target, cmNinjaDeps& outputs); + void AppendTargetOutputs(cmGeneratorTarget* target, cmNinjaDeps& outputs); + void AppendTargetDepends(cmGeneratorTarget* target, cmNinjaDeps& outputs); - void AddCustomCommandTarget(cmCustomCommand const* cc, cmTarget* target); + void AddCustomCommandTarget(cmCustomCommand const* cc, + cmGeneratorTarget* target); void AppendCustomCommandLines(cmCustomCommandGenerator const& ccg, std::vector &cmdLines); void AppendCustomCommandDeps(cmCustomCommandGenerator const& ccg, @@ -102,7 +103,7 @@ private: std::string HomeRelativeOutputPath; - typedef std::map > + typedef std::map > CustomCommandTargetMap; CustomCommandTargetMap CustomCommandTargets; }; diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index dafbda9..b533d37 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -399,7 +399,6 @@ static int calculateCommandLineLengthLimit(int linkRuleLength) void cmNinjaNormalTargetGenerator::WriteLinkStatement() { - cmTarget& target = *this->GetTarget(); cmGeneratorTarget& gt = *this->GetGeneratorTarget(); const std::string cfgName = this->GetConfigName(); std::string targetOutput = ConvertToNinjaPath( @@ -443,7 +442,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() // Write comments. cmGlobalNinjaGenerator::WriteDivider(this->GetBuildFileStream()); - const cmState::TargetType targetType = target.GetType(); + const cmState::TargetType targetType = gt.GetType(); this->GetBuildFileStream() << "# Link build statements for " << cmState::GetTargetTypeName(targetType) @@ -490,13 +489,13 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() &genTarget, useWatcomQuote); if(this->GetMakefile()->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS") - && target.GetType() == cmState::SHARED_LIBRARY) + && gt.GetType() == cmState::SHARED_LIBRARY) { - if(target.GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS")) + if(gt.GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS")) { std::string name_of_def_file = gt.GetSupportDirectory(); - name_of_def_file += "/" + target.GetName(); + name_of_def_file += "/" + gt.GetName(); name_of_def_file += ".def "; vars["LINK_FLAGS"] += " /DEF:"; vars["LINK_FLAGS"] += this->GetLocalGenerator() @@ -505,7 +504,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() } } - this->addPoolNinjaVariable("JOB_POOL_LINK", &target, vars); + this->addPoolNinjaVariable("JOB_POOL_LINK", >, vars); this->AddModuleDefinitionFlag(vars["LINK_FLAGS"]); vars["LINK_FLAGS"] = cmGlobalNinjaGenerator @@ -599,9 +598,9 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() } const std::vector *cmdLists[3] = { - &target.GetPreBuildCommands(), - &target.GetPreLinkCommands(), - &target.GetPostBuildCommands() + >.Target->GetPreBuildCommands(), + >.Target->GetPreLinkCommands(), + >.Target->GetPostBuildCommands() }; std::vector preLinkCmdLines, postBuildCmdLines; @@ -626,17 +625,17 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() } // maybe create .def file from list of objects - if (target.GetType() == cmState::SHARED_LIBRARY && + if (gt.GetType() == cmState::SHARED_LIBRARY && this->GetMakefile()->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS")) { - if(target.GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS")) + if(gt.GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS")) { std::string cmakeCommand = this->GetLocalGenerator()->ConvertToOutputFormat( cmSystemTools::GetCMakeCommand(), cmLocalGenerator::SHELL); std::string name_of_def_file = gt.GetSupportDirectory(); - name_of_def_file += "/" + target.GetName(); + name_of_def_file += "/" + gt.GetName(); name_of_def_file += ".def"; std::string cmd = cmakeCommand; cmd += " -E __create_def "; @@ -699,11 +698,11 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() const std::string rspfile = std::string(cmake::GetCMakeFilesDirectoryPostSlash()) - + target.GetName() + ".rsp"; + + gt.GetName() + ".rsp"; // Gather order-only dependencies. cmNinjaDeps orderOnlyDeps; - this->GetLocalGenerator()->AppendTargetDepends(this->GetTarget(), + this->GetLocalGenerator()->AppendTargetDepends(this->GetGeneratorTarget(), orderOnlyDeps); // Ninja should restat after linking if and only if there are byproducts. @@ -772,8 +771,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() } // Add aliases for the file name and the target name. - globalGen.AddTargetAlias(this->TargetNameOut, &target); - globalGen.AddTargetAlias(this->GetTargetName(), &target); + globalGen.AddTargetAlias(this->TargetNameOut, >); + globalGen.AddTargetAlias(this->GetTargetName(), >); } //---------------------------------------------------------------------------- @@ -781,7 +780,8 @@ void cmNinjaNormalTargetGenerator::WriteObjectLibStatement() { // Write a phony output that depends on all object files. cmNinjaDeps outputs; - this->GetLocalGenerator()->AppendTargetOutputs(this->GetTarget(), outputs); + this->GetLocalGenerator()->AppendTargetOutputs(this->GetGeneratorTarget(), + outputs); cmNinjaDeps depends = this->GetObjects(); this->GetGlobalGenerator()->WritePhonyBuild(this->GetBuildFileStream(), "Object library " @@ -791,5 +791,5 @@ void cmNinjaNormalTargetGenerator::WriteObjectLibStatement() // Add aliases for the target name. this->GetGlobalGenerator()->AddTargetAlias(this->GetTargetName(), - this->GetTarget()); + this->GetGeneratorTarget()); } diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index b018005..dc2c7a6 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -486,7 +486,8 @@ cmNinjaTargetGenerator si != customCommands.end(); ++si) { cmCustomCommand const* cc = (*si)->GetCustomCommand(); - this->GetLocalGenerator()->AddCustomCommandTarget(cc, this->GetTarget()); + this->GetLocalGenerator()->AddCustomCommandTarget(cc, + this->GetGeneratorTarget()); // Record the custom commands for this target. The container is used // in WriteObjectBuildStatement when called in a loop below. this->CustomCommands.push_back(cc); @@ -511,7 +512,8 @@ cmNinjaTargetGenerator } cmNinjaDeps orderOnlyDeps; - this->GetLocalGenerator()->AppendTargetDepends(this->Target, orderOnlyDeps); + this->GetLocalGenerator()->AppendTargetDepends(this->GeneratorTarget, + orderOnlyDeps); // Add order-only dependencies on custom command outputs. for(std::vector::const_iterator @@ -633,7 +635,8 @@ cmNinjaTargetGenerator ConvertToNinjaPath(objectFileDir), cmLocalGenerator::SHELL); - this->addPoolNinjaVariable("JOB_POOL_COMPILE", this->GetTarget(), vars); + this->addPoolNinjaVariable("JOB_POOL_COMPILE", + this->GetGeneratorTarget(), vars); this->SetMsvcTargetPdbVariable(vars); @@ -782,7 +785,7 @@ cmNinjaTargetGenerator::MacOSXContentGeneratorType::operator()( void cmNinjaTargetGenerator::addPoolNinjaVariable( const std::string& pool_property, - cmTarget* target, + cmGeneratorTarget* target, cmNinjaVars& vars) { const char* pool = target->GetProperty(pool_property); diff --git a/Source/cmNinjaTargetGenerator.h b/Source/cmNinjaTargetGenerator.h index 0267f63..e3ec423 100644 --- a/Source/cmNinjaTargetGenerator.h +++ b/Source/cmNinjaTargetGenerator.h @@ -53,9 +53,6 @@ protected: cmGeneratedFileStream& GetBuildFileStream() const; cmGeneratedFileStream& GetRulesFileStream() const; - cmTarget* GetTarget() const - { return this->Target; } - cmGeneratorTarget* GetGeneratorTarget() const { return this->GeneratorTarget; } @@ -152,7 +149,7 @@ protected: std::set MacContentFolders; void addPoolNinjaVariable(const std::string& pool_property, - cmTarget* target, + cmGeneratorTarget* target, cmNinjaVars& vars); private: diff --git a/Source/cmNinjaUtilityTargetGenerator.cxx b/Source/cmNinjaUtilityTargetGenerator.cxx index 5bbe268..b2a5334 100644 --- a/Source/cmNinjaUtilityTargetGenerator.cxx +++ b/Source/cmNinjaUtilityTargetGenerator.cxx @@ -16,7 +16,6 @@ #include "cmGlobalNinjaGenerator.h" #include "cmMakefile.h" #include "cmSourceFile.h" -#include "cmTarget.h" #include "cmCustomCommandGenerator.h" cmNinjaUtilityTargetGenerator::cmNinjaUtilityTargetGenerator( @@ -34,8 +33,8 @@ void cmNinjaUtilityTargetGenerator::Generate() cmNinjaDeps deps, outputs, util_outputs(1, utilCommandName); const std::vector *cmdLists[2] = { - &this->GetTarget()->GetPreBuildCommands(), - &this->GetTarget()->GetPostBuildCommands() + &this->GetGeneratorTarget()->Target->GetPreBuildCommands(), + &this->GetGeneratorTarget()->Target->GetPostBuildCommands() }; bool uses_terminal = false; @@ -66,7 +65,8 @@ void cmNinjaUtilityTargetGenerator::Generate() { cmCustomCommandGenerator ccg(*cc, this->GetConfigName(), this->GetLocalGenerator()); - this->GetLocalGenerator()->AddCustomCommandTarget(cc, this->GetTarget()); + this->GetLocalGenerator()->AddCustomCommandTarget(cc, + this->GetGeneratorTarget()); // Depend on all custom command outputs. const std::vector& ccOutputs = ccg.GetOutputs(); @@ -78,8 +78,10 @@ void cmNinjaUtilityTargetGenerator::Generate() } } - this->GetLocalGenerator()->AppendTargetOutputs(this->GetTarget(), outputs); - this->GetLocalGenerator()->AppendTargetDepends(this->GetTarget(), deps); + this->GetLocalGenerator()->AppendTargetOutputs(this->GetGeneratorTarget(), + outputs); + this->GetLocalGenerator()->AppendTargetDepends(this->GetGeneratorTarget(), + deps); if (commands.empty()) { this->GetGlobalGenerator()->WritePhonyBuild(this->GetBuildFileStream(), @@ -140,5 +142,5 @@ void cmNinjaUtilityTargetGenerator::Generate() } this->GetGlobalGenerator()->AddTargetAlias(this->GetTargetName(), - this->GetTarget()); + this->GetGeneratorTarget()); } -- cgit v0.12