cmake: Teach --build mode to load CMAKE_GENERATOR_TOOLSET

Extend the `cmGlobalGenerator::SetGeneratorToolset` signature to
indicate when it is called from `cmake::build`.
This commit is contained in:
Alexander Boczar 2019-09-13 17:32:13 -07:00 committed by Brad King
parent 6050951812
commit 99e83d4235
9 changed files with 31 additions and 9 deletions

View File

@ -165,7 +165,7 @@ bool cmGlobalGenerator::SetGeneratorPlatform(std::string const& p,
return false;
}
bool cmGlobalGenerator::SetGeneratorToolset(std::string const& ts,
bool cmGlobalGenerator::SetGeneratorToolset(std::string const& ts, bool,
cmMakefile* mf)
{
if (ts.empty()) {
@ -650,7 +650,7 @@ void cmGlobalGenerator::EnableLanguage(
// Tell the generator about the toolset, if any.
std::string toolset = mf->GetSafeDefinition("CMAKE_GENERATOR_TOOLSET");
if (!this->SetGeneratorToolset(toolset, mf)) {
if (!this->SetGeneratorToolset(toolset, false, mf)) {
cmSystemTools::SetFatalErrorOccured();
return;
}

View File

@ -128,7 +128,8 @@ public:
/** Set the generator-specific toolset name. Returns true if toolset
is supported and false otherwise. */
virtual bool SetGeneratorToolset(std::string const& ts, cmMakefile* mf);
virtual bool SetGeneratorToolset(std::string const& ts, bool build,
cmMakefile* mf);
/**
* Create LocalGenerators and process the CMakeLists files. This does not

View File

@ -64,8 +64,11 @@ void cmGlobalGhsMultiGenerator::ComputeTargetObjectDirectory(
}
bool cmGlobalGhsMultiGenerator::SetGeneratorToolset(std::string const& ts,
cmMakefile* mf)
bool build, cmMakefile* mf)
{
if (build) {
return true;
}
std::string tsp; /* toolset path */
this->GetToolset(mf, tsp, ts);

View File

@ -58,7 +58,8 @@ public:
static bool SupportsPlatform() { return true; }
// Toolset / Platform Support
bool SetGeneratorToolset(std::string const& ts, cmMakefile* mf) override;
bool SetGeneratorToolset(std::string const& ts, bool build,
cmMakefile* mf) override;
bool SetGeneratorPlatform(std::string const& p, cmMakefile* mf) override;
/**

View File

@ -193,7 +193,7 @@ static void cmCudaToolVersion(std::string& s)
}
bool cmGlobalVisualStudio10Generator::SetGeneratorToolset(
std::string const& ts, cmMakefile* mf)
std::string const& ts, bool build, cmMakefile* mf)
{
if (this->SystemIsWindowsCE && ts.empty() &&
this->DefaultPlatformToolset.empty()) {
@ -208,6 +208,10 @@ bool cmGlobalVisualStudio10Generator::SetGeneratorToolset(
return false;
}
if (build) {
return true;
}
if (!this->FindVCTargetsPath(mf)) {
return false;
}

View File

@ -20,7 +20,8 @@ public:
bool SetSystemName(std::string const& s, cmMakefile* mf) override;
bool SetGeneratorPlatform(std::string const& p, cmMakefile* mf) override;
bool SetGeneratorToolset(std::string const& ts, cmMakefile* mf) override;
bool SetGeneratorToolset(std::string const& ts, bool build,
cmMakefile* mf) override;
std::vector<GeneratedMakeCommand> GenerateBuildCommand(
const std::string& makeProgram, const std::string& projectName,

View File

@ -267,7 +267,7 @@ std::string cmGlobalXCodeGenerator::FindXcodeBuildCommand()
}
bool cmGlobalXCodeGenerator::SetGeneratorToolset(std::string const& ts,
cmMakefile* mf)
bool build, cmMakefile* mf)
{
if (ts.find_first_of(",=") != std::string::npos) {
std::ostringstream e;
@ -283,6 +283,9 @@ bool cmGlobalXCodeGenerator::SetGeneratorToolset(std::string const& ts,
return false;
}
this->GeneratorToolset = ts;
if (build) {
return true;
}
if (!this->GeneratorToolset.empty()) {
mf->AddDefinition("CMAKE_XCODE_PLATFORM_TOOLSET", this->GeneratorToolset);
}

View File

@ -103,7 +103,8 @@ public:
bool ShouldStripResourcePath(cmMakefile*) const override;
bool SetGeneratorToolset(std::string const& ts, cmMakefile* mf) override;
bool SetGeneratorToolset(std::string const& ts, bool build,
cmMakefile* mf) override;
void AppendFlag(std::string& flags, std::string const& flag) const;
protected:

View File

@ -2620,6 +2620,14 @@ int cmake::Build(int jobs, const std::string& dir,
return 1;
}
}
const char* cachedGeneratorToolset =
this->State->GetCacheEntryValue("CMAKE_GENERATOR_TOOLSET");
if (cachedGeneratorToolset) {
cmMakefile mf(gen, this->GetCurrentSnapshot());
if (!gen->SetGeneratorToolset(cachedGeneratorToolset, true, &mf)) {
return 1;
}
}
std::string output;
std::string projName;
const char* cachedProjectName =