mirror of
https://github.com/Kitware/CMake.git
synced 2026-03-18 09:50:35 -05:00
Merge branch 'vs-filter-default-toolset' into release-3.12
Merge-request: !2162
This commit is contained in:
@@ -263,25 +263,32 @@ bool cmGlobalVisualStudio10Generator::SetGeneratorToolset(
|
||||
this->GeneratorToolsetVersion.clear();
|
||||
}
|
||||
|
||||
std::string const toolsetPath = this->GetAuxiliaryToolset();
|
||||
if (!toolsetPath.empty() && !cmSystemTools::FileExists(toolsetPath)) {
|
||||
|
||||
std::ostringstream e;
|
||||
/* clang-format off */
|
||||
e <<
|
||||
"Generator\n"
|
||||
" " << this->GetName() << "\n"
|
||||
"given toolset and version specification\n"
|
||||
" " << this->GetPlatformToolsetString() << ",version=" <<
|
||||
this->GeneratorToolsetVersion << "\n"
|
||||
"does not seem to be installed at\n" <<
|
||||
" " << toolsetPath;
|
||||
;
|
||||
/* clang-format on */
|
||||
mf->IssueMessage(cmake::FATAL_ERROR, e.str());
|
||||
|
||||
// Clear the configured tool-set
|
||||
bool const isDefaultToolset =
|
||||
this->IsDefaultToolset(this->GeneratorToolsetVersion);
|
||||
if (isDefaultToolset) {
|
||||
// If the given version is the default toolset, remove the setting
|
||||
this->GeneratorToolsetVersion.clear();
|
||||
} else {
|
||||
std::string const toolsetPath = this->GetAuxiliaryToolset();
|
||||
if (!toolsetPath.empty() && !cmSystemTools::FileExists(toolsetPath)) {
|
||||
|
||||
std::ostringstream e;
|
||||
/* clang-format off */
|
||||
e <<
|
||||
"Generator\n"
|
||||
" " << this->GetName() << "\n"
|
||||
"given toolset and version specification\n"
|
||||
" " << this->GetPlatformToolsetString() << ",version=" <<
|
||||
this->GeneratorToolsetVersion << "\n"
|
||||
"does not seem to be installed at\n" <<
|
||||
" " << toolsetPath;
|
||||
;
|
||||
/* clang-format on */
|
||||
mf->IssueMessage(cmake::FATAL_ERROR, e.str());
|
||||
|
||||
// Clear the configured tool-set
|
||||
this->GeneratorToolsetVersion.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -615,6 +622,12 @@ cmGlobalVisualStudio10Generator::GetPlatformToolsetCudaString() const
|
||||
return this->GeneratorToolsetCuda;
|
||||
}
|
||||
|
||||
bool cmGlobalVisualStudio10Generator::IsDefaultToolset(
|
||||
const std::string&) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string cmGlobalVisualStudio10Generator::GetAuxiliaryToolset() const
|
||||
{
|
||||
return {};
|
||||
|
||||
@@ -106,6 +106,7 @@ public:
|
||||
std::string Encoding() override;
|
||||
virtual const char* GetToolsVersion() { return "4.0"; }
|
||||
|
||||
virtual bool IsDefaultToolset(const std::string& version) const;
|
||||
virtual std::string GetAuxiliaryToolset() const;
|
||||
|
||||
bool FindMakeProgram(cmMakefile* mf) override;
|
||||
|
||||
@@ -158,6 +158,27 @@ bool cmGlobalVisualStudio15Generator::GetVSInstance(std::string& dir) const
|
||||
return vsSetupAPIHelper.GetVSInstanceInfo(dir);
|
||||
}
|
||||
|
||||
bool cmGlobalVisualStudio15Generator::IsDefaultToolset(
|
||||
const std::string& version) const
|
||||
{
|
||||
if (version.empty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string vcToolsetVersion;
|
||||
if (this->vsSetupAPIHelper.GetVCToolsetVersion(vcToolsetVersion)) {
|
||||
|
||||
cmsys::RegularExpression regex("[0-9][0-9]\\.[0-9]+");
|
||||
if (regex.find(version) && regex.find(vcToolsetVersion)) {
|
||||
const auto majorMinorEnd = vcToolsetVersion.find('.', 3);
|
||||
const auto majorMinor = vcToolsetVersion.substr(0, majorMinorEnd);
|
||||
return version == majorMinor;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string cmGlobalVisualStudio15Generator::GetAuxiliaryToolset() const
|
||||
{
|
||||
const char* version = this->GetPlatformToolsetVersion();
|
||||
|
||||
@@ -32,6 +32,7 @@ public:
|
||||
|
||||
bool GetVSInstance(std::string& dir) const;
|
||||
|
||||
bool IsDefaultToolset(const std::string& version) const override;
|
||||
std::string GetAuxiliaryToolset() const override;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -199,6 +199,7 @@ bool cmVSSetupAPIHelper::GetVSInstanceInfo(
|
||||
if (!cmSystemTools::FileIsDirectory(vcToolsDir)) {
|
||||
return false;
|
||||
}
|
||||
vsInstanceInfo.VCToolsetVersion = vcToolsVersion;
|
||||
}
|
||||
|
||||
// Reboot may have been required before the product package was registered
|
||||
@@ -254,6 +255,18 @@ bool cmVSSetupAPIHelper::GetVSInstanceInfo(std::string& vsInstallLocation)
|
||||
return isInstalled;
|
||||
}
|
||||
|
||||
bool cmVSSetupAPIHelper::GetVCToolsetVersion(std::string& vsToolsetVersion)
|
||||
{
|
||||
vsToolsetVersion.clear();
|
||||
bool isInstalled = this->EnumerateAndChooseVSInstance();
|
||||
|
||||
if (isInstalled) {
|
||||
vsToolsetVersion = chosenInstanceInfo.VCToolsetVersion;
|
||||
}
|
||||
|
||||
return isInstalled && !vsToolsetVersion.empty();
|
||||
}
|
||||
|
||||
bool cmVSSetupAPIHelper::EnumerateAndChooseVSInstance()
|
||||
{
|
||||
bool isVSInstanceExists = false;
|
||||
|
||||
@@ -107,16 +107,12 @@ struct VSInstanceInfo
|
||||
std::wstring InstanceId;
|
||||
std::wstring VSInstallLocation;
|
||||
std::wstring Version;
|
||||
ULONGLONG ullVersion;
|
||||
bool IsWin10SDKInstalled;
|
||||
bool IsWin81SDKInstalled;
|
||||
std::string VCToolsetVersion;
|
||||
ULONGLONG ullVersion = 0;
|
||||
bool IsWin10SDKInstalled = false;
|
||||
bool IsWin81SDKInstalled = false;
|
||||
|
||||
VSInstanceInfo()
|
||||
{
|
||||
InstanceId = VSInstallLocation = Version = L"";
|
||||
ullVersion = 0;
|
||||
IsWin10SDKInstalled = IsWin81SDKInstalled = false;
|
||||
}
|
||||
VSInstanceInfo() = default;
|
||||
|
||||
std::string GetInstallLocation() const;
|
||||
};
|
||||
@@ -131,6 +127,7 @@ public:
|
||||
|
||||
bool IsVS2017Installed();
|
||||
bool GetVSInstanceInfo(std::string& vsInstallLocation);
|
||||
bool GetVCToolsetVersion(std::string& vsToolsetVersion);
|
||||
bool IsWin10SDKInstalled();
|
||||
bool IsWin81SDKInstalled();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user