Skip to content

Commit a6ef4f0

Browse files
fgiancane8bradking
andcommitted
bldsys/cmake/module/FindVulkan.cmake: Backport upstream changes
Backport these patches into our downstream `FindVulkan` CMake module: 5e1440302a FindVulkan: Add support for cross-compiling between Windows x64/ARM64 f9a09f76f3 FindVulkan: Drop support for 32-bit SDK on Windows b40740f28a FindVulkan: Do not search bin directories for libraries 947adbba91 FindVulkan: Use ENV{VULKAN_SDK} only if it exists This allows proper libraries discovery of Vulkan Libraries on Windows, both for x86_64 and ARM64 targets. Co-Authored-By: Brad King <brad.king@kitware.com> Tested-By: Giancane, Francesco <fgiancan@qti.qualcomm.com>
1 parent 9c2eb4a commit a6ef4f0

1 file changed

Lines changed: 64 additions & 43 deletions

File tree

bldsys/cmake/module/FindVulkan.cmake

Lines changed: 64 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -263,57 +263,78 @@ endif()
263263

264264
if(WIN32)
265265
set(_Vulkan_library_name vulkan-1)
266-
set(_Vulkan_hint_include_search_paths
267-
"$ENV{VULKAN_SDK}/include"
268-
)
269-
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
270-
set(_Vulkan_hint_executable_search_paths
271-
"$ENV{VULKAN_SDK}/bin"
272-
)
273-
set(_Vulkan_hint_library_search_paths
274-
"$ENV{VULKAN_SDK}/lib"
275-
"$ENV{VULKAN_SDK}/bin"
276-
)
277-
else()
278-
set(_Vulkan_hint_executable_search_paths
279-
"$ENV{VULKAN_SDK}/bin32"
280-
"$ENV{VULKAN_SDK}/bin"
281-
)
282-
set(_Vulkan_hint_library_search_paths
283-
"$ENV{VULKAN_SDK}/lib32"
284-
"$ENV{VULKAN_SDK}/bin32"
285-
"$ENV{VULKAN_SDK}/lib"
286-
"$ENV{VULKAN_SDK}/bin"
287-
)
288-
endif()
289266
else()
290267
set(_Vulkan_library_name vulkan)
268+
endif()
269+
set(_Vulkan_hint_include_search_paths "")
270+
set(_Vulkan_hint_executable_search_paths "")
271+
set(_Vulkan_hint_library_search_paths "")
272+
273+
if(DEFINED ENV{VULKAN_SDK} AND IS_DIRECTORY "$ENV{VULKAN_SDK}")
291274
set(_Vulkan_hint_include_search_paths
292-
"$ENV{VULKAN_SDK}/include"
275+
"$ENV{VULKAN_SDK}/include"
293276
)
294277
set(_Vulkan_hint_executable_search_paths
295-
"$ENV{VULKAN_SDK}/bin"
278+
"$ENV{VULKAN_SDK}/bin"
296279
)
280+
if(WIN32)
281+
# Detect the target architecture from one of:
282+
# - the C++ compiler,
283+
# - the C compiler,
284+
# - the VS generator,
285+
# - the command-line environment,
286+
# - fallback to CMAKE_SYSTEM_PROCESSOR.
287+
if(CMAKE_CXX_COMPILER_LOADED AND CMAKE_CXX_COMPILER_ARCHITECTURE_ID)
288+
set(_Vulkan_arch_name "${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}")
289+
elseif(CMAKE_C_COMPILER_LOADED AND CMAKE_C_COMPILER_ARCHITECTURE_ID)
290+
set(_Vulkan_arch_name "${CMAKE_C_COMPILER_ARCHITECTURE_ID}")
291+
elseif(CMAKE_VS_PLATFORM_NAME)
292+
set(_Vulkan_arch_name "${CMAKE_VS_PLATFORM_NAME}")
293+
elseif(DEFINED ENV{VSCMD_ARG_TGT_ARCH})
294+
set(_Vulkan_arch_name "$ENV{VSCMD_ARG_TGT_ARCH}")
295+
elseif(CMAKE_SYSTEM_PROCESSOR)
296+
set(_Vulkan_arch_name "${CMAKE_SYSTEM_PROCESSOR}")
297+
endif()
298+
# The Vulkan SDK may provide arch-specific directories for cross-compiling.
299+
if(_Vulkan_arch_name MATCHES "^(ARM64|arm64|aarch64)" AND IS_DIRECTORY "$ENV{VULKAN_SDK}/lib-arm64")
300+
# On X64 hosts the Vulkan SDK provides `-arm64` dirs for cross-compiling to ARM64.
301+
set(_Vulkan_arch_suffix "-arm64")
302+
elseif(_Vulkan_arch_name MATCHES "^(X64|x64|x86_64)" AND IS_DIRECTORY "$ENV{VULKAN_SDK}/lib-x64")
303+
# On ARM64 hosts the Vulkan SDK provides `-x64` dirs for cross-compiling to x64.
304+
set(_Vulkan_arch_suffix "-x64")
305+
else()
306+
# Otherwise assume we are compiling for the host.
307+
set(_Vulkan_arch_suffix "")
308+
endif()
309+
unset(_Vulkan_arch_name)
310+
else()
311+
set(_Vulkan_arch_suffix "")
312+
endif()
297313
set(_Vulkan_hint_library_search_paths
298-
"$ENV{VULKAN_SDK}/lib"
299-
)
300-
endif()
301-
if(APPLE AND DEFINED Vulkan_Target_SDK)
302-
list(APPEND _Vulkan_hint_include_search_paths
303-
"${Vulkan_Target_SDK}/macOS/include"
314+
"$ENV{VULKAN_SDK}/lib${_Vulkan_arch_suffix}"
304315
)
305-
if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
306-
list(APPEND _Vulkan_hint_library_search_paths
307-
"${Vulkan_Target_SDK}/iOS/lib"
308-
)
309-
elseif(CMAKE_SYSTEM_NAME STREQUAL "tvOS")
310-
list(APPEND _Vulkan_hint_library_search_paths
311-
"${Vulkan_Target_SDK}/tvOS/lib"
312-
)
313-
else()
314-
list(APPEND _Vulkan_hint_library_search_paths
315-
"${Vulkan_Target_SDK}/lib"
316-
)
316+
unset(_Vulkan_arch_suffix)
317+
if(APPLE)
318+
cmake_path(SET _MoltenVK_path NORMALIZE "$ENV{VULKAN_SDK}/../MoltenVK")
319+
if(IS_DIRECTORY "${_MoltenVK_path}")
320+
list(APPEND _Vulkan_hint_include_search_paths
321+
"${_MoltenVK_path}/include"
322+
)
323+
if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
324+
list(APPEND _Vulkan_hint_library_search_paths
325+
"${_MoltenVK_path}/dylib/iOS"
326+
)
327+
elseif(CMAKE_SYSTEM_NAME STREQUAL "tvOS")
328+
list(APPEND _Vulkan_hint_library_search_paths
329+
"${_MoltenVK_path}/dylib/tvOS"
330+
)
331+
else()
332+
list(APPEND _Vulkan_hint_library_search_paths
333+
"${_MoltenVK_path}/dylib/macOS"
334+
)
335+
endif()
336+
endif()
337+
unset(_MoltenVK_path)
317338
endif()
318339
endif()
319340

0 commit comments

Comments
 (0)