summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-04-03 14:11:49 (GMT)
committerBrad King <brad.king@kitware.com>2023-04-05 16:06:22 (GMT)
commit2f3d945f8382fef4139c7d0c3879f6ff2f3756a0 (patch)
treefc31f53ed3169a2b1d0755f190ec945ca48cc896 /Source
parentf0a67b629192466cec463c41df56ef3244817f70 (diff)
downloadCMake-2f3d945f8382fef4139c7d0c3879f6ff2f3756a0.zip
CMake-2f3d945f8382fef4139c7d0c3879f6ff2f3756a0.tar.gz
CMake-2f3d945f8382fef4139c7d0c3879f6ff2f3756a0.tar.bz2
VS: Add CMAKE_GENERATOR_PLATFORM field to control Windows SDK selection
Add a `version=` field to explicitly control the SDK version selection without relying on `CMAKE_SYSTEM_VERSION`. Fixes: #16713
Diffstat (limited to 'Source')
-rw-r--r--Source/cmGlobalVisualStudio10Generator.cxx9
-rw-r--r--Source/cmGlobalVisualStudio10Generator.h2
-rw-r--r--Source/cmGlobalVisualStudio14Generator.cxx71
-rw-r--r--Source/cmGlobalVisualStudio14Generator.h10
-rw-r--r--Source/cmGlobalVisualStudioVersionedGenerator.cxx3
5 files changed, 92 insertions, 3 deletions
diff --git a/Source/cmGlobalVisualStudio10Generator.cxx b/Source/cmGlobalVisualStudio10Generator.cxx
index 41d54e5..321f377 100644
--- a/Source/cmGlobalVisualStudio10Generator.cxx
+++ b/Source/cmGlobalVisualStudio10Generator.cxx
@@ -531,6 +531,9 @@ bool cmGlobalVisualStudio10Generator::InitializePlatform(cmMakefile* mf)
if (!this->InitializePlatformWindows(mf)) {
return false;
}
+ } else if (!this->SystemName.empty() &&
+ !this->VerifyNoGeneratorPlatformVersion(mf)) {
+ return false;
}
return this->cmGlobalVisualStudio8Generator::InitializePlatform(mf);
}
@@ -540,6 +543,12 @@ bool cmGlobalVisualStudio10Generator::InitializePlatformWindows(cmMakefile*)
return true;
}
+bool cmGlobalVisualStudio10Generator::VerifyNoGeneratorPlatformVersion(
+ cmMakefile*, cm::optional<std::string>) const
+{
+ return true;
+}
+
bool cmGlobalVisualStudio10Generator::SelectWindowsPhoneToolset(
std::string& toolset) const
{
diff --git a/Source/cmGlobalVisualStudio10Generator.h b/Source/cmGlobalVisualStudio10Generator.h
index 63cfe72..6917ffc 100644
--- a/Source/cmGlobalVisualStudio10Generator.h
+++ b/Source/cmGlobalVisualStudio10Generator.h
@@ -185,6 +185,8 @@ protected:
bool InitializePlatform(cmMakefile* mf) override;
virtual bool InitializePlatformWindows(cmMakefile* mf);
+ virtual bool VerifyNoGeneratorPlatformVersion(
+ cmMakefile* mf, cm::optional<std::string> reason = cm::nullopt) const;
virtual bool ProcessGeneratorToolsetField(std::string const& key,
std::string const& value);
diff --git a/Source/cmGlobalVisualStudio14Generator.cxx b/Source/cmGlobalVisualStudio14Generator.cxx
index 87c8a5e..9ae80bb 100644
--- a/Source/cmGlobalVisualStudio14Generator.cxx
+++ b/Source/cmGlobalVisualStudio14Generator.cxx
@@ -142,7 +142,31 @@ bool cmGlobalVisualStudio14Generator::InitializePlatformWindows(cmMakefile* mf)
if (cmHasLiteralPrefix(this->SystemVersion, "10.0")) {
return this->SelectWindows10SDK(mf);
}
- return true;
+ return this->VerifyNoGeneratorPlatformVersion(mf);
+}
+
+bool cmGlobalVisualStudio14Generator::VerifyNoGeneratorPlatformVersion(
+ cmMakefile* mf, cm::optional<std::string> reason) const
+{
+ if (!this->GeneratorPlatformVersion) {
+ return true;
+ }
+ std::ostringstream e;
+ /* clang-format off */
+ e <<
+ "Generator\n"
+ " " << this->GetName() << "\n"
+ "given platform specification containing a\n"
+ " version=" << *this->GeneratorPlatformVersion << "\n"
+ "field. The version field is not supported when targeting\n"
+ " " << this->SystemName << " " << this->SystemVersion << "\n"
+ ;
+ /* clang-format on */
+ if (reason) {
+ e << *reason << ".";
+ }
+ mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
+ return false;
}
bool cmGlobalVisualStudio14Generator::InitializeWindowsStore(cmMakefile* mf)
@@ -170,12 +194,42 @@ bool cmGlobalVisualStudio14Generator::InitializeAndroid(cmMakefile*)
return true;
}
+bool cmGlobalVisualStudio14Generator::ProcessGeneratorPlatformField(
+ std::string const& key, std::string const& value)
+{
+ if (key == "version") {
+ this->GeneratorPlatformVersion = value;
+ return true;
+ }
+ return false;
+}
+
bool cmGlobalVisualStudio14Generator::SelectWindows10SDK(cmMakefile* mf)
{
+ if (this->GeneratorPlatformVersion &&
+ this->GeneratorPlatformVersion->empty()) {
+ mf->IssueMessage(
+ MessageType::FATAL_ERROR,
+ cmStrCat("Generator\n ", this->GetName(),
+ "\ngiven platform specification with empty\n version=\n"
+ "field."));
+ return false;
+ }
+
// Find the default version of the Windows 10 SDK.
std::string const version = this->GetWindows10SDKVersion(mf);
if (version.empty()) {
+ if (this->GeneratorPlatformVersion) {
+ mf->IssueMessage(
+ MessageType::FATAL_ERROR,
+ cmStrCat("Generator\n ", this->GetName(),
+ "\ngiven platform specification with\n version=",
+ *this->GeneratorPlatformVersion,
+ "\nfield, but no Windows SDK with that version was found."));
+ return false;
+ }
+
if (this->SystemName == "WindowsStore") {
mf->IssueMessage(
MessageType::FATAL_ERROR,
@@ -359,7 +413,20 @@ std::string cmGlobalVisualStudio14Generator::GetWindows10SDKVersion(
// Sort the results to make sure we select the most recent one.
std::sort(sdks.begin(), sdks.end(), cmSystemTools::VersionCompareGreater);
- // Look for a SDK exactly matching the requested target version.
+ // Look for a SDK exactly matching the requested version, if any.
+ if (this->GeneratorPlatformVersion) {
+ for (std::string const& i : sdks) {
+ if (cmSystemTools::VersionCompareEqual(
+ i, *this->GeneratorPlatformVersion)) {
+ return i;
+ }
+ }
+ // An exact version was requested but not found.
+ // Our caller will issue the error message.
+ return std::string();
+ }
+
+ // Look for a SDK exactly matching the target Windows version.
for (std::string const& i : sdks) {
if (cmSystemTools::VersionCompareEqual(i, this->SystemVersion)) {
return i;
diff --git a/Source/cmGlobalVisualStudio14Generator.h b/Source/cmGlobalVisualStudio14Generator.h
index 0f016b3..f59a323 100644
--- a/Source/cmGlobalVisualStudio14Generator.h
+++ b/Source/cmGlobalVisualStudio14Generator.h
@@ -7,6 +7,8 @@
#include <memory>
#include <string>
+#include <cm/optional>
+
#include "cmGlobalVisualStudio12Generator.h"
class cmGlobalGeneratorFactory;
@@ -39,6 +41,12 @@ protected:
bool IsWindowsStoreToolsetInstalled() const;
bool InitializePlatformWindows(cmMakefile* mf) override;
+ bool VerifyNoGeneratorPlatformVersion(
+ cmMakefile* mf,
+ cm::optional<std::string> reason = cm::nullopt) const override;
+
+ bool ProcessGeneratorPlatformField(std::string const& key,
+ std::string const& value) override;
// Used to adjust the max-SDK-version calculation to accommodate user
// configuration.
@@ -62,4 +70,6 @@ protected:
private:
class Factory;
friend class Factory;
+
+ cm::optional<std::string> GeneratorPlatformVersion;
};
diff --git a/Source/cmGlobalVisualStudioVersionedGenerator.cxx b/Source/cmGlobalVisualStudioVersionedGenerator.cxx
index f3936ce..f28419a 100644
--- a/Source/cmGlobalVisualStudioVersionedGenerator.cxx
+++ b/Source/cmGlobalVisualStudioVersionedGenerator.cxx
@@ -895,7 +895,8 @@ bool cmGlobalVisualStudioVersionedGenerator::InitializePlatformWindows(
if (this->Version >= cmGlobalVisualStudioGenerator::VSVersion::VS16 &&
!cmSystemTools::VersionCompareGreater(this->SystemVersion, "8.1")) {
this->SetWindowsTargetPlatformVersion("8.1", mf);
- return true;
+ return this->VerifyNoGeneratorPlatformVersion(
+ mf, "with the Windows 8.1 SDK installed");
}
return cmGlobalVisualStudio14Generator::InitializePlatformWindows(mf);
}