From b512c53d43b6078c97e06231ccbfa8599a66a4f4 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 3 Apr 2023 10:56:47 -0400 Subject: VS: Add support for setting WindowsTargetPlatformVersion to 10.0 VS 2019 and above support this value to select a SDK version automatically. Fixes: #21403 --- Help/variable/CMAKE_GENERATOR_PLATFORM.rst | 4 ++++ Source/cmGlobalVisualStudio14Generator.cxx | 10 ++++++++++ Tests/RunCMake/GeneratorPlatform/RunCMakeTest.cmake | 8 ++++++++ 3 files changed, 22 insertions(+) diff --git a/Help/variable/CMAKE_GENERATOR_PLATFORM.rst b/Help/variable/CMAKE_GENERATOR_PLATFORM.rst index 3b6932a559..416ff60f34 100644 --- a/Help/variable/CMAKE_GENERATOR_PLATFORM.rst +++ b/Help/variable/CMAKE_GENERATOR_PLATFORM.rst @@ -56,6 +56,10 @@ Supported pairs are: The ```` may be one of: + ``10.0`` + Specify that any 10.0 SDK version may be used, and let Visual Studio + pick one. This is supported by VS 2019 and above. + ``10.0..`` Specify the exact 4-component SDK version, e.g., ``10.0.19041.0``. The specified version of the SDK must be installed. It may not exceed diff --git a/Source/cmGlobalVisualStudio14Generator.cxx b/Source/cmGlobalVisualStudio14Generator.cxx index 9ae80bbfa7..57082f4839 100644 --- a/Source/cmGlobalVisualStudio14Generator.cxx +++ b/Source/cmGlobalVisualStudio14Generator.cxx @@ -355,6 +355,16 @@ std::string cmGlobalVisualStudio14Generator::GetWindows10SDKVersion( cmMakefile* mf) { #if defined(_WIN32) && !defined(__CYGWIN__) + // Accept specific version requests as-is. + if (this->GeneratorPlatformVersion) { + std::string const& ver = *this->GeneratorPlatformVersion; + + // VS 2019 and above support specifying plain "10.0". + if (this->Version >= VSVersion::VS16 && ver == "10.0") { + return ver; + } + } + std::vector win10Roots; { diff --git a/Tests/RunCMake/GeneratorPlatform/RunCMakeTest.cmake b/Tests/RunCMake/GeneratorPlatform/RunCMakeTest.cmake index 00a32a21a5..96c2b6b3f4 100644 --- a/Tests/RunCMake/GeneratorPlatform/RunCMakeTest.cmake +++ b/Tests/RunCMake/GeneratorPlatform/RunCMakeTest.cmake @@ -39,6 +39,14 @@ if("${RunCMake_GENERATOR}" MATCHES "^Visual Studio (1[4567])( 20[0-9][0-9])?$") set(RunCMake_GENERATOR_PLATFORM "version=8.1") run_cmake_with_options(BadVersionPlatform -DCMAKE_SYSTEM_VERSION=8.1) + if(NOT RunCMake_GENERATOR MATCHES "^Visual Studio (1[45]) ") + set(expect_version "10.0") + set(RunCMake_GENERATOR_PLATFORM "version=${expect_version}") + set(RunCMake_TEST_VARIANT_DESCRIPTION "-${expect_version}") + run_cmake_with_options(VersionExists -DCMAKE_SYSTEM_VERSION=10.0) + unset(RunCMake_GENERATOR_PLATFORM) + endif() + set(kits "") cmake_host_system_information(RESULT kitsRoot10 QUERY WINDOWS_REGISTRY "HKLM/SOFTWARE/Microsoft/Windows Kits/Installed Roots" -- cgit v1.2.1