Feature Request: Support discovering available windows SDK versions prior to enable_language()
I'm working on a project for windows, where the version of the windows sdks that cmake selects by default is known to fail to compile with my project.
I want to set up my top level CMakeLists.txt to search for the available windows sdks, and select the most recent one that is known to work.
I do not want people who are building my project to need to do anything beyond pointing their IDE at the CMakeLists.txt file and clicking compile.
My attempt this far was to use https://github.com/rpavlik/cmake-modules/blob/main/FindWindowsSDK.cmake, and set the sdk version after the language was enabled, but that doesn't work.
IF(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
FIND_PACKAGE(WindowsSDK)
IF(NOT WINDOWSSDK_FOUND)
MESSAGE(FATAL_ERROR "Cannot find the Windows SDK in use. Fix me.")
ENDIF()
IF(WINDOWSSDK_LATEST_NAME VERSION_GREATER_EQUAL "10.0.17763.0")
MESSAGE(FATAL_ERROR "Newest available SDK version is detected as ${WINDOWSSDK_LATEST_NAME}, which is 10.0.17763.0 or older, and known known to not work with C++17. You must install a newer windows kit version.")
ENDIF()
SET(CMAKE_SYSTEM_VERSION ${WINDOWSSDK_LATEST_NAME} CACHE INTERNAL "" FORCE)
MESSAGE("-- Setting Windows SDK version to ${CMAKE_SYSTEM_VERSION}")
ENDIF()
The above hyperlinked cmake module can't be used before the CXX language is enabled because the directories to search aren't populated properly.
This seems to be something that would need to be built into cmake to work properly.