# libvkserve_engine: the multi-sequence engine, loaded by src/vkserve/engine.py through ctypes.
# It builds compute-ml from source (COMPUTE_ML_DIR, default ../compute-ml next to this repo) and
# compiles compute-ml's LLM core (examples/llm) into the same library.
cmake_minimum_required(VERSION 3.21)
project(vkserve_engine LANGUAGES C)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)

set(COMPUTE_ML_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../compute-ml" CACHE PATH "compute-ml source tree")
get_filename_component(COMPUTE_ML_DIR "${COMPUTE_ML_DIR}" ABSOLUTE)
if(NOT EXISTS "${COMPUTE_ML_DIR}/examples/llm/llm.c")
    message(FATAL_ERROR "compute-ml not found at ${COMPUTE_ML_DIR}; pass -DCOMPUTE_ML_DIR=<path>")
endif()
add_subdirectory("${COMPUTE_ML_DIR}" compute-ml EXCLUDE_FROM_ALL)
find_package(Vulkan REQUIRED)

add_library(vkserve_engine SHARED engine.c devices.c
            "${COMPUTE_ML_DIR}/examples/llm/llm.c" "${COMPUTE_ML_DIR}/examples/whisper/json.c")
target_include_directories(vkserve_engine PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
                           "${COMPUTE_ML_DIR}/examples/llm" "${COMPUTE_ML_DIR}/examples/whisper")
target_link_libraries(vkserve_engine PRIVATE compute_ml Vulkan::Vulkan)
if(NOT MSVC)
    target_link_libraries(vkserve_engine PRIVATE m)
endif()
set_target_properties(vkserve_engine PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
