Skip to content

Commit f9b1603

Browse files
fgiancane8bradking
andauthored
Update FindVulkan.cmake to cross-compile for Windows/Windows on ARM64 (KhronosGroup#1490)
* Remove vendored downstream version of `FindVulkan.cmake` Let CMake use its own bundled version of this module. It is more maintained and has some quality of life fixed, most notably cross-compilation on Windows(ARM64/Intel). See KhronosGroup#1489 for more context about this change. * bldsys/toolchain: introduce `ios.cmake` toolchain file As per upstream CMake recommendations, configure iOS targets using a toolchain file. * build.yml: update workflow for iOS CI to use ios toolchain file Move all the variables that were passed through command line here, as per CMake upstream recommendation. * app/CMakeLists.txt: compute `Vulkan_Target_SDK` Removing downstream vendored version of `FindVulkan.cmake` caused this variable to disappear. Compute it again where it is needed. KhronosGroup#1490 (comment) for the full discussion. * Revert "Remove vendored downstream version of `FindVulkan.cmake`" This reverts commit 1a672f7. * Revert "bldsys/toolchain: introduce `ios.cmake` toolchain file" This reverts commit 6f1680f. * Revert "build.yml: update workflow for iOS CI to use ios toolchain file" This reverts commit 265d313. * 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> * Fix wrong copyright years. Add license attributions for my changes. * app/CMakeLists.txt: restore file to its original content Changes are addressed in KhronosGroup#1500. * bldsys/cmake/module/FindVulkan.cmake: restore if(APPLE) branch As per request on the discussion thread, let's just import the changes required to build Vulkan Samples on Windows/Windows on ARM64. --------- Co-authored-by: Brad King <brad.king@kitware.com>
1 parent b8189a6 commit f9b1603

1 file changed

Lines changed: 45 additions & 27 deletions

File tree

bldsys/cmake/module/FindVulkan.cmake

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# Updates for iOS Copyright (c) 2024, Holochip Inc.
1+
# Updates for iOS Copyright (c) 2024-2026, Holochip Inc.
2+
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
23
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
34
# file Copyright.txt or https://cmake.org/licensing for details.
45

@@ -263,40 +264,57 @@ endif()
263264

264265
if(WIN32)
265266
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()
289267
else()
290268
set(_Vulkan_library_name vulkan)
269+
endif()
270+
set(_Vulkan_hint_include_search_paths "")
271+
set(_Vulkan_hint_executable_search_paths "")
272+
set(_Vulkan_hint_library_search_paths "")
273+
274+
if(DEFINED ENV{VULKAN_SDK} AND IS_DIRECTORY "$ENV{VULKAN_SDK}")
291275
set(_Vulkan_hint_include_search_paths
292-
"$ENV{VULKAN_SDK}/include"
276+
"$ENV{VULKAN_SDK}/include"
293277
)
294278
set(_Vulkan_hint_executable_search_paths
295-
"$ENV{VULKAN_SDK}/bin"
279+
"$ENV{VULKAN_SDK}/bin"
296280
)
281+
if(WIN32)
282+
# Detect the target architecture from one of:
283+
# - the C++ compiler,
284+
# - the C compiler,
285+
# - the VS generator,
286+
# - the command-line environment,
287+
# - fallback to CMAKE_SYSTEM_PROCESSOR.
288+
if(CMAKE_CXX_COMPILER_LOADED AND CMAKE_CXX_COMPILER_ARCHITECTURE_ID)
289+
set(_Vulkan_arch_name "${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}")
290+
elseif(CMAKE_C_COMPILER_LOADED AND CMAKE_C_COMPILER_ARCHITECTURE_ID)
291+
set(_Vulkan_arch_name "${CMAKE_C_COMPILER_ARCHITECTURE_ID}")
292+
elseif(CMAKE_VS_PLATFORM_NAME)
293+
set(_Vulkan_arch_name "${CMAKE_VS_PLATFORM_NAME}")
294+
elseif(DEFINED ENV{VSCMD_ARG_TGT_ARCH})
295+
set(_Vulkan_arch_name "$ENV{VSCMD_ARG_TGT_ARCH}")
296+
elseif(CMAKE_SYSTEM_PROCESSOR)
297+
set(_Vulkan_arch_name "${CMAKE_SYSTEM_PROCESSOR}")
298+
endif()
299+
# The Vulkan SDK may provide arch-specific directories for cross-compiling.
300+
if(_Vulkan_arch_name MATCHES "^(ARM64|arm64|aarch64)" AND IS_DIRECTORY "$ENV{VULKAN_SDK}/lib-arm64")
301+
# On X64 hosts the Vulkan SDK provides `-arm64` dirs for cross-compiling to ARM64.
302+
set(_Vulkan_arch_suffix "-arm64")
303+
elseif(_Vulkan_arch_name MATCHES "^(X64|x64|x86_64)" AND IS_DIRECTORY "$ENV{VULKAN_SDK}/lib-x64")
304+
# On ARM64 hosts the Vulkan SDK provides `-x64` dirs for cross-compiling to x64.
305+
set(_Vulkan_arch_suffix "-x64")
306+
else()
307+
# Otherwise assume we are compiling for the host.
308+
set(_Vulkan_arch_suffix "")
309+
endif()
310+
unset(_Vulkan_arch_name)
311+
else()
312+
set(_Vulkan_arch_suffix "")
313+
endif()
297314
set(_Vulkan_hint_library_search_paths
298-
"$ENV{VULKAN_SDK}/lib"
315+
"$ENV{VULKAN_SDK}/lib${_Vulkan_arch_suffix}"
299316
)
317+
unset(_Vulkan_arch_suffix)
300318
endif()
301319
if(APPLE AND DEFINED Vulkan_Target_SDK)
302320
list(APPEND _Vulkan_hint_include_search_paths

0 commit comments

Comments
 (0)