diff options
-rw-r--r-- | Help/release/dev/ninja-postgen-commands.rst | 5 | ||||
-rw-r--r-- | Source/cmGlobalNinjaGenerator.cxx | 39 | ||||
-rw-r--r-- | Source/cmGlobalNinjaGenerator.h | 9 |
3 files changed, 53 insertions, 0 deletions
diff --git a/Help/release/dev/ninja-postgen-commands.rst b/Help/release/dev/ninja-postgen-commands.rst new file mode 100644 index 0000000000..85b60dc057 --- /dev/null +++ b/Help/release/dev/ninja-postgen-commands.rst @@ -0,0 +1,5 @@ +ninja-postgen-commands +---------------------- + +* The :generator:`Ninja` generator learned to perform some post-processing on + the generated files for more consistent builds. diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index f5f5af852d..c9d7659817 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -530,6 +530,35 @@ void cmGlobalNinjaGenerator::Generate() if (!this->WriteDefaultBuildFile()) { return; } + + auto run_ninja_tool = [this](char const* tool) { + std::vector<std::string> command; + command.push_back(this->NinjaCommand); + command.emplace_back("-t"); + command.emplace_back(tool); + std::string error; + if (!cmSystemTools::RunSingleCommand(command, nullptr, &error, nullptr, + nullptr, + cmSystemTools::OUTPUT_NONE)) { + this->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR, + "Running\n '" + + cmJoin(command, "' '") + + "'\n" + "failed with:\n " + + error); + cmSystemTools::SetFatalErrorOccured(); + } + }; + + if (this->NinjaSupportsCleanDeadTool) { + run_ninja_tool("cleandead"); + } + if (this->NinjaSupportsUnconditionalRecompactTool) { + run_ninja_tool("recompact"); + } + if (this->NinjaSupportsRestatTool) { + run_ninja_tool("restat"); + } } bool cmGlobalNinjaGenerator::FindMakeProgram(cmMakefile* mf) @@ -593,6 +622,16 @@ void cmGlobalNinjaGenerator::CheckNinjaFeatures() } } } + this->NinjaSupportsCleanDeadTool = !cmSystemTools::VersionCompare( + cmSystemTools::OP_LESS, this->NinjaVersion.c_str(), + RequiredNinjaVersionForCleanDeadTool().c_str()); + this->NinjaSupportsUnconditionalRecompactTool = + !cmSystemTools::VersionCompare( + cmSystemTools::OP_LESS, this->NinjaVersion.c_str(), + RequiredNinjaVersionForUnconditionalRecompactTool().c_str()); + this->NinjaSupportsRestatTool = !cmSystemTools::VersionCompare( + cmSystemTools::OP_LESS, this->NinjaVersion.c_str(), + RequiredNinjaVersionForRestatTool().c_str()); } bool cmGlobalNinjaGenerator::CheckLanguages( diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h index 20e2c8e264..8691bd7ddb 100644 --- a/Source/cmGlobalNinjaGenerator.h +++ b/Source/cmGlobalNinjaGenerator.h @@ -348,6 +348,12 @@ public: return "1.9"; } static std::string RequiredNinjaVersionForDyndeps() { return "1.10"; } + static std::string RequiredNinjaVersionForRestatTool() { return "1.10"; } + static std::string RequiredNinjaVersionForUnconditionalRecompactTool() + { + return "1.10"; + } + static std::string RequiredNinjaVersionForCleanDeadTool() { return "1.10"; } bool SupportsConsolePool() const; bool SupportsImplicitOuts() const; bool SupportsManifestRestat() const; @@ -488,6 +494,9 @@ private: bool NinjaSupportsManifestRestat = false; bool NinjaSupportsMultilineDepfile = false; bool NinjaSupportsDyndeps = false; + bool NinjaSupportsRestatTool = false; + bool NinjaSupportsUnconditionalRecompactTool = false; + bool NinjaSupportsCleanDeadTool = false; private: void InitOutputPathPrefix(); |