Refactor: Allow generators to decide default configuration for build

And allow them to read any cache values they need.
This commit is contained in:
Kyle Edwards
2020-02-04 14:12:01 -05:00
parent 28013c9434
commit 2ac835b9f9
4 changed files with 21 additions and 3 deletions

View File

@@ -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";

View File

@@ -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;

View File

@@ -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,

View File

@@ -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;