# gguf.cpp / llm — the GGUF language-model runtime and its HTTP server.
#
# Same sources as the standalone gguf-server tree, with two changes for the
# unified build:
#
#   * kernels/ is gone — ggml comes from ../kernels, already configured and
#     added by the top level, so the ggml targets simply exist here;
#   * the global toolchain setup (C/C++ standards, output directories, MSVC
#     flags, backend options, build info) lives in the top level too.
#
#   src/         the GGUF model runtime (libllama)
#   common/      argument parsing, chat templates, sampling, logging
#   mtmd/        multimodal (vision/audio) projector support
#   app/         the gguf-server binary
#   ui/          embedded web UI assets (optional, empty by default)
#   thirdparty/  cpp-httplib, nlohmann/json, stb, miniaudio, subprocess.h

# features
option(GGUF_SERVER_OPENSSL  "gguf-server: use OpenSSL for HTTPS model downloads"    ON)
option(GGUF_SERVER_INSTALL  "gguf-server: install the binary on `cmake --install`"  ${GGUF_CPP_INSTALL})

# subprocess spawning powers `--models` router mode; not available everywhere
if (CMAKE_SYSTEM_NAME STREQUAL "iOS" OR CMAKE_SYSTEM_NAME STREQUAL "Android" OR ANDROID
        OR CMAKE_SYSTEM_NAME STREQUAL "Emscripten" OR EMSCRIPTEN)
    set(GGUF_SERVER_SUBPROCESS_DEFAULT OFF)
else()
    set(GGUF_SERVER_SUBPROCESS_DEFAULT ON)
endif()
option(GGUF_SERVER_SUBPROCESS "gguf-server: support router mode (spawns child servers)" ${GGUF_SERVER_SUBPROCESS_DEFAULT})

set(LLAMA_SUBPROCESS ${GGUF_SERVER_SUBPROCESS})
set(LLAMA_OPENSSL    ${GGUF_SERVER_OPENSSL})

include(common)   # llama_add_compile_flags(), via ../kernels/cmake/common.cmake

add_subdirectory(src)                # llama
add_subdirectory(thirdparty/cpp-httplib)
add_subdirectory(common)             # llama-common
add_subdirectory(mtmd)               # multimodal
add_subdirectory(ui)                 # embedded web UI assets
add_subdirectory(app)                # the gguf-server binary
