MCPcopy Create free account
hub / github.com/Kitware/CMake / EnumerateAndChooseVSInstance

Method EnumerateAndChooseVSInstance

Source/cmVSSetupHelper.cxx:406–515  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

404}
405
406bool cmVSSetupAPIHelper::EnumerateAndChooseVSInstance()
407{
408 bool isVSInstanceExists = false;
409 if (!chosenInstanceInfo.VSInstallLocation.empty()) {
410 return true;
411 }
412
413 if (this->IsEWDKEnabled()) {
414 std::string envWindowsSdkDir81;
415 std::string envVSVersion;
416 std::string envVsInstallDir;
417
418 cmSystemTools::GetEnv("WindowsSdkDir_81", envWindowsSdkDir81);
419 cmSystemTools::GetEnv("VisualStudioVersion", envVSVersion);
420 cmSystemTools::GetEnv("VSINSTALLDIR", envVsInstallDir);
421 if (envVSVersion.empty() || envVsInstallDir.empty()) {
422 return false;
423 }
424
425 chosenInstanceInfo.VSInstallLocation = envVsInstallDir;
426 chosenInstanceInfo.Version = envVSVersion;
427 if (!LoadVSInstanceVCToolsetVersion(chosenInstanceInfo)) {
428 return false;
429 }
430 chosenInstanceInfo.IsWin10SDKInstalled = true;
431 chosenInstanceInfo.IsWin81SDKInstalled = !envWindowsSdkDir81.empty();
432 return true;
433 }
434
435 std::string envVSCommonToolsDir;
436 std::string envVSCommonToolsDirEnvName =
437 cmStrCat("VS", this->Version, "0COMNTOOLS");
438
439 if (cmSystemTools::GetEnv(envVSCommonToolsDirEnvName, envVSCommonToolsDir)) {
440 cmSystemTools::ConvertToUnixSlashes(envVSCommonToolsDir);
441 }
442
443 bool specifiedLocationNotSpecifiedVersion = false;
444
445 SmartCOMPtr<ISetupInstance> instance;
446
447 std::vector<VSInstanceInfo> vecVSInstancesAll;
448
449 // Enumerate VS instances with either COM interface or Vswhere
450 if (!EnumerateVSInstancesWithCOM(vecVSInstancesAll) &&
451 !EnumerateVSInstancesWithVswhere(vecVSInstancesAll) &&
452 this->SpecifiedVSInstallLocation.empty()) {
453 return false;
454 }
455
456 std::string const wantVersion = cmStrCat(this->Version, '.');
457
458 std::vector<VSInstanceInfo> vecVSInstances;
459 for (auto const& instanceInfo : vecVSInstancesAll) {
460 // We are looking for a specific major version.
461 if (instanceInfo.Version.size() < wantVersion.size() ||
462 instanceInfo.Version.substr(0, wantVersion.size()) != wantVersion) {
463 continue;

Callers 7

SetVSInstanceMethod · 0.95
IsVSInstalledMethod · 0.95
IsWin10SDKInstalledMethod · 0.95
IsWin81SDKInstalledMethod · 0.95
GetVSInstanceInfoMethod · 0.95
GetVSInstanceVersionMethod · 0.95
GetVCToolsetVersionMethod · 0.95

Calls 9

IsEWDKEnabledMethod · 0.95
GetInstallLocationMethod · 0.80
push_backMethod · 0.80
cmStrCatFunction · 0.70
emptyMethod · 0.45
sizeMethod · 0.45
substrMethod · 0.45

Tested by

no test coverage detected