From 2ac835b9f9a7a4dec16c498a51c0dbc3d64844bc Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Tue, 4 Feb 2020 14:12:01 -0500 Subject: Refactor: Allow generators to decide default configuration for build And allow them to read any cache values they need. --- Source/cmGlobalGenerator.cxx | 8 ++++++-- Source/cmGlobalGenerator.h | 10 ++++++++++ Source/cmake.cxx | 4 ++++ Source/cmakemain.cxx | 2 +- 4 files changed, 21 insertions(+), 3 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 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 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/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 targets; - std::string config = "Debug"; + std::string config; std::string dir; std::vector nativeOptions; bool cleanFirst = false; -- cgit v0.12