cmake_minimum_required(VERSION 3.16)
project(lapcpp_native_tests LANGUAGES CXX)
enable_testing()
find_package(Threads REQUIRED)
add_executable(native_tests test_solver.cpp ../../src/_lapjv/completion.cpp)
target_link_libraries(native_tests PRIVATE Threads::Threads)
set(LAPCPP_SANITIZER "" CACHE STRING "address (with undefined behavior) or thread")
if(MSVC)
  if(LAPCPP_SANITIZER)
    message(FATAL_ERROR "Use Clang on Linux for LAPCPP_SANITIZER builds")
  endif()
  target_compile_options(native_tests PRIVATE /std:c++17 /fp:precise /EHsc)
else()
  target_compile_features(native_tests PRIVATE cxx_std_17)
  target_compile_options(native_tests PRIVATE -Wall -Wextra -Werror -ffp-contract=off)
  if(LAPCPP_SANITIZER)
    if(LAPCPP_SANITIZER STREQUAL "address")
      set(sanitizers "address,undefined")
    elseif(LAPCPP_SANITIZER STREQUAL "thread")
      set(sanitizers "thread")
    else()
      message(FATAL_ERROR "Unsupported sanitizer: ${LAPCPP_SANITIZER}")
    endif()
    target_compile_options(native_tests PRIVATE -O1 -g -fno-omit-frame-pointer -fsanitize=${sanitizers} -fno-sanitize-recover=all)
    target_link_options(native_tests PRIVATE -fsanitize=${sanitizers})
  endif()
endif()
add_test(NAME native_tests COMMAND native_tests)
set_tests_properties(native_tests PROPERTIES TIMEOUT 120)
