VS: Unable to choose 8.1 SDK version in VS 15
It seems like it's currently impossible to make CMake use the Windows 8.1 SDK when building on a Windows 10 host system with VS14 or above.
I tried forcing CMake to use the 8.1 SDK by doing
if (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows")
set (CMAKE_SYSTEM_VERSION 8.1 CACHE TYPE INTERNAL FORCE) #Force 8.1 SDK, to keep it compatible with win7
endif()
I tried 6.3
, 7
, 8
, 8.1
values and each one always chose the latest installed SDK version being 10.0.17763.0
The code cmGlobalVisualStudio14Generator::GetWindows10SDKVersion
only checks for windows 10 SDK versions.
The code compares the version here
https://gitlab.kitware.com/cmake/cmake/blob/master/Source/cmGlobalVisualStudio14Generator.cxx#L313
And correctly has "8.1" in the this->SystemVersion
but because the windows 8.1 SDK is not inside sdks
it will never be checked and it will fallback to the latest SDK on L320.
If I just cheat and insert a sdks.emplace_back("8.1");
in L307, then it correctly creates a vcxproj with Windows SDK version set to 8.1 exactly like I need.
I have also tried to do
set(CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION "8.1")
and
set (CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION 8.1 CACHE TYPE INTERNAL FORCE)
before/after the project()
definition, and also at the far end of my CMakeList.
This caused no effect (project is built with 10.0.17763.0
SDK).
I need to build applications that have to be backwards compatible till windows 7, the latest windows 10 SDK however links the dll/executable against functions in windows libraries that simply don't exist on win 7/8.
Seems like I'm not alone with that problem. https://social.msdn.microsoft.com/Forums/en-US/fcbf7b3f-9548-47ea-bb38-03d10eb6bfbb/how-to-select-the-windows-sdk-81-when-using-cmake-in-visual-studio-2017?forum=visualstudiogeneral