diff options
author | Adam Strzelecki <ono@java.pl> | 2014-06-27 22:13:52 +0200 |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2014-06-30 09:33:37 -0400 |
commit | 93371ed592b85ccc179845dbd6e6018ca2193659 (patch) | |
tree | 7a43634f2c71a9e866c724c334eeececc0cf726b | |
parent | 7243c95129fd8cd0d01495d33848663c796f91db (diff) | |
download | cmake-93371ed592b85ccc179845dbd6e6018ca2193659.tar.gz |
Ninja: Skip generating empty phony rules
Ninja generator ensures that all custom commands being target
dependencies are run before other source compilations. However in case
there are no such dependencies it currently generates empty phony rules
which clutter the build graph.
Teach the Ninja generator to produce such rules only when necessary.
-rw-r--r-- | Source/cmNinjaTargetGenerator.cxx | 32 | ||||
-rw-r--r-- | Source/cmNinjaTargetGenerator.h | 3 |
2 files changed, 21 insertions, 14 deletions
diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 24689fb58e..816e6d827a 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -542,22 +542,24 @@ cmNinjaTargetGenerator std::back_inserter(orderOnlyDeps), MapToNinjaPath()); } - cmNinjaDeps orderOnlyTarget; - orderOnlyTarget.push_back(this->OrderDependsTargetForTarget()); - this->GetGlobalGenerator()->WritePhonyBuild(this->GetBuildFileStream(), - "Order-only phony target for " - + this->GetTargetName(), - orderOnlyTarget, - cmNinjaDeps(), - cmNinjaDeps(), - orderOnlyDeps); - + if (!orderOnlyDeps.empty()) + { + 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<cmSourceFile const*> objectSources; this->GeneratorTarget->GetObjectSources(objectSources, config); for(std::vector<cmSourceFile const*>::const_iterator si = objectSources.begin(); si != objectSources.end(); ++si) { - this->WriteObjectBuildStatement(*si); + this->WriteObjectBuildStatement(*si, !orderOnlyDeps.empty()); } std::string def = this->GeneratorTarget->GetModuleDefinitionFile(config); if(!def.empty()) @@ -570,7 +572,8 @@ cmNinjaTargetGenerator void cmNinjaTargetGenerator -::WriteObjectBuildStatement(cmSourceFile const* source) +::WriteObjectBuildStatement( + cmSourceFile const* source, bool writeOrderDependsTargetForTarget) { std::string comment; const std::string language = source->GetLanguage(); @@ -599,7 +602,10 @@ cmNinjaTargetGenerator } cmNinjaDeps orderOnlyDeps; - orderOnlyDeps.push_back(this->OrderDependsTargetForTarget()); + if (writeOrderDependsTargetForTarget) + { + orderOnlyDeps.push_back(this->OrderDependsTargetForTarget()); + } // If the source file is GENERATED and does not have a custom command // (either attached to this source file or another one), assume that one of diff --git a/Source/cmNinjaTargetGenerator.h b/Source/cmNinjaTargetGenerator.h index 94c420fb8c..40a15a3ac9 100644 --- a/Source/cmNinjaTargetGenerator.h +++ b/Source/cmNinjaTargetGenerator.h @@ -114,7 +114,8 @@ protected: void WriteLanguageRules(const std::string& language); void WriteCompileRule(const std::string& language); void WriteObjectBuildStatements(); - void WriteObjectBuildStatement(cmSourceFile const* source); + void WriteObjectBuildStatement(cmSourceFile const* source, + bool writeOrderDependsTargetForTarget); void WriteCustomCommandBuildStatement(cmCustomCommand *cc); cmNinjaDeps GetObjects() const |