Browse Source

VS: Defer Windows SDK selection until CMAKE_GENERATOR_PLATFORM is known

Prepare to teach `CMAKE_GENERATOR_PLATFORM` to affect SDK selection.
Brad King 2 years ago
parent
commit
e259063b0a

+ 15 - 0
Source/cmGlobalVisualStudio10Generator.cxx

@@ -525,6 +525,21 @@ bool cmGlobalVisualStudio10Generator::InitializeAndroid(cmMakefile* mf)
   return false;
 }
 
+bool cmGlobalVisualStudio10Generator::InitializePlatform(cmMakefile* mf)
+{
+  if (this->SystemName == "Windows" || this->SystemName == "WindowsStore") {
+    if (!this->InitializePlatformWindows(mf)) {
+      return false;
+    }
+  }
+  return this->cmGlobalVisualStudio8Generator::InitializePlatform(mf);
+}
+
+bool cmGlobalVisualStudio10Generator::InitializePlatformWindows(cmMakefile*)
+{
+  return true;
+}
+
 bool cmGlobalVisualStudio10Generator::SelectWindowsPhoneToolset(
   std::string& toolset) const
 {

+ 3 - 0
Source/cmGlobalVisualStudio10Generator.h

@@ -183,6 +183,9 @@ protected:
   virtual bool InitializeTegraAndroid(cmMakefile* mf);
   virtual bool InitializeAndroid(cmMakefile* mf);
 
+  bool InitializePlatform(cmMakefile* mf) override;
+  virtual bool InitializePlatformWindows(cmMakefile* mf);
+
   virtual bool ProcessGeneratorToolsetField(std::string const& key,
                                             std::string const& value);
 

+ 1 - 4
Source/cmGlobalVisualStudio14Generator.cxx

@@ -137,7 +137,7 @@ bool cmGlobalVisualStudio14Generator::MatchesGeneratorName(
   return false;
 }
 
-bool cmGlobalVisualStudio14Generator::InitializeWindows(cmMakefile* mf)
+bool cmGlobalVisualStudio14Generator::InitializePlatformWindows(cmMakefile* mf)
 {
   if (cmHasLiteralPrefix(this->SystemVersion, "10.0")) {
     return this->SelectWindows10SDK(mf);
@@ -162,9 +162,6 @@ bool cmGlobalVisualStudio14Generator::InitializeWindowsStore(cmMakefile* mf)
     mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
     return false;
   }
-  if (cmHasLiteralPrefix(this->SystemVersion, "10.0")) {
-    return this->SelectWindows10SDK(mf);
-  }
   return true;
 }
 

+ 2 - 1
Source/cmGlobalVisualStudio14Generator.h

@@ -30,7 +30,6 @@ protected:
   cmGlobalVisualStudio14Generator(cmake* cm, const std::string& name,
                                   std::string const& platformInGeneratorName);
 
-  bool InitializeWindows(cmMakefile* mf) override;
   bool InitializeWindowsStore(cmMakefile* mf) override;
   bool InitializeAndroid(cmMakefile* mf) override;
   bool SelectWindowsStoreToolset(std::string& toolset) const override;
@@ -39,6 +38,8 @@ protected:
   // of the toolset is installed
   bool IsWindowsStoreToolsetInstalled() const;
 
+  bool InitializePlatformWindows(cmMakefile* mf) override;
+
   // Used to adjust the max-SDK-version calculation to accommodate user
   // configuration.
   std::string GetWindows10SDKMaxVersion(cmMakefile* mf) const;

+ 9 - 0
Source/cmGlobalVisualStudio8Generator.cxx

@@ -114,12 +114,21 @@ bool cmGlobalVisualStudio8Generator::SetGeneratorPlatform(std::string const& p,
                       *targetFrameworkTargetsVersion);
   }
 
+  if (!this->InitializePlatform(mf)) {
+    return false;
+  }
+
   // The generator name does not contain the platform name, and so supports
   // explicit platform specification.  We handled that above, so pass an
   // empty platform name to our base class implementation so it does not error.
   return this->cmGlobalVisualStudio7Generator::SetGeneratorPlatform("", mf);
 }
 
+bool cmGlobalVisualStudio8Generator::InitializePlatform(cmMakefile*)
+{
+  return true;
+}
+
 cm::optional<std::string> const&
 cmGlobalVisualStudio8Generator::GetTargetFrameworkVersion() const
 {

+ 2 - 0
Source/cmGlobalVisualStudio8Generator.h

@@ -60,6 +60,8 @@ protected:
   cmGlobalVisualStudio8Generator(cmake* cm, const std::string& name,
                                  std::string const& platformInGeneratorName);
 
+  virtual bool InitializePlatform(cmMakefile* mf);
+
   void AddExtraIDETargets() override;
 
   std::string FindDevEnvCommand() override;

+ 3 - 2
Source/cmGlobalVisualStudioVersionedGenerator.cxx

@@ -885,7 +885,8 @@ cmGlobalVisualStudioVersionedGenerator::FindAuxToolset(
   return AuxToolset::PropsMissing;
 }
 
-bool cmGlobalVisualStudioVersionedGenerator::InitializeWindows(cmMakefile* mf)
+bool cmGlobalVisualStudioVersionedGenerator::InitializePlatformWindows(
+  cmMakefile* mf)
 {
   // If the Win 8.1 SDK is installed then we can select a SDK matching
   // the target Windows version.
@@ -896,7 +897,7 @@ bool cmGlobalVisualStudioVersionedGenerator::InitializeWindows(cmMakefile* mf)
       this->SetWindowsTargetPlatformVersion("8.1", mf);
       return true;
     }
-    return cmGlobalVisualStudio14Generator::InitializeWindows(mf);
+    return cmGlobalVisualStudio14Generator::InitializePlatformWindows(mf);
   }
   // Otherwise we must choose a Win 10 SDK even if we are not targeting
   // Windows 10.

+ 2 - 1
Source/cmGlobalVisualStudioVersionedGenerator.h

@@ -61,7 +61,6 @@ protected:
     VSVersion version, cmake* cm, const std::string& name,
     std::string const& platformInGeneratorName);
 
-  bool InitializeWindows(cmMakefile* mf) override;
   bool SelectWindowsStoreToolset(std::string& toolset) const override;
 
   // Used to verify that the Desktop toolset for the current generator is
@@ -72,6 +71,8 @@ protected:
   // of the toolset is installed
   bool IsWindowsStoreToolsetInstalled() const;
 
+  bool InitializePlatformWindows(cmMakefile* mf) override;
+
   // Check for a Win 8 SDK known to the registry or VS installer tool.
   bool IsWin81SDKInstalled() const;