cmake_minimum_required(VERSION 3.22)

project(auth_service VERSION 0.1.0 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

include(CTest)
enable_testing()

find_package(SQLite3 REQUIRED)
find_package(OpenSSL REQUIRED)

add_subdirectory(submodules/drogon)
add_subdirectory(submodules/json)
add_subdirectory(submodules/Catch2)

add_executable(auth_service
    src/main.cpp
    src/application/application.cpp
    src/http/controllers/health_controller.cpp
    src/db/sqllite_db.cpp
    src/db/statement.cpp
    src/db/transaction.cpp
    src/db/migrations_runner.cpp
    src/repo/user_repository.cpp
    src/repo/session_repository.cpp
    src/util/time_utils.cpp
    src/security/session_token_service.cpp
)

target_include_directories(auth_service
    PRIVATE
        ${PROJECT_SOURCE_DIR}/include
        ${PROJECT_SOURCE_DIR}/src
)

target_compile_options(auth_service PRIVATE
    -Wall
    -Wextra
    -Wpedantic
)

target_link_libraries(auth_service PRIVATE
    drogon
    SQLite::SQLite3
    nlohmann_json::nlohmann_json
    OpenSSL::Crypto
)

add_executable(auth_service_tests
    tests/smoke_test.cpp
)

target_include_directories(auth_service_tests
    PRIVATE
        ${PROJECT_SOURCE_DIR}/include
        ${PROJECT_SOURCE_DIR}/src
)

target_compile_options(auth_service_tests PRIVATE
    -Wall
    -Wextra
    -Wpedantic
)

target_link_libraries(auth_service_tests PRIVATE
    Catch2::Catch2WithMain
    nlohmann_json::nlohmann_json
)

include(${PROJECT_SOURCE_DIR}/submodules/Catch2/extras/Catch.cmake)
catch_discover_tests(auth_service_tests)