From 18e478a860ce480f47ca2fdf583f3c5d65f93ccf Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 10 Mar 2014 18:48:46 -0400 Subject: [PATCH] ninja: Factor out target-level order-only dependencies This reduces ninja file output even more for projects with lots of libraries with entangled transitive dependencies. ParaView goes from the previous 58M to about 45M. --- Source/cmNinjaTargetGenerator.cxx | 27 ++++++++++++++++++++++----- Source/cmNinjaTargetGenerator.h | 4 ++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index b95c4889d..0b379bdd1 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -121,6 +121,12 @@ void cmNinjaTargetGenerator::AddFeatureFlags(std::string& flags, } } +std::string +cmNinjaTargetGenerator::OrderDependsTargetForTarget() +{ + return "cmake_order_depends_target_" + this->GetTargetName(); +} + // TODO: Most of the code is picked up from // void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink), // void cmMakefileTargetGenerator::WriteTargetLanguageFlags() @@ -516,6 +522,19 @@ cmNinjaTargetGenerator { this->Objects.push_back(this->GetSourceFilePath(*si)); } + + cmNinjaDeps orderOnlyDeps; + this->GetLocalGenerator()->AppendTargetDepends(this->Target, orderOnlyDeps); + cmNinjaDeps orderOnlyTarget; + orderOnlyTarget.push_back(this->OrderDependsTargetForTarget()); + this->GetGlobalGenerator()->WritePhonyBuild(this->GetBuildFileStream(), + "Order-only phony target for " + + this->GetTargetName(), + orderOnlyTarget, + cmNinjaDeps(), + cmNinjaDeps(), + orderOnlyDeps); + std::vector objectSources; this->GeneratorTarget->GetObjectSources(objectSources, config); for(std::vector::const_iterator @@ -554,11 +573,6 @@ cmNinjaTargetGenerator sourceFileName = this->GetSourceFilePath(source); explicitDeps.push_back(sourceFileName); - // Ensure that the target dependencies are built before any source file in - // the target, using order-only dependencies. - cmNinjaDeps orderOnlyDeps; - this->GetLocalGenerator()->AppendTargetDepends(this->Target, orderOnlyDeps); - cmNinjaDeps implicitDeps; if(const char* objectDeps = source->GetProperty("OBJECT_DEPENDS")) { std::vector depList; @@ -567,6 +581,9 @@ cmNinjaTargetGenerator std::back_inserter(implicitDeps), MapToNinjaPath()); } + cmNinjaDeps orderOnlyDeps; + orderOnlyDeps.push_back(this->OrderDependsTargetForTarget()); + // Add order-only dependencies on custom command outputs. for(std::vector::const_iterator cci = this->CustomCommands.begin(); diff --git a/Source/cmNinjaTargetGenerator.h b/Source/cmNinjaTargetGenerator.h index be516e07a..94c420fb8 100644 --- a/Source/cmNinjaTargetGenerator.h +++ b/Source/cmNinjaTargetGenerator.h @@ -74,6 +74,10 @@ protected: bool GetFeatureAsBool(const std::string& feature); void AddFeatureFlags(std::string& flags, const std::string& lang); + std::string OrderDependsTargetForTarget(); + + std::string ComputeOrderDependsForTarget(); + /** * Compute the flags for compilation of object files for a given @a language. * @note Generally it is the value of the variable whose name is computed