# voicecat-server-lib — all server implementation except main.cpp.
# Linked by the server binary AND by tests (test_m1_integration).
file(GLOB_RECURSE VOICECAT_SERVER_LIB_SOURCES CONFIGURE_DEPENDS
     "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
list(FILTER VOICECAT_SERVER_LIB_SOURCES EXCLUDE REGEX ".*[/\\\\]main\\.cpp$")

add_library(voicecat-server-lib STATIC ${VOICECAT_SERVER_LIB_SOURCES})
target_compile_features(voicecat-server-lib PRIVATE cxx_std_20)
target_link_libraries(voicecat-server-lib PUBLIC voicecat::voicecat)
target_include_directories(voicecat-server-lib PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}/src
    ${CMAKE_SOURCE_DIR}/core/src)
add_library(voicecat::server ALIAS voicecat-server-lib)

if(VOICECAT_USE_VCPKG_DEPS)
    find_package(unofficial-sqlite3 CONFIG REQUIRED)
    find_package(unofficial-sodium CONFIG REQUIRED)
    find_package(MbedTLS CONFIG REQUIRED)
    find_package(asio CONFIG REQUIRED)
    target_link_libraries(voicecat-server-lib PUBLIC
        unofficial::sqlite3::sqlite3
        unofficial-sodium::sodium
        MbedTLS::mbedtls MbedTLS::mbedcrypto MbedTLS::mbedx509
        asio::asio)
    if(WIN32)
        target_link_libraries(voicecat-server-lib PUBLIC ws2_32 mswsock)
    endif()
endif()

# The server binary is just main.cpp calling Server::run().
add_executable(voicecat-server ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp)
target_link_libraries(voicecat-server PRIVATE voicecat::server)
target_compile_features(voicecat-server PRIVATE cxx_std_20)
