summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-10-27 09:25:08 -0400
committerBrad King <brad.king@kitware.com>2022-10-27 09:25:08 -0400
commit77e4042204e76c1496ce2f728af7ae375f22f641 (patch)
tree7109364669f504a53109b85011ce80fe196dd4fe
parent93a54db04e0c44514fda82a2958811672cf0094f (diff)
parent6eee8c9000cff8d5a5051b1bad28e611bc93db2d (diff)
downloadcmake-77e4042204e76c1496ce2f728af7ae375f22f641.tar.gz
Merge branch 'vswhere-support-x86' into release-3.24
Merge-request: !7832
-rw-r--r--Source/cmVSSetupHelper.cxx23
1 files changed, 21 insertions, 2 deletions
diff --git a/Source/cmVSSetupHelper.cxx b/Source/cmVSSetupHelper.cxx
index 1a3e72ea06..8764f210cd 100644
--- a/Source/cmVSSetupHelper.cxx
+++ b/Source/cmVSSetupHelper.cxx
@@ -300,13 +300,32 @@ bool cmVSSetupAPIHelper::IsEWDKEnabled()
return false;
}
+#if !defined(CMAKE_BOOTSTRAP)
+namespace {
+std::string FindVsWhereCommand()
+{
+ std::string vswhere;
+ static const char* programFiles[] = { "ProgramFiles(x86)", "ProgramFiles" };
+ for (const char* pf : programFiles) {
+ if (cmSystemTools::GetEnv(pf, vswhere)) {
+ vswhere += "/Microsoft Visual Studio/Installer/vswhere.exe";
+ if (cmSystemTools::FileExists(vswhere)) {
+ return vswhere;
+ }
+ }
+ }
+ vswhere = "vswhere.exe";
+ return vswhere;
+}
+}
+#endif
+
bool cmVSSetupAPIHelper::EnumerateVSInstancesWithVswhere(
std::vector<VSInstanceInfo>& VSInstances)
{
#if !defined(CMAKE_BOOTSTRAP)
// Construct vswhere command to get installed VS instances in JSON format
- std::string vswhereExe = getenv("ProgramFiles(x86)") +
- std::string(R"(\Microsoft Visual Studio\Installer\vswhere.exe)");
+ std::string vswhereExe = FindVsWhereCommand();
std::vector<std::string> vswhereCmd = { vswhereExe, "-format", "json" };
// Execute vswhere command and capture JSON output