cmake_minimum_required(VERSION 3.20)
project(TooieRecompiled VERSION 0.1.0 LANGUAGES C CXX)
set(CMAKE_C_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(MSVC)
    add_compile_definitions(NOMINMAX)
endif()
# Release-family code and PDBs must not retain the developer checkout path.
# Apply before dependency subdirectories so generated code and native libraries
# receive the same mapping; Debug keeps full paths for local diagnostics.
if(WIN32 AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
    add_compile_options(
        "$<$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>,$<CONFIG:MinSizeRel>>:/clang:-ffile-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=/src>"
        "$<$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>,$<CONFIG:MinSizeRel>>:/clang:-ffile-prefix-map=${CMAKE_BINARY_DIR}=/build>"
        "$<$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>,$<CONFIG:MinSizeRel>>:/clang:-fdebug-compilation-dir=/build>")
elseif(WIN32 AND CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
    add_compile_options(
        "$<$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>,$<CONFIG:MinSizeRel>>:/pathmap:${CMAKE_CURRENT_SOURCE_DIR}=/src>"
        "$<$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>,$<CONFIG:MinSizeRel>>:/pathmap:${CMAKE_BINARY_DIR}=/build>")
endif()
# Player release of the maintained baseline engine.
set(TOOIE_PLAYER_VERSION "${PROJECT_VERSION}-alpha.5")
# One engineering engine. The old ordinary engine (TooieRecompiled, TooieFoundation, NativeHost) is retired.
# Explicit requests for it fail here instead of silently selecting a different engine.
foreach(_tooie_retired IN ITEMS TOOIE_NATIVE_HOST TOOIE_PERSISTENT_RUNTIME_EXPERIMENT)
    if(${_tooie_retired})
        message(FATAL_ERROR "${_tooie_retired} selected the retired ordinary engine. Configure with the "
            "windows-dev (or linux-dev) preset; the engineering player is the only engine.")
    endif()
endforeach()
if(DEFINED TOOIE_BASELINE AND NOT TOOIE_BASELINE)
    message(FATAL_ERROR "TOOIE_BASELINE=OFF selected the retired ordinary engine; remove it from the cache or preset.")
endif()
set(TOOIE_BASELINE ON)
# Regression tests are opt-in (the windows-tests/linux-tests presets): the ordinary player configuration has no test
# target, test fixture generation or test registration.
option(BUILD_TESTING "Configure the supported regression tests with the player" OFF)
include(cmake/Baseline.cmake)
if(BUILD_TESTING)
    enable_testing()
    include(cmake/BaselineTests.cmake)
    # Frontend settings/profile regressions (uses Baseline.cmake variables).
    include(cmake/FrontendTests.cmake)
    # Source-level checks of maintained tools and production code. They read tracked source (and temporary copies) only.
    add_test(NAME generate_local_player_mode COMMAND "${Python3_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/tests/generate_local_player_mode_test.py" "${CMAKE_SOURCE_DIR}")
    add_test(NAME bootstrap_header_view COMMAND "${Python3_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/tests/bootstrap_header_view_test.py")
    add_test(NAME bk_float_records COMMAND "${Python3_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/tests/test_bk_float_records.py")
endif()
