cmake_minimum_required(VERSION 3.24)
project(lumi-whisper-worker VERSION 0.1.0 LANGUAGES CXX)

include(FetchContent)
option(LUMI_WHISPER_CUDA "Build whisper.cpp with CUDA support" OFF)

set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
set(WHISPER_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(WHISPER_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(WHISPER_BUILD_SERVER OFF CACHE BOOL "" FORCE)
set(GGML_CUDA ${LUMI_WHISPER_CUDA} CACHE BOOL "" FORCE)

FetchContent_Declare(
  whisper
  GIT_REPOSITORY https://github.com/ggml-org/whisper.cpp.git
  GIT_TAG f049fff95a089aa9969deb009cdd4892b3e74916
  GIT_SHALLOW FALSE
)
FetchContent_Declare(
  json
  URL https://github.com/nlohmann/json/releases/download/v3.12.0/json.tar.xz
  URL_HASH SHA256=42f6e95cad6ec532fd372391373363b62a14af6d771056dbfc86160e6dfff7aa
)
FetchContent_MakeAvailable(whisper json)

add_executable(lumi-whisper-worker src/main.cpp)
target_compile_features(lumi-whisper-worker PRIVATE cxx_std_20)
target_link_libraries(lumi-whisper-worker PRIVATE whisper nlohmann_json::nlohmann_json)
if(LUMI_WHISPER_CUDA)
  target_compile_definitions(lumi-whisper-worker PRIVATE LUMI_BACKEND_CUDA=1)
endif()
if(MSVC)
  target_compile_options(lumi-whisper-worker PRIVATE /W4 /EHsc)
else()
  target_compile_options(lumi-whisper-worker PRIVATE -Wall -Wextra -Wpedantic)
endif()
install(TARGETS lumi-whisper-worker RUNTIME DESTINATION bin)
