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.
This commit is contained in:
Brad King 2023-08-08 13:31:31 -04:00
parent 209973e510
commit bba1a23da9
4 changed files with 23 additions and 24 deletions

View File

@ -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
{

View File

@ -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,

View File

@ -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
{

View File

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