From 4776a584adc0b9a68a25b5870cfaa58f4dfffb29 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 8 Aug 2023 20:32:52 -0400 Subject: Help: Add 3.27 release note on VS default SDK selection This was accidentally left out of commit f90c8ab54e (VS: Select latest available Windows SDK version by default, 2023-04-03, v3.27.0-rc1~206^2~1). Issue: #16202 --- Help/release/3.27.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Help/release/3.27.rst b/Help/release/3.27.rst index e98a49a..a8218ba 100644 --- a/Help/release/3.27.rst +++ b/Help/release/3.27.rst @@ -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`. @@ -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 ======= -- cgit v0.12 From ec6dd77053b2c88a7a341ac67184fb605a4fa837 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 10 Aug 2023 09:30:19 -0400 Subject: Tests: Remove redundant condition in RunCMake.GeneratorPlatform test --- .../RunCMake/GeneratorPlatform/RunCMakeTest.cmake | 44 +++++++++++----------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/Tests/RunCMake/GeneratorPlatform/RunCMakeTest.cmake b/Tests/RunCMake/GeneratorPlatform/RunCMakeTest.cmake index 233eb0a..9718ca9 100644 --- a/Tests/RunCMake/GeneratorPlatform/RunCMakeTest.cmake +++ b/Tests/RunCMake/GeneratorPlatform/RunCMakeTest.cmake @@ -83,29 +83,27 @@ if("${RunCMake_GENERATOR}" MATCHES "^Visual Studio (1[4567])( 20[0-9][0-9])?$") message(FATAL_ERROR "Could not find any Windows SDKs to drive test cases.") endif() - if(kits) - foreach(expect_version IN LISTS kits) - 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) - endforeach() - foreach(expect_version IN LISTS kits) - set(RunCMake_TEST_VARIANT_DESCRIPTION "-CMP0149-OLD-${expect_version}") - run_cmake_with_options(VersionExists -DCMAKE_SYSTEM_VERSION=${expect_version} -DCMAKE_POLICY_DEFAULT_CMP0149=OLD) - endforeach() - if(kits MATCHES "(^|;)([0-9.]+)$") - set(expect_version "${CMAKE_MATCH_2}") - foreach(test_version IN LISTS kits) - set(RunCMake_TEST_VARIANT_DESCRIPTION "-CMP0149-NEW-${test_version}") - run_cmake_with_options(VersionExists -DCMAKE_SYSTEM_VERSION=${test_version} -DCMAKE_POLICY_DEFAULT_CMP0149=NEW) - endforeach() - endif() - foreach(expect_version IN LISTS kits) - set(RunCMake_TEST_VARIANT_DESCRIPTION "-WindowsSDKVersion-${expect_version}") - set(ENV{WindowsSDKVersion} "${expect_version}\\") - run_cmake_with_options(VersionExists -DCMAKE_SYSTEM_VERSION=10.0 -DCMAKE_POLICY_DEFAULT_CMP0149=NEW) - unset(ENV{WindowsSDKVersion}) + foreach(expect_version IN LISTS kits) + 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) + endforeach() + foreach(expect_version IN LISTS kits) + set(RunCMake_TEST_VARIANT_DESCRIPTION "-CMP0149-OLD-${expect_version}") + run_cmake_with_options(VersionExists -DCMAKE_SYSTEM_VERSION=${expect_version} -DCMAKE_POLICY_DEFAULT_CMP0149=OLD) + endforeach() + if(kits MATCHES "(^|;)([0-9.]+)$") + set(expect_version "${CMAKE_MATCH_2}") + foreach(test_version IN LISTS kits) + set(RunCMake_TEST_VARIANT_DESCRIPTION "-CMP0149-NEW-${test_version}") + run_cmake_with_options(VersionExists -DCMAKE_SYSTEM_VERSION=${test_version} -DCMAKE_POLICY_DEFAULT_CMP0149=NEW) endforeach() endif() + foreach(expect_version IN LISTS kits) + set(RunCMake_TEST_VARIANT_DESCRIPTION "-WindowsSDKVersion-${expect_version}") + set(ENV{WindowsSDKVersion} "${expect_version}\\") + run_cmake_with_options(VersionExists -DCMAKE_SYSTEM_VERSION=10.0 -DCMAKE_POLICY_DEFAULT_CMP0149=NEW) + unset(ENV{WindowsSDKVersion}) + endforeach() endif() -- cgit v0.12 From 209973e510be9555268eb7b5722a56be60661130 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 8 Aug 2023 13:29:54 -0400 Subject: VS: Do not print empty Windows SDK version when none is selected --- Source/cmGlobalVisualStudio14Generator.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/cmGlobalVisualStudio14Generator.cxx b/Source/cmGlobalVisualStudio14Generator.cxx index 4300d5c..20aa0b0 100644 --- a/Source/cmGlobalVisualStudio14Generator.cxx +++ b/Source/cmGlobalVisualStudio14Generator.cxx @@ -248,7 +248,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 -- cgit v0.12 From bba1a23da9d64c4ef8d68d22af7b5c93727b66a7 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 8 Aug 2023 13:31:31 -0400 Subject: VS: Consolidate Windows SDK major version selection dispatch Make logic choosing between Windows 10 SDKs and the Windows 8.1 SDK easier to follow by consolidating it in the VS 14 generator. The only information we need from VS 15+ generators is whether the 8.1 SDK is installed. --- Source/cmGlobalVisualStudio14Generator.cxx | 21 ++++++++++++++++++++- Source/cmGlobalVisualStudio14Generator.h | 2 ++ Source/cmGlobalVisualStudioVersionedGenerator.cxx | 20 -------------------- Source/cmGlobalVisualStudioVersionedGenerator.h | 4 +--- 4 files changed, 23 insertions(+), 24 deletions(-) diff --git a/Source/cmGlobalVisualStudio14Generator.cxx b/Source/cmGlobalVisualStudio14Generator.cxx index 20aa0b0..e74c211 100644 --- a/Source/cmGlobalVisualStudio14Generator.cxx +++ b/Source/cmGlobalVisualStudio14Generator.cxx @@ -140,9 +140,23 @@ bool cmGlobalVisualStudio14Generator::MatchesGeneratorName( bool cmGlobalVisualStudio14Generator::InitializePlatformWindows(cmMakefile* mf) { - if (cmHasLiteralPrefix(this->SystemVersion, "10.0")) { + // 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); } + + // 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 this->VerifyNoGeneratorPlatformVersion( + mf, "with the Windows 8.1 SDK installed"); + } + return this->VerifyNoGeneratorPlatformVersion(mf); } @@ -296,6 +310,11 @@ bool cmGlobalVisualStudio14Generator::IsWindowsStoreToolsetInstalled() const cmSystemTools::KeyWOW64_32); } +bool cmGlobalVisualStudio14Generator::IsWin81SDKInstalled() const +{ + return true; +} + std::string cmGlobalVisualStudio14Generator::GetWindows10SDKMaxVersion( cmMakefile* mf) const { diff --git a/Source/cmGlobalVisualStudio14Generator.h b/Source/cmGlobalVisualStudio14Generator.h index f59a323..d8a5230 100644 --- a/Source/cmGlobalVisualStudio14Generator.h +++ b/Source/cmGlobalVisualStudio14Generator.h @@ -40,6 +40,8 @@ protected: // of the toolset is installed bool IsWindowsStoreToolsetInstalled() const; + virtual bool IsWin81SDKInstalled() const; + bool InitializePlatformWindows(cmMakefile* mf) override; bool VerifyNoGeneratorPlatformVersion( cmMakefile* mf, diff --git a/Source/cmGlobalVisualStudioVersionedGenerator.cxx b/Source/cmGlobalVisualStudioVersionedGenerator.cxx index 602b42f..14c7d0f 100644 --- a/Source/cmGlobalVisualStudioVersionedGenerator.cxx +++ b/Source/cmGlobalVisualStudioVersionedGenerator.cxx @@ -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 { diff --git a/Source/cmGlobalVisualStudioVersionedGenerator.h b/Source/cmGlobalVisualStudioVersionedGenerator.h index 8712459..8f0345f 100644 --- a/Source/cmGlobalVisualStudioVersionedGenerator.h +++ b/Source/cmGlobalVisualStudioVersionedGenerator.h @@ -72,10 +72,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; + bool IsWin81SDKInstalled() const override; std::string GetWindows10SDKMaxVersionDefault(cmMakefile*) const override; -- cgit v0.12 From 15ff89654b925b74f074ef7e13ed905c3ec38c4b Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 8 Aug 2023 16:03:40 -0400 Subject: VS: Teach CMAKE_GENERATOR_PLATFORM to use Windows 10 SDKs for older versions Honor an explicit `version=` field selecting a Windows 10 SDK regardless of the Windows target version. Issue: #25170 --- Help/variable/CMAKE_GENERATOR_PLATFORM.rst | 2 +- Source/cmGlobalVisualStudio10Generator.cxx | 2 +- Source/cmGlobalVisualStudio10Generator.h | 3 +- Source/cmGlobalVisualStudio14Generator.cxx | 82 ++++++++++++++-------- Source/cmGlobalVisualStudio14Generator.h | 4 +- .../GeneratorPlatform/BadVersionMissing-stderr.txt | 2 +- .../BadVersionPlatform-result.txt | 1 - .../BadVersionPlatform-stderr.txt | 19 ----- .../GeneratorPlatform/BadVersionPlatform.cmake | 1 - .../GeneratorPlatform/BadVersionPre2019-result.txt | 1 + .../GeneratorPlatform/BadVersionPre2019-stderr.txt | 11 +++ .../GeneratorPlatform/BadVersionPre2019.cmake | 1 + .../BadVersionUnsupported-result.txt | 1 + .../BadVersionUnsupported-stderr.txt | 11 +++ .../GeneratorPlatform/BadVersionUnsupported.cmake | 1 + .../RunCMake/GeneratorPlatform/RunCMakeTest.cmake | 12 ++-- 16 files changed, 93 insertions(+), 61 deletions(-) delete mode 100644 Tests/RunCMake/GeneratorPlatform/BadVersionPlatform-result.txt delete mode 100644 Tests/RunCMake/GeneratorPlatform/BadVersionPlatform-stderr.txt delete mode 100644 Tests/RunCMake/GeneratorPlatform/BadVersionPlatform.cmake create mode 100644 Tests/RunCMake/GeneratorPlatform/BadVersionPre2019-result.txt create mode 100644 Tests/RunCMake/GeneratorPlatform/BadVersionPre2019-stderr.txt create mode 100644 Tests/RunCMake/GeneratorPlatform/BadVersionPre2019.cmake create mode 100644 Tests/RunCMake/GeneratorPlatform/BadVersionUnsupported-result.txt create mode 100644 Tests/RunCMake/GeneratorPlatform/BadVersionUnsupported-stderr.txt create mode 100644 Tests/RunCMake/GeneratorPlatform/BadVersionUnsupported.cmake diff --git a/Help/variable/CMAKE_GENERATOR_PLATFORM.rst b/Help/variable/CMAKE_GENERATOR_PLATFORM.rst index 416ff60..7fbf6ba 100644 --- a/Help/variable/CMAKE_GENERATOR_PLATFORM.rst +++ b/Help/variable/CMAKE_GENERATOR_PLATFORM.rst @@ -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. diff --git a/Source/cmGlobalVisualStudio10Generator.cxx b/Source/cmGlobalVisualStudio10Generator.cxx index 321f377..35227db 100644 --- a/Source/cmGlobalVisualStudio10Generator.cxx +++ b/Source/cmGlobalVisualStudio10Generator.cxx @@ -544,7 +544,7 @@ bool cmGlobalVisualStudio10Generator::InitializePlatformWindows(cmMakefile*) } bool cmGlobalVisualStudio10Generator::VerifyNoGeneratorPlatformVersion( - cmMakefile*, cm::optional) const + cmMakefile*) const { return true; } diff --git a/Source/cmGlobalVisualStudio10Generator.h b/Source/cmGlobalVisualStudio10Generator.h index 38942cb..40bdd71 100644 --- a/Source/cmGlobalVisualStudio10Generator.h +++ b/Source/cmGlobalVisualStudio10Generator.h @@ -187,8 +187,7 @@ protected: bool InitializePlatform(cmMakefile* mf) override; virtual bool InitializePlatformWindows(cmMakefile* mf); - virtual bool VerifyNoGeneratorPlatformVersion( - cmMakefile* mf, cm::optional reason = cm::nullopt) const; + virtual bool VerifyNoGeneratorPlatformVersion(cmMakefile* mf) const; virtual bool ProcessGeneratorToolsetField(std::string const& key, std::string const& value); diff --git a/Source/cmGlobalVisualStudio14Generator.cxx b/Source/cmGlobalVisualStudio14Generator.cxx index e74c211..8e8062c 100644 --- a/Source/cmGlobalVisualStudio14Generator.cxx +++ b/Source/cmGlobalVisualStudio14Generator.cxx @@ -6,6 +6,7 @@ #include #include +#include #include "cmGlobalGenerator.h" #include "cmGlobalGeneratorFactory.h" @@ -140,6 +141,57 @@ bool cmGlobalVisualStudio14Generator::MatchesGeneratorName( bool cmGlobalVisualStudio14Generator::InitializePlatformWindows(cmMakefile* mf) { + // 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.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. @@ -153,15 +205,12 @@ bool cmGlobalVisualStudio14Generator::InitializePlatformWindows(cmMakefile* mf) 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 this->VerifyNoGeneratorPlatformVersion(mf); + return true; } bool cmGlobalVisualStudio14Generator::VerifyNoGeneratorPlatformVersion( - cmMakefile* mf, cm::optional reason) const + cmMakefile* mf) const { if (!this->GeneratorPlatformVersion) { return true; @@ -177,9 +226,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; } @@ -221,16 +267,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); @@ -376,16 +412,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 win10Roots; { diff --git a/Source/cmGlobalVisualStudio14Generator.h b/Source/cmGlobalVisualStudio14Generator.h index d8a5230..e903578 100644 --- a/Source/cmGlobalVisualStudio14Generator.h +++ b/Source/cmGlobalVisualStudio14Generator.h @@ -43,9 +43,7 @@ protected: virtual bool IsWin81SDKInstalled() const; bool InitializePlatformWindows(cmMakefile* mf) override; - bool VerifyNoGeneratorPlatformVersion( - cmMakefile* mf, - cm::optional reason = cm::nullopt) const override; + bool VerifyNoGeneratorPlatformVersion(cmMakefile* mf) const override; bool ProcessGeneratorPlatformField(std::string const& key, std::string const& value) override; diff --git a/Tests/RunCMake/GeneratorPlatform/BadVersionMissing-stderr.txt b/Tests/RunCMake/GeneratorPlatform/BadVersionMissing-stderr.txt index d82eb0b..41e94f3 100644 --- a/Tests/RunCMake/GeneratorPlatform/BadVersionMissing-stderr.txt +++ b/Tests/RunCMake/GeneratorPlatform/BadVersionMissing-stderr.txt @@ -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\.$ diff --git a/Tests/RunCMake/GeneratorPlatform/BadVersionPlatform-result.txt b/Tests/RunCMake/GeneratorPlatform/BadVersionPlatform-result.txt deleted file mode 100644 index d00491f..0000000 --- a/Tests/RunCMake/GeneratorPlatform/BadVersionPlatform-result.txt +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/Tests/RunCMake/GeneratorPlatform/BadVersionPlatform-stderr.txt b/Tests/RunCMake/GeneratorPlatform/BadVersionPlatform-stderr.txt deleted file mode 100644 index d3c62e3..0000000 --- a/Tests/RunCMake/GeneratorPlatform/BadVersionPlatform-stderr.txt +++ /dev/null @@ -1,19 +0,0 @@ -^CMake Error at CMakeLists.txt:[0-9]+ \(project\): - Generator - - Visual Studio [^ -]+ - - given platform specification (containing a - - version=8\.1 - - field\. The version field is not supported when targeting - - Windows 8\.1( - - with the Windows 8\.1 SDK installed\.)?|with - - version=8\.1 - - field, but no Windows SDK with that version was found\.)$ diff --git a/Tests/RunCMake/GeneratorPlatform/BadVersionPlatform.cmake b/Tests/RunCMake/GeneratorPlatform/BadVersionPlatform.cmake deleted file mode 100644 index 2fc38e5..0000000 --- a/Tests/RunCMake/GeneratorPlatform/BadVersionPlatform.cmake +++ /dev/null @@ -1 +0,0 @@ -message(FATAL_ERROR "This should not be reached!") diff --git a/Tests/RunCMake/GeneratorPlatform/BadVersionPre2019-result.txt b/Tests/RunCMake/GeneratorPlatform/BadVersionPre2019-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/GeneratorPlatform/BadVersionPre2019-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorPlatform/BadVersionPre2019-stderr.txt b/Tests/RunCMake/GeneratorPlatform/BadVersionPre2019-stderr.txt new file mode 100644 index 0000000..649b89d --- /dev/null +++ b/Tests/RunCMake/GeneratorPlatform/BadVersionPre2019-stderr.txt @@ -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\.$ diff --git a/Tests/RunCMake/GeneratorPlatform/BadVersionPre2019.cmake b/Tests/RunCMake/GeneratorPlatform/BadVersionPre2019.cmake new file mode 100644 index 0000000..2fc38e5 --- /dev/null +++ b/Tests/RunCMake/GeneratorPlatform/BadVersionPre2019.cmake @@ -0,0 +1 @@ +message(FATAL_ERROR "This should not be reached!") diff --git a/Tests/RunCMake/GeneratorPlatform/BadVersionUnsupported-result.txt b/Tests/RunCMake/GeneratorPlatform/BadVersionUnsupported-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/GeneratorPlatform/BadVersionUnsupported-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorPlatform/BadVersionUnsupported-stderr.txt b/Tests/RunCMake/GeneratorPlatform/BadVersionUnsupported-stderr.txt new file mode 100644 index 0000000..c165267 --- /dev/null +++ b/Tests/RunCMake/GeneratorPlatform/BadVersionUnsupported-stderr.txt @@ -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\.$ diff --git a/Tests/RunCMake/GeneratorPlatform/BadVersionUnsupported.cmake b/Tests/RunCMake/GeneratorPlatform/BadVersionUnsupported.cmake new file mode 100644 index 0000000..2fc38e5 --- /dev/null +++ b/Tests/RunCMake/GeneratorPlatform/BadVersionUnsupported.cmake @@ -0,0 +1 @@ +message(FATAL_ERROR "This should not be reached!") diff --git a/Tests/RunCMake/GeneratorPlatform/RunCMakeTest.cmake b/Tests/RunCMake/GeneratorPlatform/RunCMakeTest.cmake index 9718ca9..5c1689a 100644 --- a/Tests/RunCMake/GeneratorPlatform/RunCMakeTest.cmake +++ b/Tests/RunCMake/GeneratorPlatform/RunCMakeTest.cmake @@ -36,12 +36,16 @@ if("${RunCMake_GENERATOR}" MATCHES "^Visual Studio (1[4567])( 20[0-9][0-9])?$") run_cmake(BadFieldUnknown) set(RunCMake_GENERATOR_PLATFORM "version=") run_cmake(BadVersionEmpty) - set(RunCMake_GENERATOR_PLATFORM "version=1.2.3.4") + set(RunCMake_GENERATOR_PLATFORM "version=10.0.0.0") run_cmake(BadVersionMissing) - set(RunCMake_GENERATOR_PLATFORM "version=8.1") - run_cmake_with_options(BadVersionPlatform -DCMAKE_SYSTEM_VERSION=8.1) + set(RunCMake_GENERATOR_PLATFORM "version=1.2.3.4") + run_cmake(BadVersionUnsupported) - if(NOT RunCMake_GENERATOR MATCHES "^Visual Studio (1[45]) ") + if(RunCMake_GENERATOR MATCHES "^Visual Studio (1[45]) ") + set(RunCMake_GENERATOR_PLATFORM "version=10.0") + run_cmake(BadVersionPre2019) + unset(RunCMake_GENERATOR_PLATFORM) + else() set(expect_version "10.0") set(RunCMake_GENERATOR_PLATFORM "version=${expect_version}") set(RunCMake_TEST_VARIANT_DESCRIPTION "-${expect_version}") -- cgit v0.12 From ae97d82e830c6ddc81808e3f44dad8a47a30bcae Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 8 Aug 2023 14:20:43 -0400 Subject: VS: Teach CMAKE_GENERATOR_PLATFORM to support Windows 8.1 SDK selection Honor an explicit `version=8.1` field value regardless of the Windows target version. Issue: #25170 --- Help/release/3.27.rst | 8 ++++++++ Help/variable/CMAKE_GENERATOR_PLATFORM.rst | 4 ++++ Source/cmGlobalVisualStudio14Generator.cxx | 17 +++++++++++++++++ Tests/RunCMake/GeneratorPlatform/RunCMakeTest.cmake | 11 +++++++++++ 4 files changed, 40 insertions(+) diff --git a/Help/release/3.27.rst b/Help/release/3.27.rst index a8218ba..9b9db83 100644 --- a/Help/release/3.27.rst +++ b/Help/release/3.27.rst @@ -271,3 +271,11 @@ 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 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. diff --git a/Help/variable/CMAKE_GENERATOR_PLATFORM.rst b/Help/variable/CMAKE_GENERATOR_PLATFORM.rst index 7fbf6ba..22bf655 100644 --- a/Help/variable/CMAKE_GENERATOR_PLATFORM.rst +++ b/Help/variable/CMAKE_GENERATOR_PLATFORM.rst @@ -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. diff --git a/Source/cmGlobalVisualStudio14Generator.cxx b/Source/cmGlobalVisualStudio14Generator.cxx index 8e8062c..506a12a 100644 --- a/Source/cmGlobalVisualStudio14Generator.cxx +++ b/Source/cmGlobalVisualStudio14Generator.cxx @@ -167,6 +167,23 @@ bool cmGlobalVisualStudio14Generator::InitializePlatformWindows(cmMakefile* mf) 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( diff --git a/Tests/RunCMake/GeneratorPlatform/RunCMakeTest.cmake b/Tests/RunCMake/GeneratorPlatform/RunCMakeTest.cmake index 5c1689a..7620b13 100644 --- a/Tests/RunCMake/GeneratorPlatform/RunCMakeTest.cmake +++ b/Tests/RunCMake/GeneratorPlatform/RunCMakeTest.cmake @@ -65,6 +65,16 @@ if("${RunCMake_GENERATOR}" MATCHES "^Visual Studio (1[4567])( 20[0-9][0-9])?$") file(GLOB kits RELATIVE "${kitsInclude}" "${kitsInclude}/*/um/windows.h") list(TRANSFORM kits REPLACE "/.*" "") endif() + cmake_host_system_information(RESULT kitsRoot81 + QUERY WINDOWS_REGISTRY "HKLM/SOFTWARE/Microsoft/Windows Kits/Installed Roots" + VALUE "KitsRoot81" + VIEW 64_32 + ERROR_VARIABLE kitsRoot81Error + ) + if(NOT kitsRoot81Error AND EXISTS "${kitsRoot81}/include/um/windows.h") + list(PREPEND kits "8.1") + endif() + if(kits) message(STATUS "Available Kits: ${kits}") if(RunCMake_GENERATOR MATCHES "^Visual Studio 14 ") @@ -93,6 +103,7 @@ if("${RunCMake_GENERATOR}" MATCHES "^Visual Studio (1[4567])( 20[0-9][0-9])?$") run_cmake_with_options(VersionExists -DCMAKE_SYSTEM_VERSION=10.0) unset(RunCMake_GENERATOR_PLATFORM) endforeach() + list(REMOVE_ITEM kits 8.1) foreach(expect_version IN LISTS kits) set(RunCMake_TEST_VARIANT_DESCRIPTION "-CMP0149-OLD-${expect_version}") run_cmake_with_options(VersionExists -DCMAKE_SYSTEM_VERSION=${expect_version} -DCMAKE_POLICY_DEFAULT_CMP0149=OLD) -- cgit v0.12 From 89b611ab3232cdeb4892458bf9d6c3281a8fda00 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 8 Aug 2023 16:43:14 -0400 Subject: VS: Select latest Windows SDK even when targeting Windows 8.1 and below The policy added by commit f90c8ab54e (VS: Select latest available Windows SDK version by default, 2023-04-03, v3.27.0-rc1~206^2~1) applied only when targeting Windows 10+. Apply it to older versions too. Fixes: #25170 Issue: #16202 --- Help/release/3.27.rst | 5 +++++ Source/cmGlobalVisualStudio14Generator.cxx | 10 ++++++++++ Tests/RunCMake/GeneratorPlatform/RunCMakeTest.cmake | 2 +- Tests/RunCMake/GeneratorPlatform/VersionExists-check.cmake | 12 ++++++++---- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Help/release/3.27.rst b/Help/release/3.27.rst index 9b9db83..457b48c 100644 --- a/Help/release/3.27.rst +++ b/Help/release/3.27.rst @@ -275,6 +275,11 @@ Changes made since CMake 3.27.0 include the following. 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 diff --git a/Source/cmGlobalVisualStudio14Generator.cxx b/Source/cmGlobalVisualStudio14Generator.cxx index 506a12a..01294dd 100644 --- a/Source/cmGlobalVisualStudio14Generator.cxx +++ b/Source/cmGlobalVisualStudio14Generator.cxx @@ -217,6 +217,16 @@ bool cmGlobalVisualStudio14Generator::InitializePlatformWindows(cmMakefile* mf) return this->SelectWindows10SDK(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 && diff --git a/Tests/RunCMake/GeneratorPlatform/RunCMakeTest.cmake b/Tests/RunCMake/GeneratorPlatform/RunCMakeTest.cmake index 7620b13..d8965f7 100644 --- a/Tests/RunCMake/GeneratorPlatform/RunCMakeTest.cmake +++ b/Tests/RunCMake/GeneratorPlatform/RunCMakeTest.cmake @@ -103,7 +103,6 @@ if("${RunCMake_GENERATOR}" MATCHES "^Visual Studio (1[4567])( 20[0-9][0-9])?$") run_cmake_with_options(VersionExists -DCMAKE_SYSTEM_VERSION=10.0) unset(RunCMake_GENERATOR_PLATFORM) endforeach() - list(REMOVE_ITEM kits 8.1) foreach(expect_version IN LISTS kits) set(RunCMake_TEST_VARIANT_DESCRIPTION "-CMP0149-OLD-${expect_version}") run_cmake_with_options(VersionExists -DCMAKE_SYSTEM_VERSION=${expect_version} -DCMAKE_POLICY_DEFAULT_CMP0149=OLD) @@ -115,6 +114,7 @@ if("${RunCMake_GENERATOR}" MATCHES "^Visual Studio (1[4567])( 20[0-9][0-9])?$") run_cmake_with_options(VersionExists -DCMAKE_SYSTEM_VERSION=${test_version} -DCMAKE_POLICY_DEFAULT_CMP0149=NEW) endforeach() endif() + list(REMOVE_ITEM kits 8.1) foreach(expect_version IN LISTS kits) set(RunCMake_TEST_VARIANT_DESCRIPTION "-WindowsSDKVersion-${expect_version}") set(ENV{WindowsSDKVersion} "${expect_version}\\") diff --git a/Tests/RunCMake/GeneratorPlatform/VersionExists-check.cmake b/Tests/RunCMake/GeneratorPlatform/VersionExists-check.cmake index 6c3c8e5..62fb278 100644 --- a/Tests/RunCMake/GeneratorPlatform/VersionExists-check.cmake +++ b/Tests/RunCMake/GeneratorPlatform/VersionExists-check.cmake @@ -1,9 +1,13 @@ if(actual_stdout MATCHES "CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION='([^']+)'") set(actual_version "${CMAKE_MATCH_1}") - if(NOT "${actual_version}" STREQUAL "${expect_version}") - set(RunCMake_TEST_FAILED "Actual SDK version '${actual_version}' did not match expected '${expect_version}'") - return() - endif() +elseif(actual_stdout MATCHES "CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION=''" AND RunCMake_GENERATOR MATCHES "Visual Studio 1[45] ") + set(actual_version "8.1") else() set(RunCMake_TEST_FAILED "No CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION found in output.") + return() +endif() + +if(NOT "${actual_version}" STREQUAL "${expect_version}") + set(RunCMake_TEST_FAILED "Actual SDK version '${actual_version}' did not match expected '${expect_version}'") + return() endif() -- cgit v0.12