summaryrefslogtreecommitdiffstats
path: root/Source/cmGlobalNinjaGenerator.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmGlobalNinjaGenerator.cxx')
-rw-r--r--Source/cmGlobalNinjaGenerator.cxx91
1 files changed, 72 insertions, 19 deletions
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx
index 2a59708..0487ad1 100644
--- a/Source/cmGlobalNinjaGenerator.cxx
+++ b/Source/cmGlobalNinjaGenerator.cxx
@@ -25,6 +25,7 @@
#include "cmGeneratorExpressionEvaluationFile.h"
#include "cmGeneratorTarget.h"
#include "cmGlobalGenerator.h"
+#include "cmLinkLineComputer.h"
#include "cmListFileCache.h"
#include "cmLocalGenerator.h"
#include "cmLocalNinjaGenerator.h"
@@ -44,8 +45,6 @@
#include "cmVersion.h"
#include "cmake.h"
-class cmLinkLineComputer;
-
const char* cmGlobalNinjaGenerator::NINJA_BUILD_FILE = "build.ninja";
const char* cmGlobalNinjaGenerator::NINJA_RULES_FILE = "rules.ninja";
const char* cmGlobalNinjaGenerator::INDENT = " ";
@@ -85,13 +84,15 @@ void cmGlobalNinjaGenerator::WriteComment(std::ostream& os,
os << "# " << comment.substr(lpos) << "\n\n";
}
-cmLinkLineComputer* cmGlobalNinjaGenerator::CreateLinkLineComputer(
+std::unique_ptr<cmLinkLineComputer>
+cmGlobalNinjaGenerator::CreateLinkLineComputer(
cmOutputConverter* outputConverter,
cmStateDirectory const& /* stateDir */) const
{
- return new cmNinjaLinkLineComputer(
- outputConverter,
- this->LocalGenerators[0]->GetStateSnapshot().GetDirectory(), this);
+ return std::unique_ptr<cmLinkLineComputer>(
+ cm::make_unique<cmNinjaLinkLineComputer>(
+ outputConverter,
+ this->LocalGenerators[0]->GetStateSnapshot().GetDirectory(), this));
}
std::string cmGlobalNinjaGenerator::EncodeRuleName(std::string const& name)
@@ -529,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)
@@ -592,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(
@@ -1152,7 +1192,10 @@ void cmGlobalNinjaGenerator::WriteTargetAliases(std::ostream& os)
this->AppendTargetOutputs(ta.second.GeneratorTarget, build.ExplicitDeps,
ta.second.Config);
}
- this->WriteBuild(os, build);
+ this->WriteBuild(this->EnableCrossConfigBuild()
+ ? os
+ : *this->GetConfigFileStream(ta.second.Config),
+ build);
}
if (this->IsMultiConfig()) {
@@ -1219,7 +1262,10 @@ void cmGlobalNinjaGenerator::WriteFolderTargets(std::ostream& os)
}
}
// Write target
- this->WriteBuild(os, build);
+ this->WriteBuild(this->EnableCrossConfigBuild()
+ ? os
+ : *this->GetConfigFileStream(config),
+ build);
}
// Add shortcut target
@@ -1234,7 +1280,7 @@ void cmGlobalNinjaGenerator::WriteFolderTargets(std::ostream& os)
}
// Add target for all configs
- if (this->IsMultiConfig()) {
+ if (this->EnableCrossConfigBuild()) {
build.ExplicitDeps.clear();
for (auto const& config : configs) {
build.ExplicitDeps.push_back(this->BuildAlias(
@@ -1242,7 +1288,7 @@ void cmGlobalNinjaGenerator::WriteFolderTargets(std::ostream& os)
}
build.Outputs.front() = this->BuildAlias(
this->ConvertToNinjaPath(currentBinaryDir + "/all"), "all");
- this->WriteBuild(*this->GetCommonFileStream(), build);
+ this->WriteBuild(os, build);
}
}
}
@@ -1290,8 +1336,7 @@ void cmGlobalNinjaGenerator::WriteUnknownExplicitDependencies(std::ostream& os)
knownDependencies.insert(this->ConvertToNinjaPath(j));
}
}
- for (cmGeneratorExpressionEvaluationFile* li :
- lg->GetMakefile()->GetEvaluationFiles()) {
+ for (const auto& li : lg->GetMakefile()->GetEvaluationFiles()) {
// get all the files created by generator expressions and convert them
// to ninja paths
for (std::string const& evaluationFile : li->GetFiles()) {
@@ -1670,6 +1715,9 @@ void cmGlobalNinjaGenerator::WriteTargetClean(std::ostream& os)
config));
}
for (auto const& fileConfig : configs) {
+ if (fileConfig != config && !this->EnableCrossConfigBuild()) {
+ continue;
+ }
if (this->IsMultiConfig()) {
build.Variables["FILE_ARG"] = cmStrCat(
"-f ", cmGlobalNinjaMultiGenerator::GetNinjaFilename(fileConfig));
@@ -1678,7 +1726,7 @@ void cmGlobalNinjaGenerator::WriteTargetClean(std::ostream& os)
}
}
- if (this->IsMultiConfig()) {
+ if (this->EnableCrossConfigBuild()) {
build.Outputs.front() = this->BuildAlias(
this->NinjaOutputPath(this->GetCleanTargetName()), "all");
build.ExplicitDeps.clear();
@@ -2044,7 +2092,7 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile(
snapshot.GetDirectory().SetRelativePathTopBinary(dir_top_bld.c_str());
auto mfd = cm::make_unique<cmMakefile>(this, snapshot);
auto lgd = this->CreateLocalGenerator(mfd.get());
- this->Makefiles.push_back(mfd.release());
+ this->Makefiles.push_back(std::move(mfd));
this->LocalGenerators.push_back(std::move(lgd));
}
@@ -2152,6 +2200,12 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile(
return true;
}
+bool cmGlobalNinjaGenerator::EnableCrossConfigBuild() const
+{
+ return this->IsMultiConfig() &&
+ this->Makefiles.front()->IsOn("CMAKE_NINJA_MULTI_CROSS_CONFIG_ENABLE");
+}
+
int cmcmd_cmake_ninja_dyndep(std::vector<std::string>::const_iterator argBeg,
std::vector<std::string>::const_iterator argEnd)
{
@@ -2222,12 +2276,11 @@ int cmcmd_cmake_ninja_dyndep(std::vector<std::string>::const_iterator argBeg,
cmake cm(cmake::RoleInternal, cmState::Unknown);
cm.SetHomeDirectory(dir_top_src);
cm.SetHomeOutputDirectory(dir_top_bld);
- std::unique_ptr<cmGlobalNinjaGenerator> ggd(
- static_cast<cmGlobalNinjaGenerator*>(cm.CreateGlobalGenerator("Ninja")));
+ auto ggd = cm.CreateGlobalGenerator("Ninja");
if (!ggd ||
- !ggd->WriteDyndepFile(dir_top_src, dir_top_bld, dir_cur_src, dir_cur_bld,
- arg_dd, arg_ddis, module_dir, linked_target_dirs,
- arg_lang)) {
+ !cm::static_reference_cast<cmGlobalNinjaGenerator>(ggd).WriteDyndepFile(
+ dir_top_src, dir_top_bld, dir_cur_src, dir_cur_bld, arg_dd, arg_ddis,
+ module_dir, linked_target_dirs, arg_lang)) {
return 1;
}
return 0;