diff options
-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-- | Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake | 10 | ||||
-rw-r--r-- | Tests/RunCMake/NinjaMultiConfig/SimpleDefaultBuildAliasList-all-configs-build-check.cmake (renamed from Tests/RunCMake/NinjaMultiConfig/SimpleDefaultBuildAliasList-all-configs-ninja-check.cmake) | 0 |
6 files changed, 54 insertions, 13 deletions
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/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake b/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake index 7518395..2344158 100644 --- a/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake +++ b/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake @@ -62,7 +62,12 @@ function(run_cmake_build case suffix config) foreach(tgt IN LISTS ARGN) list(APPEND tgts --target ${tgt}) endforeach() - run_cmake_command(${case}-${suffix}-build "${CMAKE_COMMAND}" --build . --config ${config} ${tgts}) + if(config) + set(config_arg --config ${config}) + else() + set(config_arg) + endif() + run_cmake_command(${case}-${suffix}-build "${CMAKE_COMMAND}" --build . ${config_arg} ${tgts}) endfunction() function(run_ninja case suffix file) @@ -122,7 +127,8 @@ run_cmake_configure(SimpleDefaultBuildAliasList) unset(RunCMake_TEST_OPTIONS) include(${RunCMake_TEST_BINARY_DIR}/target_files.cmake) run_ninja(SimpleDefaultBuildAliasList target-configs build.ninja simpleexe) -run_ninja(SimpleDefaultBuildAliasList all-configs build.ninja all) +# IMPORTANT: This tests cmake --build . with no config using build.ninja +run_cmake_build(SimpleDefaultBuildAliasList all-configs "" all) run_ninja(SimpleDefaultBuildAliasList all-relwithdebinfo build.ninja all:RelWithDebInfo) run_ninja(SimpleDefaultBuildAliasList clean-configs build.ninja clean) diff --git a/Tests/RunCMake/NinjaMultiConfig/SimpleDefaultBuildAliasList-all-configs-ninja-check.cmake b/Tests/RunCMake/NinjaMultiConfig/SimpleDefaultBuildAliasList-all-configs-build-check.cmake index 8ffdd20..8ffdd20 100644 --- a/Tests/RunCMake/NinjaMultiConfig/SimpleDefaultBuildAliasList-all-configs-ninja-check.cmake +++ b/Tests/RunCMake/NinjaMultiConfig/SimpleDefaultBuildAliasList-all-configs-build-check.cmake |