Skip to content

Commit

Permalink
Merge topic 'vs-sdk-selection' into release-3.27
Browse files Browse the repository at this point in the history
89b611a VS: Select latest Windows SDK even when targeting Windows 8.1 and below
ae97d82 VS: Teach CMAKE_GENERATOR_PLATFORM to support Windows 8.1 SDK selection
15ff896 VS: Teach CMAKE_GENERATOR_PLATFORM to use Windows 10 SDKs for older versions
bba1a23 VS: Consolidate Windows SDK major version selection dispatch
209973e VS: Do not print empty Windows SDK version when none is selected
ec6dd77 Tests: Remove redundant condition in RunCMake.GeneratorPlatform test
4776a58 Help: Add 3.27 release note on VS default SDK selection

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !8697
  • Loading branch information
bradking authored and kwrobot committed Aug 10, 2023
2 parents d22a1f0 + 89b611a commit 065474d
Show file tree
Hide file tree
Showing 18 changed files with 201 additions and 109 deletions.
18 changes: 17 additions & 1 deletion Help/release/3.27.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Generators
linker will cause a relink if they change (typically modified timestamps).
See the :variable:`CMAKE_LINK_DEPENDS_USE_LINKER` variable.

* The :ref:`Visual Studio Generators` for VS 2015 and above learned to
* The :ref:`Visual Studio Generators` for VS 14 (2015) and above learned to
select the Windows SDK version explicitly using a ``version=`` field
in the :variable:`CMAKE_GENERATOR_PLATFORM` variable.
See :ref:`Visual Studio Platform Selection`.
Expand Down Expand Up @@ -257,6 +257,9 @@ Other Changes
* :ref:`Visual Studio Generators`, for VS 15.8 (2017) and newer, now
build custom commands in parallel. See policy :policy:`CMP0147`.

* :ref:`Visual Studio Generators` for VS 14 (2015) and above now prefer
to select the latest Windows SDK version. See policy :policy:`CMP0149`.

Updates
=======

Expand All @@ -268,3 +271,16 @@ Changes made since CMake 3.27.0 include the following.
* This version made no changes to documented features or interfaces.
Some implementation updates were made to support ecosystem changes
and/or fix regressions.

3.27.2
------

* :ref:`Visual Studio Generators` for VS 14 (2015) and above now prefer to
select the latest Windows SDK, as documented by policy :policy:`CMP0149`,
when targeting any version of Windows. In CMake 3.27.[0-1] the
preference was limited to targeting Windows 10 and above.

* :ref:`Visual Studio Generators` for VS 14 (2015) and above now support
using ``version=8.1`` in the :variable:`CMAKE_GENERATOR_PLATFORM` variable
to select the Windows 8.1 SDK. In CMake 3.27.[0-1] the ``version=`` field
was limited to selecting Windows 10 SDKs.
6 changes: 5 additions & 1 deletion Help/variable/CMAKE_GENERATOR_PLATFORM.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Supported pairs are:
.. 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
above when targeting Windows or Windows Store. CMake will set the
:variable:`CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION` variable to the
selected SDK version.

Expand All @@ -66,6 +66,10 @@ Supported pairs are:
the value of :variable:`CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION_MAXIMUM`,
if that variable is set.

``8.1``
Specify the 8.1 SDK version. This is always supported by VS 2015.
On VS 2017 and above the 8.1 SDK must be installed.

If the ``version`` field is not specified, CMake selects a version as
described in the :variable:`CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION`
variable documentation.
2 changes: 1 addition & 1 deletion Source/cmGlobalVisualStudio10Generator.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ bool cmGlobalVisualStudio10Generator::InitializePlatformWindows(cmMakefile*)
}

bool cmGlobalVisualStudio10Generator::VerifyNoGeneratorPlatformVersion(
cmMakefile*, cm::optional<std::string>) const
cmMakefile*) const
{
return true;
}
Expand Down
3 changes: 1 addition & 2 deletions Source/cmGlobalVisualStudio10Generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@ class cmGlobalVisualStudio10Generator : public cmGlobalVisualStudio8Generator

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 VerifyNoGeneratorPlatformVersion(cmMakefile* mf) const;

virtual bool ProcessGeneratorToolsetField(std::string const& key,
std::string const& value);
Expand Down
127 changes: 100 additions & 27 deletions Source/cmGlobalVisualStudio14Generator.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <sstream>

#include <cm/vector>
#include <cmext/string_view>

#include "cmGlobalGenerator.h"
#include "cmGlobalGeneratorFactory.h"
Expand Down Expand Up @@ -140,14 +141,103 @@ bool cmGlobalVisualStudio14Generator::MatchesGeneratorName(

bool cmGlobalVisualStudio14Generator::InitializePlatformWindows(cmMakefile* mf)
{
if (cmHasLiteralPrefix(this->SystemVersion, "10.0")) {
// If a Windows SDK version is explicitly requested, search for it.
if (this->GeneratorPlatformVersion) {
std::string const& version = *this->GeneratorPlatformVersion;

// VS 2019 and above support specifying plain "10.0".
if (version == "10.0"_s) {
if (this->Version >= VSVersion::VS16) {
this->SetWindowsTargetPlatformVersion("10.0", mf);
return true;
}
/* clang-format off */
mf->IssueMessage(MessageType::FATAL_ERROR, cmStrCat(
"Generator\n"
" ", this->GetName(), "\n"
"given platform specification containing a\n"
" version=10.0\n"
"field. The value 10.0 is only supported by VS 2019 and above.\n"
));
/* clang-format on */
return false;
}

if (cmHasLiteralPrefix(version, "10.0.")) {
return this->SelectWindows10SDK(mf);
}

if (version == "8.1"_s) {
if (this->IsWin81SDKInstalled()) {
this->SetWindowsTargetPlatformVersion("8.1", mf);
return true;
}
/* clang-format off */
mf->IssueMessage(MessageType::FATAL_ERROR, cmStrCat(
"Generator\n"
" ", this->GetName(), "\n"
"given platform specification containing a\n"
" version=8.1\n"
"field, but the Windows 8.1 SDK is not installed.\n"
));
/* clang-format on */
return false;
}

if (version.empty()) {
/* clang-format off */
mf->IssueMessage(MessageType::FATAL_ERROR, cmStrCat(
"Generator\n"
" ", this->GetName(), "\n"
"given platform specification with empty\n"
" version=\n"
"field.\n"
));
/* clang-format on */
return false;
}

/* clang-format off */
mf->IssueMessage(MessageType::FATAL_ERROR, cmStrCat(
"Generator\n"
" ", this->GetName(), "\n"
"given platform specification containing a\n"
" version=", version, "\n"
"field with unsupported value.\n"
));
/* clang-format on */
return false;
}

// 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->VerifyNoGeneratorPlatformVersion(mf);

// Under CMP0149 NEW behavior, we search for a Windows 10 SDK even
// when targeting older Windows versions, but it is not required.
if (mf->GetPolicyStatus(cmPolicies::CMP0149) == cmPolicies::NEW) {
std::string const version = this->GetWindows10SDKVersion(mf);
if (!version.empty()) {
this->SetWindowsTargetPlatformVersion(version, mf);
return true;
}
}

// 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 true;
}

bool cmGlobalVisualStudio14Generator::VerifyNoGeneratorPlatformVersion(
cmMakefile* mf, cm::optional<std::string> reason) const
cmMakefile* mf) const
{
if (!this->GeneratorPlatformVersion) {
return true;
Expand All @@ -163,9 +253,6 @@ bool cmGlobalVisualStudio14Generator::VerifyNoGeneratorPlatformVersion(
" " << this->SystemName << " " << this->SystemVersion << "\n"
;
/* clang-format on */
if (reason) {
e << *reason << ".";
}
mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
return false;
}
Expand Down Expand Up @@ -207,16 +294,6 @@ bool cmGlobalVisualStudio14Generator::ProcessGeneratorPlatformField(

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);

Expand Down Expand Up @@ -248,7 +325,8 @@ void cmGlobalVisualStudio14Generator::SetWindowsTargetPlatformVersion(
std::string const& version, cmMakefile* mf)
{
this->WindowsTargetPlatformVersion = version;
if (!cmSystemTools::VersionCompareEqual(this->WindowsTargetPlatformVersion,
if (!this->WindowsTargetPlatformVersion.empty() &&
!cmSystemTools::VersionCompareEqual(this->WindowsTargetPlatformVersion,
this->SystemVersion)) {
std::ostringstream e;
e << "Selecting Windows SDK version " << this->WindowsTargetPlatformVersion
Expand Down Expand Up @@ -295,6 +373,11 @@ bool cmGlobalVisualStudio14Generator::IsWindowsStoreToolsetInstalled() const
cmSystemTools::KeyWOW64_32);
}

bool cmGlobalVisualStudio14Generator::IsWin81SDKInstalled() const
{
return true;
}

std::string cmGlobalVisualStudio14Generator::GetWindows10SDKMaxVersion(
cmMakefile* mf) const
{
Expand Down Expand Up @@ -356,16 +439,6 @@ 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<std::string> win10Roots;

{
Expand Down
6 changes: 3 additions & 3 deletions Source/cmGlobalVisualStudio14Generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ class cmGlobalVisualStudio14Generator : public cmGlobalVisualStudio12Generator
// of the toolset is installed
bool IsWindowsStoreToolsetInstalled() const;

virtual bool IsWin81SDKInstalled() const;

bool InitializePlatformWindows(cmMakefile* mf) override;
bool VerifyNoGeneratorPlatformVersion(
cmMakefile* mf,
cm::optional<std::string> reason = cm::nullopt) const override;
bool VerifyNoGeneratorPlatformVersion(cmMakefile* mf) const override;

bool ProcessGeneratorPlatformField(std::string const& key,
std::string const& value) override;
Expand Down
20 changes: 0 additions & 20 deletions Source/cmGlobalVisualStudioVersionedGenerator.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -901,26 +901,6 @@ cmGlobalVisualStudioVersionedGenerator::FindAuxToolset(
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(
std::string& toolset) const
{
Expand Down
4 changes: 1 addition & 3 deletions Source/cmGlobalVisualStudioVersionedGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,8 @@ class cmGlobalVisualStudioVersionedGenerator
// 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;
bool IsWin81SDKInstalled() const override;

std::string GetWindows10SDKMaxVersionDefault(cmMakefile*) const override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

given platform specification with

version=1\.2\.3\.4
version=10\.0\.0\.0

field, but no Windows SDK with that version was found\.$
19 changes: 0 additions & 19 deletions Tests/RunCMake/GeneratorPlatform/BadVersionPlatform-stderr.txt

This file was deleted.

11 changes: 11 additions & 0 deletions Tests/RunCMake/GeneratorPlatform/BadVersionPre2019-stderr.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
^CMake Error at CMakeLists.txt:[0-9]+ \(project\):
Generator

Visual Studio [^
]+

given platform specification containing a

version=10\.0

field\. The value 10\.0 is only supported by VS 2019 and above\.$
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
11 changes: 11 additions & 0 deletions Tests/RunCMake/GeneratorPlatform/BadVersionUnsupported-stderr.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
^CMake Error at CMakeLists.txt:[0-9]+ \(project\):
Generator

Visual Studio [^
]+

given platform specification containing a

version=1\.2\.3\.4

field with unsupported value\.$
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
message(FATAL_ERROR "This should not be reached!")
Loading

0 comments on commit 065474d

Please sign in to comment.