cmake_minimum_required(VERSION 3.25)
project(product_fpol LANGUAGES CXX)

include(GNUInstallDirs)
include(CTest)

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

find_package(modulus CONFIG REQUIRED COMPONENTS boost_json openssl)
find_package(ligo CONFIG REQUIRED)
find_package(Threads REQUIRED)

add_executable(fpol_server src/main.cpp src/server.cpp)
target_link_libraries(fpol_server PRIVATE modulus::modulus ligo::ligo Threads::Threads)
target_compile_options(fpol_server PRIVATE $<$<CXX_COMPILER_ID:GNU,Clang>:-Wall;-Wextra;-Wpedantic>)

if(BUILD_TESTING)
  find_package(Python3 REQUIRED COMPONENTS Interpreter)
  add_test(NAME product_fpol
    COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_server.py $<TARGET_FILE:fpol_server>
  )
  set_tests_properties(product_fpol PROPERTIES TIMEOUT 60)
  add_custom_target(check
    COMMAND ${CMAKE_CTEST_COMMAND} --test-dir ${CMAKE_BINARY_DIR} -R ^product_fpol$ --output-on-failure
    DEPENDS fpol_server
    USES_TERMINAL
  )
endif()

install(TARGETS fpol_server RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
