Просмотр исходного кода

cmVSSetupHelper: Add option to specify an instance

Brad King 8 лет назад
Родитель
Сommit
17edfa4198
2 измененных файлов с 29 добавлено и 4 удалено
  1. 25 4
      Source/cmVSSetupHelper.cxx
  2. 4 0
      Source/cmVSSetupHelper.h

+ 25 - 4
Source/cmVSSetupHelper.cxx

@@ -80,6 +80,14 @@ cmVSSetupAPIHelper::~cmVSSetupAPIHelper()
     CoUninitialize();
 }
 
+bool cmVSSetupAPIHelper::SetVSInstance(std::string const& vsInstallLocation)
+{
+  this->SpecifiedVSInstallLocation = vsInstallLocation;
+  cmSystemTools::ConvertToUnixSlashes(this->SpecifiedVSInstallLocation);
+  chosenInstanceInfo = VSInstanceInfo();
+  return this->EnumerateAndChooseVSInstance();
+}
+
 bool cmVSSetupAPIHelper::IsVS2017Installed()
 {
   return this->EnumerateAndChooseVSInstance();
@@ -296,16 +304,29 @@ bool cmVSSetupAPIHelper::EnumerateAndChooseVSInstance()
     instance = instance2 = NULL;
 
     if (isInstalled) {
-      if (!envVSCommonToolsDir.empty()) {
+      if (!this->SpecifiedVSInstallLocation.empty()) {
+        // We are looking for a specific instance.
         std::string currentVSLocation = instanceInfo.GetInstallLocation();
-        currentVSLocation += "/Common7/Tools";
         if (cmSystemTools::ComparePath(currentVSLocation,
-                                       envVSCommonToolsDir)) {
+                                       this->SpecifiedVSInstallLocation)) {
           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 = instanceInfo.GetInstallLocation();
+          currentVSLocation += "/Common7/Tools";
+          if (cmSystemTools::ComparePath(currentVSLocation,
+                                         envVSCommonToolsDir)) {
+            chosenInstanceInfo = instanceInfo;
+            return true;
+          }
+        }
+        // Otherwise, add this to the list of candidates.
+        vecVSInstances.push_back(instanceInfo);
       }
-      vecVSInstances.push_back(instanceInfo);
     }
   }
 

+ 4 - 0
Source/cmVSSetupHelper.h

@@ -126,6 +126,8 @@ public:
   cmVSSetupAPIHelper();
   ~cmVSSetupAPIHelper();
 
+  bool SetVSInstance(std::string const& vsInstallLocation);
+
   bool IsVS2017Installed();
   bool GetVSInstanceInfo(std::string& vsInstallLocation);
   bool IsWin10SDKInstalled();
@@ -150,6 +152,8 @@ private:
   HRESULT comInitialized;
   // current best instance of VS selected
   VSInstanceInfo chosenInstanceInfo;
+
+  std::string SpecifiedVSInstallLocation;
 };
 
 #endif