cmake_minimum_required(VERSION 3.25)
project(auto_pause_tests LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(rexglue 0.10.0 REQUIRED CONFIG)
enable_testing()
set(test_sources auto_pause_test)
# The actual InputSystem disconnect fixture is unconditional in ReIGlue change 0399.
# Client tests cover the current SDK export and an injected missing-export fallback.
if(WIN32)
    list(APPEND test_sources auto_pause_native_probe auto_pause_native_tu4_probe
        auto_pause_sdk_probe auto_pause_missing_bridge_probe)
endif()
foreach(name IN LISTS test_sources)
    set(source_name ${name})
    if(NOT name STREQUAL "auto_pause_test")
        set(source_name auto_pause_native_probe)
    endif()
    add_executable(${name} ../../../forza-recomp/tests/${source_name}.cpp)
    target_include_directories(${name} PRIVATE ../../../forza-recomp/src)
    if(name STREQUAL "auto_pause_sdk_probe")
        target_compile_definitions(${name} PRIVATE FORZA_AUTO_PAUSE_SDK_BRIDGE=1)
    elseif(name STREQUAL "auto_pause_missing_bridge_probe")
        target_compile_definitions(${name} PRIVATE FORZA_AUTO_PAUSE_MISSING_BRIDGE=1)
    elseif(name STREQUAL "auto_pause_native_tu4_probe")
        target_compile_definitions(${name} PRIVATE FORZA_TITLE_UPDATE=4)
    endif()
    target_link_libraries(${name} PRIVATE rex::runtime)
    if(MSVC)
        target_compile_options(${name} PRIVATE /UNDEBUG)
    else()
        target_compile_options(${name} PRIVATE -UNDEBUG)
    endif()
    if(WIN32)
        target_compile_definitions(${name} PRIVATE NOMINMAX)
        add_custom_command(TARGET ${name} POST_BUILD
            COMMAND ${CMAKE_COMMAND} -E copy_if_different
            "$<TARGET_FILE:rex::runtime>" "$<TARGET_FILE_DIR:${name}>")
    endif()
    add_test(NAME ${name} COMMAND ${name})
    set_tests_properties(${name} PROPERTIES TIMEOUT 30)
endforeach()
if(WIN32)
    set_tests_properties(auto_pause_native_probe auto_pause_native_tu4_probe PROPERTIES
        PASS_REGULAR_EXPRESSION "native auto-pause: live paused")
    set_tests_properties(auto_pause_sdk_probe PROPERTIES
        PASS_REGULAR_EXPRESSION "SDK auto-pause: actual export")
    set_tests_properties(auto_pause_missing_bridge_probe PROPERTIES
        PASS_REGULAR_EXPRESSION "missing bridge auto-pause: injected absence")
endif()
