Skip to content

Commit aa16873

Browse files
authored
CMake: fix FindD3D12.cmake when using non-VS generators (microsoft#6056)
FindD3D12.cmake sets WIN10_SDK_VERSION to CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION; however, this latter variable is only defined when using a Visual Studio CMake generator. When using Ninja instead, for example, this variable will be empty, and WIN10_SDK_VERSION will remain unset. This change detects when CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION and attempts to retrieve the latest SDK by listing directories under ${WIN10_SDK_PATH}/Include.
1 parent 5cecea9 commit aa16873

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

cmake/modules/FindD3D12.cmake

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
# Find the Win10 SDK path.
22
if ("$ENV{WIN10_SDK_PATH}$ENV{WIN10_SDK_VERSION}" STREQUAL "" )
33
get_filename_component(WIN10_SDK_PATH "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;KitsRoot10]" ABSOLUTE CACHE)
4-
set (WIN10_SDK_VERSION ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION})
4+
if (CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION)
5+
set (WIN10_SDK_VERSION ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION})
6+
else()
7+
# CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION may not be defined if, for example,
8+
# the Ninja generator is used instead of Visual Studio. Attempt to retrieve the
9+
# most recent SDK version from the list of paths under "${WIN10_SDK_PATH}/Include/".
10+
file(GLOB sdk_dirs RELATIVE "${WIN10_SDK_PATH}/Include/" "${WIN10_SDK_PATH}/Include/10.*")
11+
if (sdk_dirs)
12+
list(POP_BACK sdk_dirs WIN10_SDK_VERSION)
13+
endif()
14+
unset(sdk_dirs)
15+
endif()
516
elseif(TRUE)
617
set (WIN10_SDK_PATH $ENV{WIN10_SDK_PATH})
718
set (WIN10_SDK_VERSION $ENV{WIN10_SDK_VERSION})

0 commit comments

Comments
 (0)