diff options
author | Brad King <brad.king@kitware.com> | 2020-02-05 14:10:59 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2020-02-05 14:11:10 (GMT) |
commit | 56ddef613d2bf4c23ad40ef6f2102b515bbef3a3 (patch) | |
tree | 8751851e362c2bd9e316c4cda67a185299b6655a /Source | |
parent | 94be195a5462f4d15e722333263f9a2eef09458f (diff) | |
parent | bd4ae2af0fe00813919c8188da7bb07d57ef3734 (diff) | |
download | CMake-56ddef613d2bf4c23ad40ef6f2102b515bbef3a3.zip CMake-56ddef613d2bf4c23ad40ef6f2102b515bbef3a3.tar.gz CMake-56ddef613d2bf4c23ad40ef6f2102b515bbef3a3.tar.bz2 |
Merge topic 'ninja-multi-cmake-build-no-config'
bd4ae2af0f Help: Make note of ninja -f argument in Ninja Multi-Config docs
79e5b3c46a Help: Explain new behavior of cmake --build in Ninja Multi-Config
16a4ba5b31 Ninja Multi-Config: Use build.ninja if cmake --build has no --config
2ac835b9f9 Refactor: Allow generators to decide default configuration for build
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !4323
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmGlobalGenerator.cxx | 8 | ||||
-rw-r--r-- | Source/cmGlobalGenerator.h | 10 | ||||
-rw-r--r-- | Source/cmGlobalNinjaGenerator.cxx | 41 | ||||
-rw-r--r-- | Source/cmGlobalNinjaGenerator.h | 5 | ||||
-rw-r--r-- | Source/cmState.cxx | 10 | ||||
-rw-r--r-- | Source/cmState.h | 1 | ||||
-rw-r--r-- | Source/cmake.cxx | 4 | ||||
-rw-r--r-- | Source/cmakemain.cxx | 2 |
8 files changed, 67 insertions, 14 deletions
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 1f084f5..7ddeb99 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1878,6 +1878,10 @@ int cmGlobalGenerator::Build( output += "\n"; return 1; } + std::string realConfig = config; + if (realConfig.empty()) { + realConfig = this->GetDefaultBuildConfig(); + } int retVal = 0; cmSystemTools::SetRunCommandHideConsole(true); @@ -1886,7 +1890,7 @@ int cmGlobalGenerator::Build( std::vector<GeneratedMakeCommand> makeCommand = this->GenerateBuildCommand(makeCommandCSTR, projectName, bindir, targets, - config, fast, jobs, verbose, nativeOptions); + realConfig, fast, jobs, verbose, nativeOptions); // Workaround to convince some commands to produce output. if (outputflag == cmSystemTools::OUTPUT_PASSTHROUGH && @@ -1898,7 +1902,7 @@ int cmGlobalGenerator::Build( if (clean) { std::vector<GeneratedMakeCommand> cleanCommand = this->GenerateBuildCommand(makeCommandCSTR, projectName, bindir, - { "clean" }, config, fast, jobs, verbose); + { "clean" }, realConfig, fast, jobs, verbose); output += "\nRun Clean Command:"; output += cleanCommand.front().Printable(); output += "\n"; diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index f6ed10f..e6ab1dd 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -44,6 +44,7 @@ class cmLocalGenerator; class cmMakefile; class cmOutputConverter; class cmSourceFile; +class cmState; class cmStateDirectory; class cmake; @@ -135,6 +136,12 @@ public: virtual bool SetGeneratorToolset(std::string const& ts, bool build, cmMakefile* mf); + /** Read any other cache entries needed for cmake --build. */ + virtual bool ReadCacheEntriesForBuild(const cmState& /*state*/) + { + return true; + } + /** * Create LocalGenerators and process the CMakeLists files. This does not * actually produce any makefiles, DSPs, etc. @@ -382,6 +389,9 @@ public: // Lookup edit_cache target command preferred by this generator. virtual std::string GetEditCacheCommand() const { return ""; } + // Default config to use for cmake --build + virtual std::string GetDefaultBuildConfig() const { return "Debug"; } + // Class to track a set of dependencies. using TargetDependSet = cmTargetDependSet; diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index f7694ff..ff1e5d6 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -800,8 +800,7 @@ cmGlobalNinjaGenerator::GenerateBuildCommand( makeCommand.Add("-j", std::to_string(jobs)); } - this->AppendNinjaFileArgument(makeCommand, - config.empty() ? "Debug" : config); + this->AppendNinjaFileArgument(makeCommand, config); makeCommand.Add(makeOptions.begin(), makeOptions.end()); for (const auto& tname : targetNames) { @@ -2559,8 +2558,10 @@ void cmGlobalNinjaMultiGenerator::CloseBuildFileStreams() void cmGlobalNinjaMultiGenerator::AppendNinjaFileArgument( GeneratedMakeCommand& command, const std::string& config) const { - command.Add("-f"); - command.Add(GetNinjaConfigFilename(config)); + if (!config.empty()) { + command.Add("-f"); + command.Add(GetNinjaConfigFilename(config)); + } } std::string cmGlobalNinjaMultiGenerator::GetNinjaImplFilename( @@ -2601,11 +2602,30 @@ void cmGlobalNinjaMultiGenerator::GetQtAutoGenConfigs( bool cmGlobalNinjaMultiGenerator::InspectConfigTypeVariables() { - auto configsVec = this->Makefiles.front()->GetGeneratorConfigs(); + return this->ReadCacheEntriesForBuild(*this->Makefiles.front()->GetState()); +} + +std::string cmGlobalNinjaMultiGenerator::GetDefaultBuildConfig() const +{ + if (this->DefaultFileConfig.empty()) { + return "Debug"; + } + return ""; +} + +bool cmGlobalNinjaMultiGenerator::ReadCacheEntriesForBuild( + const cmState& state) +{ + std::vector<std::string> configsVec; + cmExpandList(state.GetSafeCacheEntryValue("CMAKE_CONFIGURATION_TYPES"), + configsVec); + if (configsVec.empty()) { + configsVec.emplace_back(); + } std::set<std::string> configs(configsVec.cbegin(), configsVec.cend()); - this->DefaultFileConfig = this->Makefiles.front()->GetSafeDefinition( - "CMAKE_NMC_DEFAULT_BUILD_FILE_CONFIG"); + this->DefaultFileConfig = + state.GetSafeCacheEntryValue("CMAKE_NMC_DEFAULT_BUILD_FILE_CONFIG"); if (!this->DefaultFileConfig.empty() && !configs.count(this->DefaultFileConfig)) { std::ostringstream msg; @@ -2618,9 +2638,8 @@ bool cmGlobalNinjaMultiGenerator::InspectConfigTypeVariables() } std::vector<std::string> crossConfigsVec; - cmExpandList( - this->Makefiles.front()->GetSafeDefinition("CMAKE_NMC_CROSS_CONFIGS"), - crossConfigsVec); + cmExpandList(state.GetSafeCacheEntryValue("CMAKE_NMC_CROSS_CONFIGS"), + crossConfigsVec); auto crossConfigs = ListSubsetWithAll(configs, crossConfigsVec); if (!crossConfigs) { std::ostringstream msg; @@ -2633,7 +2652,7 @@ bool cmGlobalNinjaMultiGenerator::InspectConfigTypeVariables() this->CrossConfigs = *crossConfigs; auto defaultConfigsString = - this->Makefiles.front()->GetSafeDefinition("CMAKE_NMC_DEFAULT_CONFIGS"); + state.GetSafeCacheEntryValue("CMAKE_NMC_DEFAULT_CONFIGS"); if (defaultConfigsString.empty()) { defaultConfigsString = this->DefaultFileConfig; } diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h index 3b45249..0e53c0e 100644 --- a/Source/cmGlobalNinjaGenerator.h +++ b/Source/cmGlobalNinjaGenerator.h @@ -32,6 +32,7 @@ class cmLinkLineComputer; class cmLocalGenerator; class cmMakefile; class cmOutputConverter; +class cmState; class cmStateDirectory; class cmake; struct cmDocumentationEntry; @@ -633,6 +634,10 @@ public: bool InspectConfigTypeVariables() override; + std::string GetDefaultBuildConfig() const override; + + bool ReadCacheEntriesForBuild(const cmState& state) override; + protected: bool OpenBuildFileStreams() override; void CloseBuildFileStreams() override; diff --git a/Source/cmState.cxx b/Source/cmState.cxx index 0ce8dd7..9fc7615 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -141,6 +141,16 @@ const char* cmState::GetCacheEntryValue(std::string const& key) const return e->Value.c_str(); } +std::string cmState::GetSafeCacheEntryValue(std::string const& key) const +{ + std::string retval; + auto val = this->GetCacheEntryValue(key); + if (val) { + retval = val; + } + return retval; +} + const std::string* cmState::GetInitializedCacheValue( std::string const& key) const { diff --git a/Source/cmState.h b/Source/cmState.h index 817046f..6ee2b0c 100644 --- a/Source/cmState.h +++ b/Source/cmState.h @@ -88,6 +88,7 @@ public: std::vector<std::string> GetCacheEntryKeys() const; const char* GetCacheEntryValue(std::string const& key) const; + std::string GetSafeCacheEntryValue(std::string const& key) const; const std::string* GetInitializedCacheValue(std::string const& key) const; cmStateEnums::CacheEntryType GetCacheEntryType(std::string const& key) const; void SetCacheEntryValue(std::string const& key, std::string const& value); diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 5fa40d5..f4b9f16 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -2767,6 +2767,10 @@ int cmake::Build(int jobs, const std::string& dir, } #endif + if (!this->GlobalGenerator->ReadCacheEntriesForBuild(*this->State)) { + return 1; + } + this->GlobalGenerator->PrintBuildCommandAdvice(std::cerr, jobs); return this->GlobalGenerator->Build( jobs, "", dir, projName, targets, output, "", config, clean, false, diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index 5579ae1..494d5d9 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -350,7 +350,7 @@ int do_build(int ac, char const* const* av) #else int jobs = cmake::NO_BUILD_PARALLEL_LEVEL; std::vector<std::string> targets; - std::string config = "Debug"; + std::string config; std::string dir; std::vector<std::string> nativeOptions; bool cleanFirst = false; |