FindVulkan incorrectly finds x64 binaries when cross-building for ARM64 with MSVC
The FindVulkan module contains an assumption that the only two platforms for Windows are x86 and x64, here: https://gitlab.kitware.com/cmake/cmake/-/blob/v3.26.4/Modules/FindVulkan.cmake#L244-268
As such, when running a build on an x64 machine, intending to build binaries for ARM64, it makes incorrect choices. Currently the Vulkan SDK does not include ARM64 or ARM binaries for Windows, so it should exit without finding libraries. (Tools and headers are OK to find, since they are either running on the build machine, or architecture-independent.) However, it is only checking sizeof(void*) and thus the x64 binaries get found, leading to a linker error later for mixing architectures.
The workaround is to avoid calling find_package(Vulkan)
on Windows on ARM builds. However, this is made more complex by #17702 and the related issue that CMAKE_SYSTEM_PROCESSOR
is not usefully set with MSVC (it reports AMD64 when crossbuilding for ARM64)
To reproduce:
- Make or find a project that uses
find_package(Vulkan)
(I initially found it working on https://github.com/KhronosGroup/OpenXR-SDK-Source though I will have a workaround merged soon.) - Make sure you have the Vulkan SDK installed, on an AMD64 windows machine.
- Open a command prompt.
- Run
vcvarsamd64_arm64.bat
(from visual studio, which sets up for running the compiler on amd64 to output binaries for arm64) - Run
cmake -G Ninja -S . -B build
- Observe in
build/CMakeCache.txt
that Vulkan_LIBRARY is set to a value (the file under the SDK namedLib/vulkan-1.lib
- this is the amd64 build), when it should not be. (It should be NOTFOUND, I believe)
(It looks like the only way to get Vulkan binaries for Windows on ARM64 is via msys/mingw using clang? https://packages.msys2.org/package/mingw-w64-clang-aarch64-vulkan-loader?repo=clangarm64 Not sure how useful it is, since I'm not aware of any Vulkan-capable GPU drivers for Windows on ARM even though they should be possible. In any case, that package provides a pkgconfig file vulkan.pc
)