fix: improve host compiler detection in vulkan shader build

Improve host compiler detection for vulkan shader generation:
- Add NO_CMAKE_FIND_ROOT_PATH to all compiler searches
- Consolidate compiler detection logic
- Fix Windows-specific MSVC detection
- Ensure correct compiler search in cross-compilation
This commit is contained in:
Junil Kim 2025-01-12 11:22:58 +09:00
parent 481d57f7c7
commit 46b4c8da44

View file

@ -4,33 +4,28 @@ cmake_policy(SET CMP0114 NEW)
find_package(Vulkan COMPONENTS glslc REQUIRED)
function(detect_host_compiler)
find_program(GNU_C_COMPILER gcc NO_CMAKE_FIND_ROOT_PATH)
find_program(GNU_CXX_COMPILER g++ NO_CMAKE_FIND_ROOT_PATH)
find_program(CLANG_C_COMPILER clang NO_CMAKE_FIND_ROOT_PATH)
find_program(CLANG_CXX_COMPILER clang++ NO_CMAKE_FIND_ROOT_PATH)
if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
find_program(MSVC_COMPILER cl)
find_program(GNU_C_COMPILER gcc)
find_program(GNU_CXX_COMPILER g++)
find_program(MSVC_COMPILER cl NO_CMAKE_FIND_ROOT_PATH)
if (MSVC_COMPILER)
set(HOST_C_COMPILER "${MSVC_COMPILER}" PARENT_SCOPE)
set(HOST_CXX_COMPILER "${MSVC_COMPILER}" PARENT_SCOPE)
elseif (CLANG_C_COMPILER AND CLANG_CXX_COMPILER)
set(HOST_C_COMPILER "${CLANG_C_COMPILER}" PARENT_SCOPE)
set(HOST_CXX_COMPILER "${CLANG_CXX_COMPILER}" PARENT_SCOPE)
else()
message(WARNING "Neither MSVC nor clang found")
return()
endif()
endif()
if (GNU_C_COMPILER AND GNU_CXX_COMPILER)
set(HOST_C_COMPILER "${GNU_C_COMPILER}" PARENT_SCOPE)
set(HOST_CXX_COMPILER "${GNU_CXX_COMPILER}" PARENT_SCOPE)
elseif (CLANG_C_COMPILER AND CLANG_CXX_COMPILER)
set(HOST_C_COMPILER "${CLANG_C_COMPILER}" PARENT_SCOPE)
set(HOST_CXX_COMPILER "${CLANG_CXX_COMPILER}" PARENT_SCOPE)
else()
find_program(CLANG_C_COMPILER clang)
find_program(CLANG_CXX_COMPILER clang++)
find_program(GNU_C_COMPILER gcc)
find_program(GNU_CXX_COMPILER g++)
if (GNU_C_COMPILER AND GNU_CXX_COMPILER)
set(HOST_C_COMPILER "${GNU_C_COMPILER}" PARENT_SCOPE)
set(HOST_CXX_COMPILER "${GNU_CXX_COMPILER}" PARENT_SCOPE)
elseif (CLANG_C_COMPILER AND CLANG_CXX_COMPILER)
set(HOST_C_COMPILER "${CLANG_C_COMPILER}" PARENT_SCOPE)
set(HOST_CXX_COMPILER "${CLANG_CXX_COMPILER}" PARENT_SCOPE)
else()
message(WARNING "Neither clang nor gcc found")
endif()
message(WARNING "No suitable host compiler found")
endif()
endfunction()