11# Provision UI assets and generate ui.cpp/ui.h.
22#
33# Asset provisioning priority:
4- # 1. Pre -built assets in SRC_DIST_DIR (manually built by user)
4+ # 1. If BUILD_UI=ON: pre -built assets in SRC_DIST_DIR (manually built by user)
55# 2. If BUILD_UI=ON: npm build
6- # 3. If above did not produce assets and HF_ENABLED=ON: HF Bucket download
6+ # 3. If BUILD_UI=ON, above did not produce assets, and HF_ENABLED=ON: HF Bucket download
77
88cmake_minimum_required (VERSION 3.16 )
99
@@ -257,7 +257,7 @@ function(emit_files)
257257
258258 if ("${LLAMA_UI_EMBED} " STREQUAL "" )
259259 set (h "#pragma once\n\n #include <stddef.h>\n\n " )
260- if (present)
260+ if (BUILD_UI AND present)
261261 string (APPEND h "#define LLAMA_UI_HAS_ASSETS 1\n\n " )
262262 endif ()
263263 string (APPEND h
@@ -270,7 +270,7 @@ function(emit_files)
270270 )
271271
272272 set (cpp "#include \" ui.h\"\n\n #include <string.h>\n\n " )
273- if (present)
273+ if (BUILD_UI AND present)
274274 set (asset_index 0)
275275 foreach (asset ${ASSETS} )
276276 file (READ "${DIST_DIR} /${asset} " asset_hex HEX )
@@ -318,7 +318,7 @@ function(emit_files)
318318 endif ()
319319
320320 set (args "${UI_CPP} " "${UI_H} " )
321- if (present)
321+ if (BUILD_UI AND present)
322322 foreach (asset ${ASSETS} )
323323 list (APPEND args "${asset} " "${DIST_DIR} /${asset} " )
324324 endforeach ()
@@ -336,10 +336,12 @@ endfunction()
336336# ---------------------------------------------------------------------------
337337# 1. Priority 1: pre-built assets supplied in tools/ui/dist
338338# ---------------------------------------------------------------------------
339- copy_src_dist (SRC_OK )
340- if (SRC_OK)
341- emit_files ()
342- return ()
339+ if (BUILD_UI)
340+ copy_src_dist (SRC_OK )
341+ if (SRC_OK)
342+ emit_files ()
343+ return ()
344+ endif ()
343345endif ()
344346
345347# ---------------------------------------------------------------------------
@@ -355,9 +357,9 @@ if(BUILD_UI)
355357endif ()
356358
357359# ---------------------------------------------------------------------------
358- # 3. Priority 3: HF Bucket download (if npm did not produce assets and HF_ENABLED=ON)
360+ # 3. Priority 3: HF Bucket download (if BUILD_UI=ON, npm did not produce assets, and HF_ENABLED=ON)
359361# ---------------------------------------------------------------------------
360- if (NOT provisioned AND HF_ENABLED)
362+ if (BUILD_UI AND NOT provisioned AND HF_ENABLED)
361363 resolve_version (VERSION )
362364
363365 set (stamp_ok FALSE )
@@ -388,7 +390,7 @@ endif()
388390# ---------------------------------------------------------------------------
389391# 4. Fallback: warn about stale or missing assets, then emit whatever we have
390392# ---------------------------------------------------------------------------
391- if (NOT provisioned)
393+ if (BUILD_UI AND NOT provisioned)
392394 assets_present (have_assets )
393395 if (have_assets)
394396 message (WARNING "UI: provisioning failed; embedding stale assets from ${DIST_DIR} " )
@@ -399,6 +401,8 @@ if(NOT provisioned)
399401 "https://github.com/ggml-org/llama.cpp/releases and "
400402 "extract to tools/ui/dist." )
401403 endif ()
404+ elseif (NOT BUILD_UI)
405+ message (STATUS "UI: LLAMA_BUILD_UI=OFF, building without an embedded UI" )
402406endif ()
403407
404408emit_files ()
0 commit comments