# Standalone, CI-friendly build for the FunASR llama.cpp runtime.
#
# Fetches a pinned llama.cpp (which provides ggml + llama) and builds the runtime
# binaries against it — no manual copying into a llama.cpp checkout, no hardcoded
# paths. Linux / macOS / Windows, x64 / arm64. Static libs -> self-contained binaries.
#
# cmake -B build -DCMAKE_BUILD_TYPE=Release
# cmake --build build -j # binaries land in build/bin/
#
# Build against a local checkout instead of fetching:
# -DFETCHCONTENT_SOURCE_DIR_LLAMA=/path/to/llama.cpp
cmake_minimum_required(VERSION 3.16)
project(funasr-llamacpp-sensevoice CXX C)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) # static deps -> self-contained binaries
if(MSVC)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
add_compile_options(/utf-8)
endif()
if(WIN32)
add_compile_definitions(NOMINMAX WIN32_LEAN_AND_MEAN)
endif()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
foreach(config ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${config} config_upper)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${config_upper} ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${config_upper} ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${config_upper} ${CMAKE_BINARY_DIR}/lib)
endforeach()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE Release CACHE STRING "" FORCE)
endif()
option(FUNASR_BUILD_RUST "Build the Rust C ABI bridge library" OFF)
include(FetchContent)
set(LLAMA_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(LLAMA_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(LLAMA_BUILD_TOOLS OFF CACHE BOOL "" FORCE)
set(LLAMA_BUILD_SERVER OFF CACHE BOOL "" FORCE)
set(LLAMA_CURL OFF CACHE BOOL "" FORCE)
FetchContent_Declare(llama
GIT_REPOSITORY https://github.com/ggml-org/llama.cpp.git
GIT_TAG 8086439a4cea94c71a5dfb8fe4ad1546aebd640f)
FetchContent_MakeAvailable(llama)
find_package(Threads REQUIRED)
set(FUNASR_COMMON ${CMAKE_CURRENT_SOURCE_DIR}/funasr-common)
function(funasr_add name src)
add_executable(${name} ${src})
target_include_directories(${name} PRIVATE ${FUNASR_COMMON})
target_link_libraries(${name} PRIVATE ${ARGN} Threads::Threads)
install(TARGETS ${name} RUNTIME DESTINATION bin)
endfunction()
funasr_add(llama-funasr-sensevoice funasr-sensevoice/funasr-sensevoice.cpp ggml)
funasr_add(llama-funasr-vad funasr-vad/funasr-vad.cpp ggml)
if(FUNASR_BUILD_RUST)
add_library(funasr_rs SHARED funasr-capi/funasr_c_api.cpp)
target_compile_definitions(funasr_rs PRIVATE FUNASR_RS_EXPORTS)
target_include_directories(funasr_rs
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/funasr-capi
PRIVATE
${FUNASR_COMMON})
target_link_libraries(funasr_rs PRIVATE ggml Threads::Threads)
if(WIN32)
set_target_properties(funasr_rs PROPERTIES PREFIX "")
endif()
install(TARGETS funasr_rs
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
endif()