# daemon/ produces the veloxd binary and the veloxd_rpc static library it is built from.
# Owned by lane DAEMON. Wired in by PKG via add_subdirectory(daemon) in the root file,
# guarded on this file existing.
#
# Layering (CLAUDE.md §3): depends on velox::core and velox::proto. No Qt. The engine
# (velox::core) is not linked yet — it arrives when sched/ and the task glue land; this
# first drop is the RPC transport + dispatcher skeleton so the CLI and GUI have a real
# server to talk to.

if(NOT TARGET nlohmann_json::nlohmann_json)
    find_package(nlohmann_json 3.11 REQUIRED)
endif()
find_package(Threads REQUIRED)

# --- veloxd_rpc — the server library ----------------------------------------------------
add_library(veloxd_rpc STATIC
    src/rpc/runtime_dir.cpp
    src/rpc/event_loop.cpp
    src/rpc/uds_server.cpp
    src/rpc/dispatcher.cpp
)
add_library(velox::daemon_rpc ALIAS veloxd_rpc)

target_include_directories(veloxd_rpc
    PUBLIC  ${CMAKE_CURRENT_SOURCE_DIR}/src
)
target_compile_features(veloxd_rpc PUBLIC cxx_std_23)
target_compile_options(veloxd_rpc PRIVATE -Wall -Wextra -Wpedantic -Werror)
target_link_libraries(veloxd_rpc
    PUBLIC  velox::proto nlohmann_json::nlohmann_json Threads::Threads
)

# --- veloxd — the daemon binary -------------------------------------------------------
add_executable(veloxd src/main.cpp)
target_compile_features(veloxd PRIVATE cxx_std_23)
target_compile_options(veloxd PRIVATE -Wall -Wextra -Wpedantic -Werror)
target_link_libraries(veloxd PRIVATE veloxd_rpc)

if(VELOX_BUILD_TESTS AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/tests/CMakeLists.txt)
    add_subdirectory(tests)
endif()
