@@ -36,6 +36,23 @@ set(UI_CPP "${CMAKE_CURRENT_BINARY_DIR}/ui.cpp")
3636set (UI_H "${CMAKE_CURRENT_BINARY_DIR } /ui.h" )
3737
3838if (CMAKE_CROSSCOMPILING )
39+ function (llama_check_host_cxx compiler out_var )
40+ set (src "${CMAKE_CURRENT_BINARY_DIR } /host-cxx-check.cpp" )
41+ set (exe "${CMAKE_CURRENT_BINARY_DIR } /host-cxx-check${CMAKE_EXECUTABLE_SUFFIX } " )
42+ file (WRITE "${src} " "#include <stdio.h>\n int main() { puts(\" ok\" ); return 0; }\n " )
43+ execute_process (
44+ COMMAND "${compiler} " -std=c++17 "${src} " -o "${exe} "
45+ RESULT_VARIABLE rc
46+ OUTPUT_QUIET
47+ ERROR_QUIET
48+ )
49+ if (rc EQUAL 0)
50+ set (${out_var} TRUE PARENT_SCOPE )
51+ else ()
52+ set (${out_var} FALSE PARENT_SCOPE )
53+ endif ()
54+ endfunction ()
55+
3956 find_program (HOST_CXX_COMPILER
4057 NAMES c++ g++ clang++
4158 PATHS /usr/local/bin /usr/bin /bin
@@ -44,27 +61,39 @@ if(CMAKE_CROSSCOMPILING)
4461 if (NOT HOST_CXX_COMPILER)
4562 find_program (HOST_CXX_COMPILER NAMES c++ g++ clang++ NO_CMAKE_FIND_ROOT_PATH )
4663 endif ()
47- if (NOT HOST_CXX_COMPILER)
48- message (FATAL_ERROR "UI: no host C++ compiler (g++/clang++) found to build llama-ui-embed; set -DHOST_CXX_COMPILER=<path>" )
64+ if (HOST_CXX_COMPILER)
65+ llama_check_host_cxx ("${HOST_CXX_COMPILER} " HOST_CXX_OK )
66+ if (NOT HOST_CXX_OK)
67+ message (STATUS "UI: ignoring unusable host compiler ${HOST_CXX_COMPILER} " )
68+ unset (HOST_CXX_COMPILER CACHE )
69+ unset (HOST_CXX_COMPILER)
70+ endif ()
4971 endif ()
50- message (STATUS "UI: building llama-ui-embed with host compiler ${HOST_CXX_COMPILER} " )
5172
52- if (CMAKE_HOST_WIN32 )
53- set (LLAMA_UI_EMBED_EXE "${CMAKE_CURRENT_BINARY_DIR } /llama-ui-embed.exe" )
73+ if (HOST_CXX_COMPILER)
74+ message (STATUS "UI: building llama-ui-embed with host compiler ${HOST_CXX_COMPILER} " )
75+
76+ if (CMAKE_HOST_WIN32 )
77+ set (LLAMA_UI_EMBED_EXE "${CMAKE_CURRENT_BINARY_DIR } /llama-ui-embed.exe" )
78+ else ()
79+ set (LLAMA_UI_EMBED_EXE "${CMAKE_CURRENT_BINARY_DIR } /llama-ui-embed" )
80+ endif ()
81+
82+ add_custom_command (
83+ OUTPUT "${LLAMA_UI_EMBED_EXE} "
84+ COMMAND "${HOST_CXX_COMPILER} " -O2 -std=c++17
85+ -o "${LLAMA_UI_EMBED_EXE} " "${CMAKE_CURRENT_SOURCE_DIR } /embed.cpp"
86+ DEPENDS "${CMAKE_CURRENT_SOURCE_DIR } /embed.cpp"
87+ COMMENT "Building llama-ui-embed (host)"
88+ VERBATIM
89+ )
90+ add_custom_target (llama-ui-embed-host DEPENDS "${LLAMA_UI_EMBED_EXE} " )
91+ set (LLAMA_UI_EMBED_TARGET llama-ui-embed-host)
5492 else ()
55- set (LLAMA_UI_EMBED_EXE "${CMAKE_CURRENT_BINARY_DIR } /llama-ui-embed" )
93+ message (STATUS "UI: no usable host C++ compiler, using CMake asset emitter" )
94+ set (LLAMA_UI_EMBED_EXE "" )
95+ set (LLAMA_UI_EMBED_TARGET "" )
5696 endif ()
57-
58- add_custom_command (
59- OUTPUT "${LLAMA_UI_EMBED_EXE} "
60- COMMAND "${HOST_CXX_COMPILER} " -O2 -std=c++17
61- -o "${LLAMA_UI_EMBED_EXE} " "${CMAKE_CURRENT_SOURCE_DIR } /embed.cpp"
62- DEPENDS "${CMAKE_CURRENT_SOURCE_DIR } /embed.cpp"
63- COMMENT "Building llama-ui-embed (host)"
64- VERBATIM
65- )
66- add_custom_target (llama-ui-embed-host DEPENDS "${LLAMA_UI_EMBED_EXE} " )
67- set (LLAMA_UI_EMBED_TARGET llama-ui-embed-host)
6897else ()
6998 add_executable (llama-ui-embed embed.cpp )
7099 target_compile_features (llama-ui-embed PRIVATE cxx_std_17 )
@@ -94,7 +123,9 @@ add_custom_target(llama-ui-assets ALL
94123 VERBATIM
95124)
96125
97- add_dependencies (llama-ui-assets ${LLAMA_UI_EMBED_TARGET} )
126+ if (LLAMA_UI_EMBED_TARGET)
127+ add_dependencies (llama-ui-assets ${LLAMA_UI_EMBED_TARGET} )
128+ endif ()
98129
99130set_source_files_properties (${UI_CPP} ${UI_H} PROPERTIES GENERATED TRUE )
100131
0 commit comments