diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 1f084f5eb6..7ddeb995a2 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 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 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 f6ed10fa9d..e6ab1dd7f8 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/cmake.cxx b/Source/cmake.cxx index 5fa40d525e..f4b9f1672c 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 5579ae16e9..494d5d982d 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 targets; - std::string config = "Debug"; + std::string config; std::string dir; std::vector nativeOptions; bool cleanFirst = false;