# EchoionStandalone — the daemon that runs Core without a TeamSpeak client.
#
# It uses the host-common CoreLoader/FileWatcher to load and hot-reload Core,
# and implements IPluginInterface with EchoionProtocol's native UDP client.

cmake_minimum_required(VERSION 4.0.0)
project(EchoionStandalone VERSION 1.0.0 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 26)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

find_package(PkgConfig REQUIRED)
pkg_check_modules(SWRESAMPLE REQUIRED IMPORTED_TARGET libswresample libavutil)
pkg_check_modules(OPUS REQUIRED IMPORTED_TARGET opus)
find_package(Threads REQUIRED)

add_executable(EchoionStandalone
    src/main.cpp
    src/StandaloneClientInterface.cpp
    src/AudioEncoder.cpp
    src/MessageChunker.cpp
)

target_include_directories(EchoionStandalone PRIVATE
    "${CMAKE_CURRENT_SOURCE_DIR}/include"
)

target_link_libraries(EchoionStandalone PRIVATE
    Echoion::Protocol
    Echoion::Host
    Echoion::ApiBase
    Echoion::ApiPlugin
    Echoion::ApiOpaque
    Echoion::ApiPluginInterface
    Echoion::ApiCoreInterface
    Echoion::ApiLogger
    Void::Data
    Void::Log
    Void::Stacktrace
    Threads::Threads
    PkgConfig::SWRESAMPLE
    PkgConfig::OPUS
)

set_target_properties(EchoionStandalone PROPERTIES
    OUTPUT_NAME "echoiond"
    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)

install(TARGETS EchoionStandalone RUNTIME DESTINATION bin)

if(BUILD_TESTS)
    add_executable(echoion_standalone_message_tests
        tests/test_message_chunker.cpp
        src/MessageChunker.cpp
    )
    target_include_directories(echoion_standalone_message_tests PRIVATE
        "${CMAKE_CURRENT_SOURCE_DIR}/include"
    )
    target_compile_features(echoion_standalone_message_tests PRIVATE cxx_std_20)
    add_test(NAME echoion_standalone_message_tests
        COMMAND echoion_standalone_message_tests)
endif()
