@@ -3,6 +3,39 @@ cmake_policy(SET CMP0114 NEW)
3
3
4
4
find_package (Vulkan COMPONENTS glslc REQUIRED )
5
5
6
+ function (detect_host_compiler )
7
+ if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows" )
8
+ find_program (MSVC_COMPILER cl )
9
+ find_program (GNU_C_COMPILER gcc )
10
+ find_program (GNU_CXX_COMPILER g++ )
11
+ if (MSVC_COMPILER )
12
+ set (HOST_C_COMPILER "${MSVC_COMPILER} " PARENT_SCOPE )
13
+ set (HOST_CXX_COMPILER "${MSVC_COMPILER} " PARENT_SCOPE )
14
+ elseif (CLANG_C_COMPILER AND CLANG_CXX_COMPILER )
15
+ set (HOST_C_COMPILER "${CLANG_C_COMPILER} " PARENT_SCOPE )
16
+ set (HOST_CXX_COMPILER "${CLANG_CXX_COMPILER} " PARENT_SCOPE )
17
+ else ()
18
+ message (WARNING "Neither MSVC nor clang found" )
19
+ endif ()
20
+ elseif (CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" )
21
+ find_program (CLANG_C_COMPILER clang )
22
+ find_program (CLANG_CXX_COMPILER clang++ )
23
+ find_program (GNU_C_COMPILER gcc )
24
+ find_program (GNU_CXX_COMPILER g++ )
25
+ if (GNU_C_COMPILER AND GNU_CXX_COMPILER )
26
+ set (HOST_C_COMPILER "${GNU_C_COMPILER} " PARENT_SCOPE )
27
+ set (HOST_CXX_COMPILER "${GNU_CXX_COMPILER} " PARENT_SCOPE )
28
+ elseif (CLANG_C_COMPILER AND CLANG_CXX_COMPILER )
29
+ set (HOST_C_COMPILER "${CLANG_C_COMPILER} " PARENT_SCOPE )
30
+ set (HOST_CXX_COMPILER "${CLANG_CXX_COMPILER} " PARENT_SCOPE )
31
+ else ()
32
+ message (WARNING "Neither clang nor gcc found" )
33
+ endif ()
34
+ else ()
35
+ message (WARNING "Unsupported host system: ${CMAKE_HOST_SYSTEM_NAME} " )
36
+ endif ()
37
+ endfunction ()
38
+
6
39
if (Vulkan_FOUND )
7
40
message (STATUS "Vulkan found" )
8
41
@@ -51,22 +84,36 @@ if (Vulkan_FOUND)
51
84
if (NOT CMAKE_CROSSCOMPILING )
52
85
add_subdirectory (vulkan-shaders )
53
86
else ()
87
+ if (GGML_SHADERS_GEN_TOOLCHAIN )
88
+ set (HOST_CMAKE_TOOLCHAIN_FILE ${GGML_SHADERS_GEN_TOOLCHAIN} )
89
+ else ()
90
+ detect_host_compiler ()
91
+ if (NOT HOST_C_COMPILER OR NOT HOST_CXX_COMPILER )
92
+ message (FATAL_ERROR "Host compiler not found" )
93
+ else ()
94
+ message (STATUS "Host compiler: ${HOST_C_COMPILER} ${HOST_CXX_COMPILER} " )
95
+ endif ()
96
+ file (WRITE ${CMAKE_BINARY_DIR} /host_toolchain.cmake
97
+ "set(CMAKE_BUILD_TYPE Release)\n "
98
+ "set(CMAKE_C_FLAGS -O2)\n "
99
+ "set(CMAKE_CXX_FLAGS -O2)\n "
100
+ "set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)\n "
101
+ "set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)\n "
102
+ "set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)\n "
103
+ "set(CMAKE_C_COMPILER ${HOST_C_COMPILER} )\n "
104
+ "set(CMAKE_CXX_COMPILER ${HOST_CXX_COMPILER} )\n "
105
+ )
106
+ set (HOST_CMAKE_TOOLCHAIN_FILE ${CMAKE_BINARY_DIR} /host_toolchain.cmake )
107
+ endif ()
108
+ message (STATUS "vulkan-shaders-gen toolchain file: ${HOST_CMAKE_TOOLCHAIN_FILE} " )
109
+
54
110
include (ExternalProject )
55
111
# Native build through ExternalProject_Add
56
112
ExternalProject_Add (
57
113
vulkan-shaders-gen
58
114
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} /vulkan-shaders
59
- CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release
115
+ CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${HOST_CMAKE_TOOLCHAIN_FILE}
60
116
-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}
61
- -DCMAKE_TOOLCHAIN_FILE=
62
- -DCMAKE_SYSROOT=
63
- -DCMAKE_C_FLAGS=-O2
64
- -DCMAKE_CXX_FLAGS=-O2
65
- -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER
66
- -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=NEVER
67
- -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=NEVER
68
- -DCMAKE_C_COMPILER=gcc
69
- -DCMAKE_CXX_COMPILER=g++
70
117
BUILD_COMMAND ${CMAKE_COMMAND} --build .
71
118
INSTALL_COMMAND ${CMAKE_COMMAND} --install .
72
119
INSTALL_DIR ${CMAKE_BINARY_DIR}
0 commit comments