summaryrefslogtreecommitdiffstats
path: root/Source/cmVSSetupHelper.cxx
diff options
context:
space:
mode:
authorNiyas Sait <niyas.sait@linaro.org>2022-04-09 17:03:18 (GMT)
committerNiyas Sait <niyas.sait@linaro.org>2022-04-11 15:33:03 (GMT)
commit069cff63f62b76fedec9064240b4aa53f1d5c71f (patch)
tree7af112bb571ec5d47c22cc28653e20fcffc921f3 /Source/cmVSSetupHelper.cxx
parent7fc248bde34c529c6f1312a56c7e82303238b9c1 (diff)
downloadCMake-069cff63f62b76fedec9064240b4aa53f1d5c71f.zip
CMake-069cff63f62b76fedec9064240b4aa53f1d5c71f.tar.gz
CMake-069cff63f62b76fedec9064240b4aa53f1d5c71f.tar.bz2
VS: refactor EnumerateAndChooseVSInstance
Move all VS instance enumeration code using COM interface to EnumerateVSInstancesWithCOM
Diffstat (limited to 'Source/cmVSSetupHelper.cxx')
-rw-r--r--Source/cmVSSetupHelper.cxx128
1 files changed, 72 insertions, 56 deletions
diff --git a/Source/cmVSSetupHelper.cxx b/Source/cmVSSetupHelper.cxx
index cbd241b..49ad441 100644
--- a/Source/cmVSSetupHelper.cxx
+++ b/Source/cmVSSetupHelper.cxx
@@ -295,6 +295,39 @@ bool cmVSSetupAPIHelper::IsEWDKEnabled()
return false;
}
+bool cmVSSetupAPIHelper::EnumerateVSInstancesWithCOM(
+ std::vector<VSInstanceInfo>& VSInstances)
+{
+ if (initializationFailure || setupConfig == NULL || setupConfig2 == NULL ||
+ setupHelper == NULL)
+ return false;
+
+ SmartCOMPtr<IEnumSetupInstances> enumInstances = NULL;
+ if (FAILED(
+ setupConfig2->EnumInstances((IEnumSetupInstances**)&enumInstances)) ||
+ !enumInstances) {
+ return false;
+ }
+
+ SmartCOMPtr<ISetupInstance> instance;
+ while (SUCCEEDED(enumInstances->Next(1, &instance, NULL)) && instance) {
+ SmartCOMPtr<ISetupInstance2> instance2 = NULL;
+ if (FAILED(
+ instance->QueryInterface(IID_ISetupInstance2, (void**)&instance2)) ||
+ !instance2) {
+ instance = NULL;
+ continue;
+ }
+
+ VSInstanceInfo instanceInfo;
+ bool isInstalled = GetVSInstanceInfo(instance2, instanceInfo);
+ instance = instance2 = NULL;
+ if (isInstalled)
+ VSInstances.push_back(instanceInfo);
+ }
+ return true;
+}
+
bool cmVSSetupAPIHelper::EnumerateAndChooseVSInstance()
{
bool isVSInstanceExists = false;
@@ -321,10 +354,6 @@ bool cmVSSetupAPIHelper::EnumerateAndChooseVSInstance()
return true;
}
- if (initializationFailure || setupConfig == NULL || setupConfig2 == NULL ||
- setupHelper == NULL)
- return false;
-
std::string envVSCommonToolsDir;
std::string envVSCommonToolsDirEnvName =
"VS" + std::to_string(this->Version) + "0COMNTOOLS";
@@ -334,72 +363,59 @@ bool cmVSSetupAPIHelper::EnumerateAndChooseVSInstance()
cmSystemTools::ConvertToUnixSlashes(envVSCommonToolsDir);
}
- std::vector<VSInstanceInfo> vecVSInstances;
- SmartCOMPtr<IEnumSetupInstances> enumInstances = NULL;
- if (FAILED(
- setupConfig2->EnumInstances((IEnumSetupInstances**)&enumInstances)) ||
- !enumInstances) {
- return false;
- }
-
std::string const wantVersion = std::to_string(this->Version) + '.';
bool specifiedLocationNotSpecifiedVersion = false;
SmartCOMPtr<ISetupInstance> instance;
- while (SUCCEEDED(enumInstances->Next(1, &instance, NULL)) && instance) {
- SmartCOMPtr<ISetupInstance2> instance2 = NULL;
- if (FAILED(
- instance->QueryInterface(IID_ISetupInstance2, (void**)&instance2)) ||
- !instance2) {
- instance = NULL;
+
+ std::vector<VSInstanceInfo> vecVSInstancesAll;
+
+ // Enumerate VS instances with COM interface
+ if (!EnumerateVSInstancesWithCOM(vecVSInstancesAll)) {
+ return false;
+ }
+
+ std::vector<VSInstanceInfo> vecVSInstances;
+ for (const auto& instanceInfo : vecVSInstancesAll) {
+ // We are looking for a specific major version.
+ if (instanceInfo.Version.size() < wantVersion.size() ||
+ instanceInfo.Version.substr(0, wantVersion.size()) != wantVersion) {
continue;
}
- VSInstanceInfo instanceInfo;
- bool isInstalled = GetVSInstanceInfo(instance2, instanceInfo);
- instance = instance2 = NULL;
-
- if (isInstalled) {
- // We are looking for a specific major version.
- if (instanceInfo.Version.size() < wantVersion.size() ||
- instanceInfo.Version.substr(0, wantVersion.size()) != wantVersion) {
- continue;
+ if (!this->SpecifiedVSInstallLocation.empty()) {
+ // We are looking for a specific instance.
+ std::string currentVSLocation = instanceInfo.GetInstallLocation();
+ if (cmSystemTools::ComparePath(currentVSLocation,
+ this->SpecifiedVSInstallLocation)) {
+ if (this->SpecifiedVSInstallVersion.empty() ||
+ instanceInfo.Version == this->SpecifiedVSInstallVersion) {
+ chosenInstanceInfo = instanceInfo;
+ return true;
+ }
+ specifiedLocationNotSpecifiedVersion = true;
}
-
- if (!this->SpecifiedVSInstallLocation.empty()) {
- // We are looking for a specific instance.
- std::string currentVSLocation = instanceInfo.GetInstallLocation();
+ } else if (!this->SpecifiedVSInstallVersion.empty()) {
+ // We are looking for a specific version.
+ if (instanceInfo.Version == this->SpecifiedVSInstallVersion) {
+ chosenInstanceInfo = instanceInfo;
+ return true;
+ }
+ } else {
+ // We are not looking for a specific instance.
+ // If we've been given a hint then use it.
+ if (!envVSCommonToolsDir.empty()) {
+ std::string currentVSLocation =
+ cmStrCat(instanceInfo.GetInstallLocation(), "/Common7/Tools");
if (cmSystemTools::ComparePath(currentVSLocation,
- this->SpecifiedVSInstallLocation)) {
- if (this->SpecifiedVSInstallVersion.empty() ||
- instanceInfo.Version == this->SpecifiedVSInstallVersion) {
- chosenInstanceInfo = instanceInfo;
- return true;
- }
- specifiedLocationNotSpecifiedVersion = true;
- }
- } else if (!this->SpecifiedVSInstallVersion.empty()) {
- // We are looking for a specific version.
- if (instanceInfo.Version == this->SpecifiedVSInstallVersion) {
+ envVSCommonToolsDir)) {
chosenInstanceInfo = instanceInfo;
return true;
}
- } else {
- // We are not looking for a specific instance.
- // If we've been given a hint then use it.
- if (!envVSCommonToolsDir.empty()) {
- std::string currentVSLocation =
- cmStrCat(instanceInfo.GetInstallLocation(), "/Common7/Tools");
- if (cmSystemTools::ComparePath(currentVSLocation,
- envVSCommonToolsDir)) {
- chosenInstanceInfo = instanceInfo;
- return true;
- }
- }
- // Otherwise, add this to the list of candidates.
- vecVSInstances.push_back(instanceInfo);
}
+ // Otherwise, add this to the list of candidates.
+ vecVSInstances.push_back(instanceInfo);
}
}