cmake_minimum_required(VERSION 3.20)

project(HopeFallout4CoreChecks VERSION 0.2.0 LANGUAGES CXX)

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

set(
    HOPE_PORTABLE_CORE_DIR
    "${CMAKE_CURRENT_SOURCE_DIR}/../HopePortableCore"
    CACHE PATH
    "Path to the shared HopePortableCore project"
)

if(NOT EXISTS "${HOPE_PORTABLE_CORE_DIR}/include/hope/hope_core.h")
    message(FATAL_ERROR "HopePortableCore not found at ${HOPE_PORTABLE_CORE_DIR}")
endif()

add_library(hope_portable_core STATIC
    "${HOPE_PORTABLE_CORE_DIR}/src/hope_core.cpp"
)
target_include_directories(hope_portable_core PUBLIC
    "${HOPE_PORTABLE_CORE_DIR}/include"
)

add_executable(hope_f4_adapter_contract_tests
    tests/adapter_contract_tests.cpp
    src/config.cpp
)
target_include_directories(hope_f4_adapter_contract_tests PRIVATE src)
target_link_libraries(hope_f4_adapter_contract_tests PRIVATE hope_portable_core)

add_executable(hope_f4_motion_spike
    tools/motion_spike.cpp
)
target_include_directories(hope_f4_motion_spike PRIVATE src)
target_link_libraries(hope_f4_motion_spike PRIVATE hope_portable_core)

if(MSVC)
    foreach(target hope_portable_core hope_f4_adapter_contract_tests hope_f4_motion_spike)
        target_compile_options(${target} PRIVATE /W4 /WX /permissive- /EHsc)
    endforeach()
endif()

enable_testing()
add_test(NAME hope_f4_adapter_contract COMMAND hope_f4_adapter_contract_tests)
add_test(NAME hope_f4_motion_spike COMMAND hope_f4_motion_spike --self-test)

add_executable(hope_f4_fall_protection_tests tests/fall_protection_tests.cpp)
target_include_directories(hope_f4_fall_protection_tests PRIVATE src)
if(MSVC)
    target_compile_options(hope_f4_fall_protection_tests PRIVATE /W4 /WX /permissive- /EHsc)
endif()
add_test(NAME hope_f4_fall_protection COMMAND hope_f4_fall_protection_tests)
