From 3c4698da3a3c8470c8b6b1d025b10af0d5371625 Mon Sep 17 00:00:00 2001 From: Basil Fierz Date: Wed, 20 Jun 2018 22:34:54 +0200 Subject: VS: Allow toolset version selection to specify default toolset Teach the feature added by commit v3.12.0-rc1~38^2 (VS: Add option to select the version of the toolset used by VS 2017, 2018-05-19) to accept the default toolset version in addition to older versions. If the default toolset version is supplied, simply clear it so the default will be used. Fixes: #18107 --- Source/cmGlobalVisualStudio10Generator.cxx | 49 +++++++++++++++++++----------- Source/cmGlobalVisualStudio10Generator.h | 1 + Source/cmGlobalVisualStudio15Generator.cxx | 21 +++++++++++++ Source/cmGlobalVisualStudio15Generator.h | 1 + 4 files changed, 54 insertions(+), 18 deletions(-) diff --git a/Source/cmGlobalVisualStudio10Generator.cxx b/Source/cmGlobalVisualStudio10Generator.cxx index 8c20313..a5709d5 100644 --- a/Source/cmGlobalVisualStudio10Generator.cxx +++ b/Source/cmGlobalVisualStudio10Generator.cxx @@ -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 {}; diff --git a/Source/cmGlobalVisualStudio10Generator.h b/Source/cmGlobalVisualStudio10Generator.h index f85b773..6eb597c 100644 --- a/Source/cmGlobalVisualStudio10Generator.h +++ b/Source/cmGlobalVisualStudio10Generator.h @@ -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; diff --git a/Source/cmGlobalVisualStudio15Generator.cxx b/Source/cmGlobalVisualStudio15Generator.cxx index 6af5793..9983a43 100644 --- a/Source/cmGlobalVisualStudio15Generator.cxx +++ b/Source/cmGlobalVisualStudio15Generator.cxx @@ -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(); diff --git a/Source/cmGlobalVisualStudio15Generator.h b/Source/cmGlobalVisualStudio15Generator.h index 3b9cfc7..cdc97ad 100644 --- a/Source/cmGlobalVisualStudio15Generator.h +++ b/Source/cmGlobalVisualStudio15Generator.h @@ -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: -- cgit v0.12