From 7c1a6853e59db5c41ab943d3f41019eef837e966 Mon Sep 17 00:00:00 2001 From: Junil Kim Date: Tue, 24 Dec 2024 12:52:04 +0900 Subject: [PATCH] refactor: ggml: Improve vulkan-shaders-gen toolchain setup Use configure_file to generate host_toolchain.cmake from template --- ggml/src/ggml-vulkan/CMakeLists.txt | 15 ++------------- ggml/src/ggml-vulkan/host_toolchain.cmake.in | 8 ++++++++ 2 files changed, 10 insertions(+), 13 deletions(-) create mode 100644 ggml/src/ggml-vulkan/host_toolchain.cmake.in diff --git a/ggml/src/ggml-vulkan/CMakeLists.txt b/ggml/src/ggml-vulkan/CMakeLists.txt index f2e986c12..1f1e5d6ea 100644 --- a/ggml/src/ggml-vulkan/CMakeLists.txt +++ b/ggml/src/ggml-vulkan/CMakeLists.txt @@ -17,7 +17,7 @@ function(detect_host_compiler) else() message(WARNING "Neither MSVC nor clang found") endif() - elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") + else() find_program(CLANG_C_COMPILER clang) find_program(CLANG_CXX_COMPILER clang++) find_program(GNU_C_COMPILER gcc) @@ -31,8 +31,6 @@ function(detect_host_compiler) else() message(WARNING "Neither clang nor gcc found") endif() - else() - message(WARNING "Unsupported host system: ${CMAKE_HOST_SYSTEM_NAME}") endif() endfunction() @@ -107,16 +105,7 @@ if (Vulkan_FOUND) else() message(STATUS "Host compiler: ${HOST_C_COMPILER} ${HOST_CXX_COMPILER}") endif() - file(WRITE ${CMAKE_BINARY_DIR}/host_toolchain.cmake - "set(CMAKE_BUILD_TYPE Release)\n" - "set(CMAKE_C_FLAGS -O2)\n" - "set(CMAKE_CXX_FLAGS -O2)\n" - "set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)\n" - "set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)\n" - "set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)\n" - "set(CMAKE_C_COMPILER ${HOST_C_COMPILER})\n" - "set(CMAKE_CXX_COMPILER ${HOST_CXX_COMPILER})\n" - ) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/host_toolchain.cmake.in ${CMAKE_BINARY_DIR}/host_toolchain.cmake @ONLY) set(HOST_CMAKE_TOOLCHAIN_FILE ${CMAKE_BINARY_DIR}/host_toolchain.cmake) endif() message(STATUS "vulkan-shaders-gen toolchain file: ${HOST_CMAKE_TOOLCHAIN_FILE}") diff --git a/ggml/src/ggml-vulkan/host_toolchain.cmake.in b/ggml/src/ggml-vulkan/host_toolchain.cmake.in new file mode 100644 index 000000000..f4d7480e0 --- /dev/null +++ b/ggml/src/ggml-vulkan/host_toolchain.cmake.in @@ -0,0 +1,8 @@ +set(CMAKE_BUILD_TYPE Release) +set(CMAKE_C_FLAGS -O2) +set(CMAKE_CXX_FLAGS -O2) +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER) +set(CMAKE_C_COMPILER @HOST_C_COMPILER@) +set(CMAKE_CXX_COMPILER @HOST_CXX_COMPILER@)