summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-10-21 15:54:19 (GMT)
committerBrad King <brad.king@kitware.com>2021-10-29 15:52:58 (GMT)
commit5d1f377737a9d1d14f4925072c46201d6b7b3c30 (patch)
treea2999e87faf8e3babbeb43403b5a5ba62f04eeb8 /Source
parent006fe1e919f3d326f9a8d749b59324b5512a0d87 (diff)
downloadCMake-5d1f377737a9d1d14f4925072c46201d6b7b3c30.zip
CMake-5d1f377737a9d1d14f4925072c46201d6b7b3c30.tar.gz
CMake-5d1f377737a9d1d14f4925072c46201d6b7b3c30.tar.bz2
cmVSSetupHelper: Factor out helper to load MSVC toolset version
Diffstat (limited to 'Source')
-rw-r--r--Source/cmVSSetupHelper.cxx42
1 files changed, 26 insertions, 16 deletions
diff --git a/Source/cmVSSetupHelper.cxx b/Source/cmVSSetupHelper.cxx
index d0932ba..b9443d6 100644
--- a/Source/cmVSSetupHelper.cxx
+++ b/Source/cmVSSetupHelper.cxx
@@ -46,12 +46,33 @@ const CLSID CLSID_SetupConfiguration = {
/* clang-format on */
#endif
+namespace {
const WCHAR* Win10SDKComponent =
L"Microsoft.VisualStudio.Component.Windows10SDK";
const WCHAR* Win81SDKComponent =
L"Microsoft.VisualStudio.Component.Windows81SDK";
const WCHAR* ComponentType = L"Component";
+bool LoadVSInstanceVCToolsetVersion(VSInstanceInfo& vsInstanceInfo)
+{
+ std::string const vcRoot = vsInstanceInfo.GetInstallLocation();
+ std::string vcToolsVersionFile =
+ vcRoot + "/VC/Auxiliary/Build/Microsoft.VCToolsVersion.default.txt";
+ std::string vcToolsVersion;
+ cmsys::ifstream fin(vcToolsVersionFile.c_str());
+ if (!fin || !cmSystemTools::GetLineFromStream(fin, vcToolsVersion)) {
+ return false;
+ }
+ vcToolsVersion = cmTrimWhitespace(vcToolsVersion);
+ std::string const vcToolsDir = vcRoot + "/VC/Tools/MSVC/" + vcToolsVersion;
+ if (!cmSystemTools::FileIsDirectory(vcToolsDir)) {
+ return false;
+ }
+ vsInstanceInfo.VCToolsetVersion = vcToolsVersion;
+ return true;
+}
+}
+
std::string VSInstanceInfo::GetInstallLocation() const
{
return this->VSInstallLocation;
@@ -176,21 +197,8 @@ bool cmVSSetupAPIHelper::GetVSInstanceInfo(
}
// Check if a compiler is installed with this instance.
- {
- std::string const vcRoot = vsInstanceInfo.GetInstallLocation();
- std::string vcToolsVersionFile =
- vcRoot + "/VC/Auxiliary/Build/Microsoft.VCToolsVersion.default.txt";
- std::string vcToolsVersion;
- cmsys::ifstream fin(vcToolsVersionFile.c_str());
- if (!fin || !cmSystemTools::GetLineFromStream(fin, vcToolsVersion)) {
- return false;
- }
- vcToolsVersion = cmTrimWhitespace(vcToolsVersion);
- std::string const vcToolsDir = vcRoot + "/VC/Tools/MSVC/" + vcToolsVersion;
- if (!cmSystemTools::FileIsDirectory(vcToolsDir)) {
- return false;
- }
- vsInstanceInfo.VCToolsetVersion = vcToolsVersion;
+ if (!LoadVSInstanceVCToolsetVersion(vsInstanceInfo)) {
+ return false;
}
// Reboot may have been required before the product package was registered
@@ -301,7 +309,9 @@ bool cmVSSetupAPIHelper::EnumerateAndChooseVSInstance()
chosenInstanceInfo.VSInstallLocation = envVsInstallDir;
chosenInstanceInfo.Version = envVSVersion;
- chosenInstanceInfo.VCToolsetVersion = envVSVersion;
+ if (!LoadVSInstanceVCToolsetVersion(chosenInstanceInfo)) {
+ return false;
+ }
chosenInstanceInfo.IsWin10SDKInstalled = true;
chosenInstanceInfo.IsWin81SDKInstalled = !envWindowsSdkDir81.empty();
return true;