summaryrefslogtreecommitdiffstats
path: root/Source/cmGlobalVisualStudioVersionedGenerator.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-03-11 21:59:20 (GMT)
committerBrad King <brad.king@kitware.com>2021-03-12 13:36:40 (GMT)
commit58a50a3a0aa814c0fb00720cb8fc9edb2cf72344 (patch)
tree19b9ef83bef46cff1ae566967ca629727df2ca63 /Source/cmGlobalVisualStudioVersionedGenerator.cxx
parent09f59da7f09ef864c592cb7e3ffd26373ae2f705 (diff)
downloadCMake-58a50a3a0aa814c0fb00720cb8fc9edb2cf72344.zip
CMake-58a50a3a0aa814c0fb00720cb8fc9edb2cf72344.tar.gz
CMake-58a50a3a0aa814c0fb00720cb8fc9edb2cf72344.tar.bz2
VS: Fix '-T version=14.28' under VS 16.9
CMake accepts the toolset version that is default in the current VS version by matching the name later VS versions will use for the SxS props files. It predicts the future name based on the first two components of the current VS version's default toolset. However, this heuristic breaks naming the VS 16.8 toolset version 14.28 under VS 16.9 because the latter's default toolset version is 14.28.29910, which did not increment the second version component (unprecedented in VS). Fix this by always using the requested version's SxS props file when it exists, even if it matches the first two components of the current VS version's default toolset. Also add a special case for the name VS 16.10 will use for VS 16.9's default toolset, so that it can be used with VS 16.9 too. Fixes: #21922
Diffstat (limited to 'Source/cmGlobalVisualStudioVersionedGenerator.cxx')
-rw-r--r--Source/cmGlobalVisualStudioVersionedGenerator.cxx90
1 files changed, 50 insertions, 40 deletions
diff --git a/Source/cmGlobalVisualStudioVersionedGenerator.cxx b/Source/cmGlobalVisualStudioVersionedGenerator.cxx
index 84f870e..4e2464b 100644
--- a/Source/cmGlobalVisualStudioVersionedGenerator.cxx
+++ b/Source/cmGlobalVisualStudioVersionedGenerator.cxx
@@ -2,6 +2,8 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmGlobalVisualStudioVersionedGenerator.h"
+#include <cmext/string_view>
+
#include "cmAlgorithms.h"
#include "cmDocumentationEntry.h"
#include "cmLocalVisualStudio10Generator.h"
@@ -391,27 +393,6 @@ bool cmGlobalVisualStudioVersionedGenerator::GetVSInstanceVersion(
return vsSetupAPIHelper.GetVSInstanceVersion(vsInstanceVersion);
}
-bool cmGlobalVisualStudioVersionedGenerator::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;
-}
-
bool cmGlobalVisualStudioVersionedGenerator::IsStdOutEncodingSupported() const
{
// Supported from Visual Studio 16.7 Preview 3.
@@ -446,29 +427,58 @@ cmGlobalVisualStudioVersionedGenerator::GetAndroidApplicationTypeRevision()
return "";
}
-std::string cmGlobalVisualStudioVersionedGenerator::GetAuxiliaryToolset() const
+cmGlobalVisualStudioVersionedGenerator::AuxToolset
+cmGlobalVisualStudioVersionedGenerator::FindAuxToolset(
+ std::string& version, std::string& props) const
{
- const char* version = this->GetPlatformToolsetVersion();
- if (version) {
- std::string instancePath;
- GetVSInstance(instancePath);
- std::string toolsetDir = instancePath + "/VC/Auxiliary/Build";
- char sep = '/';
- if (cmSystemTools::VersionCompareGreaterEq(version, "14.20")) {
- std::string toolsetDot =
- cmStrCat(toolsetDir, '.', version, "/Microsoft.VCToolsVersion.",
- version, ".props");
- if (cmSystemTools::PathExists(toolsetDot)) {
- sep = '.';
+ if (version.empty()) {
+ return AuxToolset::None;
+ }
+
+ std::string instancePath;
+ this->GetVSInstance(instancePath);
+ cmSystemTools::ConvertToUnixSlashes(instancePath);
+
+ if (cmSystemTools::VersionCompareGreaterEq(version, "14.20")) {
+ props = cmStrCat(instancePath, "/VC/Auxiliary/Build."_s, version,
+ "/Microsoft.VCToolsVersion."_s, version, ".props"_s);
+ if (cmSystemTools::PathExists(props)) {
+ return AuxToolset::PropsExist;
+ }
+ }
+ props = cmStrCat(instancePath, "/VC/Auxiliary/Build/"_s, version,
+ "/Microsoft.VCToolsVersion."_s, version, ".props"_s);
+ if (cmSystemTools::PathExists(props)) {
+ return AuxToolset::PropsExist;
+ }
+
+ // Accept the toolset version that is default in the current VS version
+ // by matching the name later VS versions will use for the SxS props files.
+ std::string vcToolsetVersion;
+ if (this->vsSetupAPIHelper.GetVCToolsetVersion(vcToolsetVersion)) {
+ // Accept an exact-match (three-component version).
+ if (version == vcToolsetVersion) {
+ return AuxToolset::Default;
+ }
+
+ // Accept known SxS props file names using four version components
+ // in VS versions later than the current.
+ if (version == "14.28.16.9" && vcToolsetVersion == "14.28.29910") {
+ return AuxToolset::Default;
+ }
+
+ // The first two components of the default toolset version typically
+ // match the name used by later VS versions for the SxS props files.
+ cmsys::RegularExpression twoComponent("^([0-9]+\\.[0-9]+)");
+ if (twoComponent.find(version)) {
+ std::string const versionPrefix = cmStrCat(twoComponent.match(1), '.');
+ if (cmHasPrefix(vcToolsetVersion, versionPrefix)) {
+ return AuxToolset::Default;
}
}
- std::string toolsetPath =
- cmStrCat(toolsetDir, sep, version, "/Microsoft.VCToolsVersion.", version,
- ".props");
- cmSystemTools::ConvertToUnixSlashes(toolsetPath);
- return toolsetPath;
}
- return {};
+
+ return AuxToolset::PropsMissing;
}
bool cmGlobalVisualStudioVersionedGenerator::InitializeWindows(cmMakefile* mf)