diff options
author | Kyle Edwards <kyle.edwards@kitware.com> | 2020-12-09 21:39:15 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2020-12-15 12:01:21 (GMT) |
commit | dcf9f4d2f71d7c608ce24b690d30d465df51dc71 (patch) | |
tree | 0868f3cd8176eb883063a77350864b70782b2dad /Source/cmNinjaUtilityTargetGenerator.cxx | |
parent | 15467f12f796205f97721f43ae7d9ee7cdc47466 (diff) | |
download | CMake-dcf9f4d2f71d7c608ce24b690d30d465df51dc71.zip CMake-dcf9f4d2f71d7c608ce24b690d30d465df51dc71.tar.gz CMake-dcf9f4d2f71d7c608ce24b690d30d465df51dc71.tar.bz2 |
Ninja Multi-Config: Add support for cross-config custom commands
Co-Author: Brad King <brad.king@kitware.com>
Diffstat (limited to 'Source/cmNinjaUtilityTargetGenerator.cxx')
-rw-r--r-- | Source/cmNinjaUtilityTargetGenerator.cxx | 53 |
1 files changed, 42 insertions, 11 deletions
diff --git a/Source/cmNinjaUtilityTargetGenerator.cxx b/Source/cmNinjaUtilityTargetGenerator.cxx index ad1d5f1..0b62e16 100644 --- a/Source/cmNinjaUtilityTargetGenerator.cxx +++ b/Source/cmNinjaUtilityTargetGenerator.cxx @@ -5,6 +5,7 @@ #include <algorithm> #include <array> #include <iterator> +#include <set> #include <string> #include <utility> #include <vector> @@ -34,13 +35,30 @@ cmNinjaUtilityTargetGenerator::~cmNinjaUtilityTargetGenerator() = default; void cmNinjaUtilityTargetGenerator::Generate(const std::string& config) { + for (auto const& fileConfig : this->GetConfigNames()) { + if (!this->GetGlobalGenerator() + ->GetCrossConfigs(fileConfig) + .count(config)) { + continue; + } + if (fileConfig != config && + this->GetGeneratorTarget()->GetType() == cmStateEnums::GLOBAL_TARGET) { + continue; + } + this->WriteUtilBuildStatements(config, fileConfig); + } +} + +void cmNinjaUtilityTargetGenerator::WriteUtilBuildStatements( + std::string const& config, std::string const& fileConfig) +{ cmGlobalNinjaGenerator* gg = this->GetGlobalGenerator(); cmLocalNinjaGenerator* lg = this->GetLocalGenerator(); cmGeneratorTarget* genTarget = this->GetGeneratorTarget(); std::string configDir; if (genTarget->Target->IsPerConfig()) { - configDir = gg->ConfigDirectory(config); + configDir = gg->ConfigDirectory(fileConfig); } std::string utilCommandName = cmStrCat(lg->GetCurrentBinaryDirectory(), "/CMakeFiles", configDir, "/", @@ -60,8 +78,8 @@ void cmNinjaUtilityTargetGenerator::Generate(const std::string& config) for (std::vector<cmCustomCommand> const* cmdList : cmdLists) { for (cmCustomCommand const& ci : *cmdList) { - cmCustomCommandGenerator ccg(ci, config, lg); - lg->AppendCustomCommandDeps(ccg, deps, config); + cmCustomCommandGenerator ccg(ci, fileConfig, lg); + lg->AppendCustomCommandDeps(ccg, deps, fileConfig); lg->AppendCustomCommandLines(ccg, commands); std::vector<std::string> const& ccByproducts = ccg.GetByproducts(); std::transform(ccByproducts.begin(), ccByproducts.end(), @@ -103,13 +121,19 @@ void cmNinjaUtilityTargetGenerator::Generate(const std::string& config) std::copy(util_outputs.begin(), util_outputs.end(), std::back_inserter(gg->GetByproductsForCleanTarget())); } - lg->AppendTargetDepends(genTarget, deps, config, config, + // TODO: Does this need an output config? + // Does this need to go in impl-<config>.ninja? + lg->AppendTargetDepends(genTarget, deps, config, fileConfig, DependOnTargetArtifact); if (commands.empty()) { phonyBuild.Comment = "Utility command for " + this->GetTargetName(); phonyBuild.ExplicitDeps = std::move(deps); - gg->WriteBuild(this->GetCommonFileStream(), phonyBuild); + if (genTarget->GetType() != cmStateEnums::GLOBAL_TARGET) { + gg->WriteBuild(this->GetImplFileStream(fileConfig), phonyBuild); + } else { + gg->WriteBuild(this->GetCommonFileStream(), phonyBuild); + } } else { std::string command = lg->BuildCommandLine(commands, "utility", this->GeneratorTarget); @@ -145,15 +169,22 @@ void cmNinjaUtilityTargetGenerator::Generate(const std::string& config) std::string ccConfig; if (genTarget->Target->IsPerConfig() && genTarget->GetType() != cmStateEnums::GLOBAL_TARGET) { - ccConfig = config; + ccConfig = fileConfig; + } + if (config == fileConfig || + gg->GetPerConfigUtilityTargets().count(genTarget->GetName())) { + gg->WriteCustomCommandBuild( + command, desc, "Utility command for " + this->GetTargetName(), + /*depfile*/ "", /*job_pool*/ "", uses_terminal, + /*restat*/ true, util_outputs, ccConfig, deps); } - gg->WriteCustomCommandBuild(command, desc, - "Utility command for " + this->GetTargetName(), - /*depfile*/ "", /*job_pool*/ "", uses_terminal, - /*restat*/ true, util_outputs, ccConfig, deps); phonyBuild.ExplicitDeps.push_back(utilCommandName); - gg->WriteBuild(this->GetCommonFileStream(), phonyBuild); + if (genTarget->GetType() != cmStateEnums::GLOBAL_TARGET) { + gg->WriteBuild(this->GetImplFileStream(fileConfig), phonyBuild); + } else { + gg->WriteBuild(this->GetCommonFileStream(), phonyBuild); + } } // Find ADDITIONAL_CLEAN_FILES |