summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorKyle Edwards <kyle.edwards@kitware.com>2020-01-23 19:46:16 (GMT)
committerKyle Edwards <kyle.edwards@kitware.com>2020-01-23 20:47:12 (GMT)
commitb7a2baf38c1f481f31db9ab41fc129a970287efd (patch)
tree946c797459ed2801bc808623f3c62852e4ff9018 /Source
parentab2fc918216011a03f0fe7696e7bba67fc2627b3 (diff)
downloadCMake-b7a2baf38c1f481f31db9ab41fc129a970287efd.zip
CMake-b7a2baf38c1f481f31db9ab41fc129a970287efd.tar.gz
CMake-b7a2baf38c1f481f31db9ab41fc129a970287efd.tar.bz2
Ninja Multi-Config: Add variable to control configs used in cross-config build
Diffstat (limited to 'Source')
-rw-r--r--Source/cmGlobalNinjaGenerator.cxx62
-rw-r--r--Source/cmGlobalNinjaGenerator.h6
-rw-r--r--Source/cmNinjaNormalTargetGenerator.cxx10
3 files changed, 64 insertions, 14 deletions
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx
index 0911cd0..020d2af 100644
--- a/Source/cmGlobalNinjaGenerator.cxx
+++ b/Source/cmGlobalNinjaGenerator.cxx
@@ -1191,8 +1191,7 @@ void cmGlobalNinjaGenerator::WriteTargetAliases(std::ostream& os)
build.Outputs.front() = ta.first;
build.ExplicitDeps.clear();
if (ta.second.Config == "all") {
- for (auto const& config :
- ta.second.GeneratorTarget->Makefile->GetGeneratorConfigs()) {
+ for (auto const& config : this->GetCrossConfigs("")) {
this->AppendTargetOutputs(ta.second.GeneratorTarget,
build.ExplicitDeps, config);
}
@@ -1200,7 +1199,9 @@ void cmGlobalNinjaGenerator::WriteTargetAliases(std::ostream& os)
this->AppendTargetOutputs(ta.second.GeneratorTarget, build.ExplicitDeps,
ta.second.Config);
}
- this->WriteBuild(this->EnableCrossConfigBuild()
+ this->WriteBuild(this->EnableCrossConfigBuild() &&
+ (ta.second.Config == "all" ||
+ this->GetCrossConfigs("").count(ta.second.Config))
? os
: *this->GetImplFileStream(ta.second.Config),
build);
@@ -1301,9 +1302,11 @@ void cmGlobalNinjaGenerator::WriteFolderTargets(std::ostream& os)
}
}
// Write target
- this->WriteBuild(
- this->EnableCrossConfigBuild() ? os : *this->GetImplFileStream(config),
- build);
+ this->WriteBuild(this->EnableCrossConfigBuild() &&
+ this->GetCrossConfigs("").count(config)
+ ? os
+ : *this->GetImplFileStream(config),
+ build);
}
// Add shortcut target
@@ -1330,7 +1333,7 @@ void cmGlobalNinjaGenerator::WriteFolderTargets(std::ostream& os)
// Add target for all configs
if (this->EnableCrossConfigBuild()) {
build.ExplicitDeps.clear();
- for (auto const& config : configs) {
+ for (auto const& config : this->GetCrossConfigs("")) {
build.ExplicitDeps.push_back(this->BuildAlias(
this->ConvertToNinjaPath(currentBinaryDir + "/all"), config));
}
@@ -1785,11 +1788,19 @@ void cmGlobalNinjaGenerator::WriteTargetClean(std::ostream& os)
build.ExplicitDeps.clear();
if (additionalFiles) {
- build.ExplicitDeps.push_back(
- this->NinjaOutputPath(this->GetAdditionalCleanTargetName()));
+ for (auto const& config : this->GetCrossConfigs("")) {
+ build.ExplicitDeps.push_back(this->BuildAlias(
+ this->NinjaOutputPath(this->GetAdditionalCleanTargetName()),
+ config));
+ }
}
- build.Variables["TARGETS"] = "";
+ std::vector<std::string> byproducts;
+ for (auto const& config : this->GetCrossConfigs("")) {
+ byproducts.push_back(
+ this->BuildAlias(GetByproductsForCleanTargetName(), config));
+ }
+ build.Variables["TARGETS"] = cmJoin(byproducts, " ");
for (auto const& fileConfig : configs) {
build.Variables["FILE_ARG"] = cmStrCat(
@@ -2359,6 +2370,15 @@ void cmGlobalNinjaGenerator::AppendDirectoryForConfig(
}
}
+std::set<std::string> cmGlobalNinjaGenerator::GetCrossConfigs(
+ const std::string& /*fileConfig*/) const
+{
+ std::set<std::string> result;
+ result.insert(
+ this->Makefiles.front()->GetSafeDefinition("CMAKE_BUILD_TYPE"));
+ return result;
+}
+
const char* cmGlobalNinjaMultiGenerator::NINJA_COMMON_FILE =
"CMakeFiles/common.ninja";
const char* cmGlobalNinjaMultiGenerator::NINJA_FILE_EXTENSION = ".ninja";
@@ -2525,3 +2545,25 @@ const char* cmGlobalNinjaMultiGenerator::GetDefaultBuildAlias() const
return this->GetDefaultBuildType();
}
+
+std::set<std::string> cmGlobalNinjaMultiGenerator::GetCrossConfigs(
+ const std::string& fileConfig) const
+{
+ std::vector<std::string> configs;
+ if (this->EnableCrossConfigBuild()) {
+ auto configsValue = this->Makefiles.front()->GetSafeDefinition(
+ "CMAKE_NINJA_MULTI_CROSS_CONFIGS");
+ if (!configsValue.empty()) {
+ cmExpandList(configsValue, configs);
+ } else {
+ configs = this->Makefiles.front()->GetGeneratorConfigs();
+ }
+ }
+
+ std::set<std::string> result(configs.cbegin(), configs.cend());
+ if (!fileConfig.empty()) {
+ result.insert(fileConfig);
+ }
+
+ return result;
+}
diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h
index b61999f..d00a061 100644
--- a/Source/cmGlobalNinjaGenerator.h
+++ b/Source/cmGlobalNinjaGenerator.h
@@ -412,6 +412,9 @@ public:
virtual const char* GetDefaultBuildAlias() const { return nullptr; }
+ virtual std::set<std::string> GetCrossConfigs(
+ const std::string& fileConfig) const;
+
protected:
void Generate() override;
@@ -623,6 +626,9 @@ public:
const char* GetDefaultBuildAlias() const override;
+ std::set<std::string> GetCrossConfigs(
+ const std::string& fileConfig) const override;
+
protected:
bool OpenBuildFileStreams() override;
void CloseBuildFileStreams() override;
diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx
index a871a92..437548a 100644
--- a/Source/cmNinjaNormalTargetGenerator.cxx
+++ b/Source/cmNinjaNormalTargetGenerator.cxx
@@ -72,8 +72,9 @@ void cmNinjaNormalTargetGenerator::Generate(const std::string& config)
// Write the build statements
bool firstForConfig = true;
for (auto const& fileConfig : this->GetConfigNames()) {
- if (fileConfig != config &&
- !this->GetGlobalGenerator()->EnableCrossConfigBuild()) {
+ if (!this->GetGlobalGenerator()
+ ->GetCrossConfigs(fileConfig)
+ .count(config)) {
continue;
}
this->WriteObjectBuildStatements(config, fileConfig, firstForConfig);
@@ -85,8 +86,9 @@ void cmNinjaNormalTargetGenerator::Generate(const std::string& config)
} else {
firstForConfig = true;
for (auto const& fileConfig : this->GetConfigNames()) {
- if (fileConfig != config &&
- !this->GetGlobalGenerator()->EnableCrossConfigBuild()) {
+ if (!this->GetGlobalGenerator()
+ ->GetCrossConfigs(fileConfig)
+ .count(config)) {
continue;
}
// If this target has cuda language link inputs, and we need to do