Browse Source

VS: Consolidate Windows SDK major version selection dispatch

Make logic choosing between Windows 10 SDKs and the Windows 8.1 SDK
easier to follow by consolidating it in the VS 14 generator.  The only
information we need from VS 15+ generators is whether the 8.1 SDK is
installed.
Brad King 2 years ago
parent
commit
bba1a23da9

+ 20 - 1
Source/cmGlobalVisualStudio14Generator.cxx

@@ -140,9 +140,23 @@ bool cmGlobalVisualStudio14Generator::MatchesGeneratorName(
 
 
 bool cmGlobalVisualStudio14Generator::InitializePlatformWindows(cmMakefile* mf)
 bool cmGlobalVisualStudio14Generator::InitializePlatformWindows(cmMakefile* mf)
 {
 {
-  if (cmHasLiteralPrefix(this->SystemVersion, "10.0")) {
+  // If we are targeting Windows 10+, we select a Windows 10 SDK.
+  // If no Windows 8.1 SDK is installed, which is possible with VS 2017 and
+  // higher, then we must choose a Windows 10 SDK anyway.
+  if (cmHasLiteralPrefix(this->SystemVersion, "10.0") ||
+      !this->IsWin81SDKInstalled()) {
     return this->SelectWindows10SDK(mf);
     return this->SelectWindows10SDK(mf);
   }
   }
+
+  // We are not targeting Windows 10+, so fall back to the Windows 8.1 SDK.
+  // For VS 2019 and above we must explicitly specify it.
+  if (this->Version >= cmGlobalVisualStudioGenerator::VSVersion::VS16 &&
+      !cmSystemTools::VersionCompareGreater(this->SystemVersion, "8.1")) {
+    this->SetWindowsTargetPlatformVersion("8.1", mf);
+    return this->VerifyNoGeneratorPlatformVersion(
+      mf, "with the Windows 8.1 SDK installed");
+  }
+
   return this->VerifyNoGeneratorPlatformVersion(mf);
   return this->VerifyNoGeneratorPlatformVersion(mf);
 }
 }
 
 
@@ -296,6 +310,11 @@ bool cmGlobalVisualStudio14Generator::IsWindowsStoreToolsetInstalled() const
                                           cmSystemTools::KeyWOW64_32);
                                           cmSystemTools::KeyWOW64_32);
 }
 }
 
 
+bool cmGlobalVisualStudio14Generator::IsWin81SDKInstalled() const
+{
+  return true;
+}
+
 std::string cmGlobalVisualStudio14Generator::GetWindows10SDKMaxVersion(
 std::string cmGlobalVisualStudio14Generator::GetWindows10SDKMaxVersion(
   cmMakefile* mf) const
   cmMakefile* mf) const
 {
 {

+ 2 - 0
Source/cmGlobalVisualStudio14Generator.h

@@ -40,6 +40,8 @@ protected:
   // of the toolset is installed
   // of the toolset is installed
   bool IsWindowsStoreToolsetInstalled() const;
   bool IsWindowsStoreToolsetInstalled() const;
 
 
+  virtual bool IsWin81SDKInstalled() const;
+
   bool InitializePlatformWindows(cmMakefile* mf) override;
   bool InitializePlatformWindows(cmMakefile* mf) override;
   bool VerifyNoGeneratorPlatformVersion(
   bool VerifyNoGeneratorPlatformVersion(
     cmMakefile* mf,
     cmMakefile* mf,

+ 0 - 20
Source/cmGlobalVisualStudioVersionedGenerator.cxx

@@ -901,26 +901,6 @@ cmGlobalVisualStudioVersionedGenerator::FindAuxToolset(
   return AuxToolset::PropsMissing;
   return AuxToolset::PropsMissing;
 }
 }
 
 
-bool cmGlobalVisualStudioVersionedGenerator::InitializePlatformWindows(
-  cmMakefile* mf)
-{
-  // If the Win 8.1 SDK is installed then we can select a SDK matching
-  // the target Windows version.
-  if (this->IsWin81SDKInstalled()) {
-    // VS 2019 does not default to 8.1 so specify it explicitly when needed.
-    if (this->Version >= cmGlobalVisualStudioGenerator::VSVersion::VS16 &&
-        !cmSystemTools::VersionCompareGreater(this->SystemVersion, "8.1")) {
-      this->SetWindowsTargetPlatformVersion("8.1", mf);
-      return this->VerifyNoGeneratorPlatformVersion(
-        mf, "with the Windows 8.1 SDK installed");
-    }
-    return cmGlobalVisualStudio14Generator::InitializePlatformWindows(mf);
-  }
-  // Otherwise we must choose a Win 10 SDK even if we are not targeting
-  // Windows 10.
-  return this->SelectWindows10SDK(mf);
-}
-
 bool cmGlobalVisualStudioVersionedGenerator::SelectWindowsStoreToolset(
 bool cmGlobalVisualStudioVersionedGenerator::SelectWindowsStoreToolset(
   std::string& toolset) const
   std::string& toolset) const
 {
 {

+ 1 - 3
Source/cmGlobalVisualStudioVersionedGenerator.h

@@ -72,10 +72,8 @@ protected:
   // of the toolset is installed
   // of the toolset is installed
   bool IsWindowsStoreToolsetInstalled() const;
   bool IsWindowsStoreToolsetInstalled() const;
 
 
-  bool InitializePlatformWindows(cmMakefile* mf) override;
-
   // Check for a Win 8 SDK known to the registry or VS installer tool.
   // Check for a Win 8 SDK known to the registry or VS installer tool.
-  bool IsWin81SDKInstalled() const;
+  bool IsWin81SDKInstalled() const override;
 
 
   std::string GetWindows10SDKMaxVersionDefault(cmMakefile*) const override;
   std::string GetWindows10SDKMaxVersionDefault(cmMakefile*) const override;