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
This commit is contained in:
Brad King
2023-04-03 10:11:49 -04:00
parent f0a67b6291
commit 2f3d945f83
22 changed files with 248 additions and 15 deletions

View File

@@ -26,6 +26,8 @@ Platform specification is supported only on specific generators:
See native build system documentation for allowed platform names.
.. _`Visual Studio Platform Selection`:
Visual Studio Platform Selection
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -42,4 +44,24 @@ name is provided in the :variable:`CMAKE_VS_PLATFORM_NAME` variable.
The ``key=value`` pairs form a comma-separated list of options to
specify generator-specific details of the platform selection.
There are no supported pairs: this syntax is reserved for future use.
Supported pairs are:
``version=<version>``
.. versionadded:: 3.27
Specify the Windows SDK version to use. This is supported by VS 2015 and
above when targeting Windows 10.0+ or Windows Store. CMake will set the
:variable:`CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION` variable to the
selected SDK version.
The ``<version>`` may be one of:
``10.0.<build>.<increment>``
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
the value of :variable:`CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION_MAXIMUM`,
if that variable is set.
If the ``version`` field is not specified, CMake selects a version as
described in the :variable:`CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION`
variable documentation.

View File

@@ -5,11 +5,19 @@ CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION
Visual Studio Windows Target Platform Version.
When targeting Windows 10 and above Visual Studio 2015 and above support
specification of a target Windows version to select a corresponding SDK.
The :variable:`CMAKE_SYSTEM_VERSION` variable may be set to specify a
version. Otherwise CMake computes a default version based on the Windows
SDK versions available. The chosen Windows target version number is provided
When targeting Windows 10 and above, :ref:`Visual Studio Generators` for
VS 2015 and above support specification of a Windows SDK version:
* If :variable:`CMAKE_GENERATOR_PLATFORM` specifies a ``version=`` field,
as documented by :ref:`Visual Studio Platform Selection`, that SDK
version is selected.
* Otherwise, if :variable:`CMAKE_SYSTEM_VERSION` is set to an available
SDK version, that version is selected.
* Otherwise, CMake uses the latest Windows SDK version available.
The chosen Windows target version number is provided
in ``CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION``. If no Windows 10 SDK
is available this value will be empty.

View File

@@ -10,5 +10,5 @@ be set to a false value (e.g. ``OFF``, ``FALSE``, or ``0``) or the SDK version
to use as the maximum (e.g. ``10.0.14393.0``). If unset, the default depends
on which version of Visual Studio is targeted by the current generator.
This can be used in conjunction with :variable:`CMAKE_SYSTEM_VERSION`, which
CMake uses to select :variable:`CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION`.
This can be used to exclude Windows SDK versions from consideration for
:variable:`CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION`.