@@ -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
@@ -65,22 +98,36 @@ if (Vulkan_FOUND)
65
98
if (NOT CMAKE_CROSSCOMPILING )
66
99
add_subdirectory (vulkan-shaders )
67
100
else ()
101
+ if (GGML_SHADERS_GEN_TOOLCHAIN )
102
+ set (HOST_CMAKE_TOOLCHAIN_FILE ${GGML_SHADERS_GEN_TOOLCHAIN} )
103
+ else ()
104
+ detect_host_compiler ()
105
+ if (NOT HOST_C_COMPILER OR NOT HOST_CXX_COMPILER )
106
+ message (FATAL_ERROR "Host compiler not found" )
107
+ else ()
108
+ message (STATUS "Host compiler: ${HOST_C_COMPILER} ${HOST_CXX_COMPILER} " )
109
+ endif ()
110
+ file (WRITE ${CMAKE_BINARY_DIR} /host_toolchain.cmake
111
+ "set(CMAKE_BUILD_TYPE Release)\n "
112
+ "set(CMAKE_C_FLAGS -O2)\n "
113
+ "set(CMAKE_CXX_FLAGS -O2)\n "
114
+ "set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)\n "
115
+ "set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)\n "
116
+ "set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)\n "
117
+ "set(CMAKE_C_COMPILER ${HOST_C_COMPILER} )\n "
118
+ "set(CMAKE_CXX_COMPILER ${HOST_CXX_COMPILER} )\n "
119
+ )
120
+ set (HOST_CMAKE_TOOLCHAIN_FILE ${CMAKE_BINARY_DIR} /host_toolchain.cmake )
121
+ endif ()
122
+ message (STATUS "vulkan-shaders-gen toolchain file: ${HOST_CMAKE_TOOLCHAIN_FILE} " )
123
+
68
124
include (ExternalProject )
69
125
# Native build through ExternalProject_Add
70
126
ExternalProject_Add (
71
127
vulkan-shaders-gen
72
128
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} /vulkan-shaders
73
- CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release
129
+ CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${HOST_CMAKE_TOOLCHAIN_FILE}
74
130
-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}
75
- -DCMAKE_TOOLCHAIN_FILE=
76
- -DCMAKE_SYSROOT=
77
- -DCMAKE_C_FLAGS=-O2
78
- -DCMAKE_CXX_FLAGS=-O2
79
- -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER
80
- -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=NEVER
81
- -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=NEVER
82
- -DCMAKE_C_COMPILER=gcc
83
- -DCMAKE_CXX_COMPILER=g++
84
131
BUILD_COMMAND ${CMAKE_COMMAND} --build .
85
132
INSTALL_COMMAND ${CMAKE_COMMAND} --install .
86
133
INSTALL_DIR ${CMAKE_BINARY_DIR}
0 commit comments