# TooieRecomp — Banjo-Tooie static recompilation (P05+ executable).
cmake_minimum_required(VERSION 3.20)
project(TooieRecomp LANGUAGES C CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Standalone: rt64, N64ModernRuntime (+N64Recomp), RecompFrontend, SlotMap and SDL2 (Windows) are vendored as regular
# files under lib/ (provenance, pins and patch chain: vendor/UPSTREAMS.tsv; integrity: tools/vendor_verify.sh).
# No sibling checkout, submodule or download is used. assets/ and recompcontrollerdb.txt live in this repository.
set(TOOIE_LIB "${CMAKE_SOURCE_DIR}/lib")
set(N64MR "${TOOIE_LIB}/N64ModernRuntime")
set(RT64_ROOT "${TOOIE_LIB}/rt64")
set(RECOMP_FRONTEND "${TOOIE_LIB}/RecompFrontend")
if(NOT EXISTS "${RT64_ROOT}/CMakeLists.txt" OR NOT EXISTS "${N64MR}/CMakeLists.txt" OR NOT EXISTS "${RECOMP_FRONTEND}/CMakeLists.txt")
  message(FATAL_ERROR "vendored tree incomplete under ${TOOIE_LIB}: run tools/vendor_verify.sh")
endif()

if (NOT CMAKE_BUILD_TYPE)
  set(CMAKE_BUILD_TYPE Release)
endif()

# Generated RECOMP_FUNC symbols are weak only under Clang. GCC emits strong
# definitions, so boot_hw_stubs cannot interpose. The protected Tooie build
# is Clang; a clean GCC configure reaches link and fails.
if(NOT CMAKE_C_COMPILER_ID MATCHES "Clang")
    message(FATAL_ERROR
        "TooieRecompiled requires Clang (this compiler is '${CMAKE_C_COMPILER_ID}'). "
        "GCC RECOMP_FUNC is not weak, so boot_hw_stubs cannot override generated "
        "functions. Configure with -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++")
endif()

# Must be CMake variables (not only compile defs) before add_subdirectory(rt64).
set(RT64_SDL_WINDOW_VULKAN TRUE)
set(RT64_STATIC TRUE CACHE BOOL "Build RT64 as a static library" FORCE)
if(NOT WIN32) # BanjoRecomp sets these on Linux only; Windows keeps its D3D12 default.
  set(PLUME_SDL_VULKAN_ENABLED TRUE CACHE BOOL "Enable SDL Vulkan integration" FORCE)
  add_compile_definitions("PLUME_SDL_VULKAN_ENABLED")
  add_compile_definitions("RT64_SDL_WINDOW_VULKAN")
endif()

if(WIN32)
  # Vendored official SDL2-devel 2.30.3 VC contents (lib/SDL2-windows; provenance vendor/UPSTREAMS.tsv). No FetchContent.
  # RecompFrontend reads sdl2_SOURCE_DIR; rt64 (local seam patch) consumes the SDL2::SDL2/SDL2::SDL2main targets below.
  # UNVERIFIED on a native Windows host (no Windows toolchain on the authoring host): see tools/BUILDING.md.
  set(sdl2_SOURCE_DIR "${TOOIE_LIB}/SDL2-windows")
  if(NOT EXISTS "${sdl2_SOURCE_DIR}/lib/x64/SDL2.lib")
    message(FATAL_ERROR "lib/SDL2-windows is incomplete: run tools/vendor_verify.sh")
  endif()
  set(SDL2_INCLUDE_DIRS "${sdl2_SOURCE_DIR}/include")
  add_library(SDL2::SDL2 INTERFACE IMPORTED)
  set_target_properties(SDL2::SDL2 PROPERTIES
    INTERFACE_INCLUDE_DIRECTORIES "${sdl2_SOURCE_DIR}/include"
    INTERFACE_LINK_LIBRARIES "${sdl2_SOURCE_DIR}/lib/x64/SDL2.lib;Winmm.lib")
  add_library(SDL2::SDL2main INTERFACE IMPORTED)
  set_target_properties(SDL2::SDL2main PROPERTIES
    INTERFACE_LINK_LIBRARIES "${sdl2_SOURCE_DIR}/lib/x64/SDL2main.lib")
  add_compile_definitions(NOMINMAX HLSL_CPU __PRFCHWINTRIN_H)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR")
  if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-everything /W4")
  endif()
else()
  find_package(SDL2 REQUIRED)
endif()

# --- RT64 + N64ModernRuntime + RecompFrontend (vendored under lib/) ---
add_subdirectory(${RT64_ROOT} ${CMAKE_BINARY_DIR}/rt64)
set(BUILD_SHARED_LIBS OFF)
add_subdirectory(${N64MR} ${CMAKE_BINARY_DIR}/N64ModernRuntime)
target_include_directories(rt64 PRIVATE ${CMAKE_BINARY_DIR}/rt64/src)

set(RECOMP_FRONTEND_N64MODERNRUNTIME_PATH ${N64MR})
set(RECOMP_FRONTEND_RT64_PATH ${RT64_ROOT})

# DXC + shader opts must be set before RecompFrontend (custom commands expand ${DXC}).
set(DXC_COMMON_OPTS "-I${RT64_ROOT}/src")
set(DXC_DXIL_OPTS "-Wno-ignored-attributes")
set(DXC_SPV_OPTS "-spirv" "-fspv-target-env=vulkan1.0" "-fvk-use-dx-layout")
set(DXC_PS_OPTS ${DXC_COMMON_OPTS} "-E" "PSMain" "-T" "ps_6_0" "-D" "DYNAMIC_RENDER_PARAMS")
set(DXC_VS_OPTS ${DXC_COMMON_OPTS} "-E" "VSMain" "-T" "vs_6_0" "-D" "DYNAMIC_RENDER_PARAMS" "-fvk-invert-y")
set(DXC_CS_OPTS ${DXC_COMMON_OPTS} "-E" "CSMain" "-T" "cs_6_0")
set(DXC_GS_OPTS ${DXC_COMMON_OPTS} "-E" "GSMain" "-T" "gs_6_0")
if(WIN32)
  set(DXC "${RT64_ROOT}/src/contrib/dxc/bin/x64/dxc.exe")
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8 AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|AMD64")
  set(DXC "LD_LIBRARY_PATH=${RT64_ROOT}/src/contrib/dxc/lib/x64" "${RT64_ROOT}/src/contrib/dxc/bin/x64/dxc-linux")
else()
  message(FATAL_ERROR "Only x86_64 Linux/Windows DXC is vendored (arm64/macOS DXC trees were excluded, see vendor/EXCLUDES.txt)")
endif()

add_subdirectory(${RECOMP_FRONTEND} ${CMAKE_BINARY_DIR}/RecompFrontend)

# --- RecompiledFuncs (generated by N64Recomp in P04) ---
add_library(RecompiledFuncs STATIC)
file(GLOB FUNC_C_SOURCES CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/RecompiledFuncs/*.c")
file(GLOB FUNC_CXX_SOURCES CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/RecompiledFuncs/*.cpp")
target_sources(RecompiledFuncs PRIVATE ${FUNC_C_SOURCES} ${FUNC_CXX_SOURCES})
target_compile_options(RecompiledFuncs PRIVATE
    -fno-strict-aliasing
    -Wno-unused-variable
    -Wno-implicit-function-declaration
    -falign-functions=16
)
# Existing generated sources use lround* for MIPS ROUND.{W,L}.{S,D}.  Map those
# calls at this target boundary until regeneration emits ROUND_* directly.
target_compile_definitions(RecompiledFuncs PRIVATE
    RECOMP_MIPS_ROUND_COMPAT=1
)
target_include_directories(RecompiledFuncs PRIVATE
    ${CMAKE_SOURCE_DIR}/include
    ${CMAKE_SOURCE_DIR}/RecompiledFuncs
    ${N64MR}/ultramodern/include
    ${N64MR}/librecomp/include
    ${N64MR}/N64Recomp/include
)

# --- Empty patches lib (P05) ---
# These three files are tracked empty scaffolds, not generated ROM output.
# A clean checkout must already contain them; do not synthesize them here.
set(_TOOIE_PATCH_SCAFFOLDS
    patches.c
    patches_bin.c
    recomp_overlays.inl
)
foreach(_scaffold IN LISTS _TOOIE_PATCH_SCAFFOLDS)
    if(NOT EXISTS "${CMAKE_SOURCE_DIR}/RecompiledPatches/${_scaffold}")
        message(FATAL_ERROR
            "Missing tracked RecompiledPatches scaffold: ${_scaffold}. "
            "These empty files are versioned source inputs, not generated output.")
    endif()
endforeach()

add_library(PatchesLib STATIC
    ${CMAKE_SOURCE_DIR}/RecompiledPatches/patches.c
    ${CMAKE_SOURCE_DIR}/RecompiledPatches/patches_bin.c
)
target_include_directories(PatchesLib PRIVATE
    ${CMAKE_SOURCE_DIR}/include
    ${N64MR}/ultramodern/include
    ${N64MR}/librecomp/include
    ${N64MR}/N64Recomp/include
)

# --- Retail cart -> decompressed image (in-memory use of the vendored decomp/tools/rom_decompressor) ---
# Same recipe as tools/windows/extract: the decompressor's zlib calls run on the vendored miniz (already linked by librecomp,
# so no second miniz is compiled) through a zlib.h shim that lives only in the build tree and only on this target's include
# path. fmt is the copy N64Recomp already builds into the game (decomp/tools/fmt is the same major version, v11, in the same
# inline namespace, so a second compiled copy would be a duplicate-symbol link error); tooie_utils is private to this library.
set(TOOIE_DECOMP_TOOLS "${CMAKE_SOURCE_DIR}/decomp/tools")
set(TOOIE_CART_SHIM_DIR "${CMAKE_BINARY_DIR}/cart_decompress_shim")
file(MAKE_DIRECTORY "${TOOIE_CART_SHIM_DIR}")
file(WRITE "${TOOIE_CART_SHIM_DIR}/miniz_export.h" "#pragma once\n#ifndef MINIZ_EXPORT\n#define MINIZ_EXPORT\n#endif\n")
file(WRITE "${TOOIE_CART_SHIM_DIR}/zlib.h" "#pragma once\n#include \"miniz.h\"\n")
add_library(tooie_cart_decompress STATIC
    ${TOOIE_DECOMP_TOOLS}/rom_decompressor.cpp
    ${TOOIE_DECOMP_TOOLS}/tooie_utils.cpp
)
target_include_directories(tooie_cart_decompress PUBLIC ${TOOIE_DECOMP_TOOLS})
target_include_directories(tooie_cart_decompress PRIVATE
    ${TOOIE_CART_SHIM_DIR}
    ${N64MR}/thirdparty/miniz
    ${TOOIE_DECOMP_TOOLS}/toml11/include
    ${TOOIE_DECOMP_TOOLS}/elfio
)
target_compile_definitions(tooie_cart_decompress PRIVATE TOOIE_ROM_DECOMPRESSOR_LIB)
target_link_libraries(tooie_cart_decompress PRIVATE miniz fmt)
# Vendored sources are not ours to fix: silence their warnings (as tools/windows/extract does).
if(MSVC)
    target_compile_options(tooie_cart_decompress PRIVATE /w)
    target_compile_definitions(tooie_cart_decompress PRIVATE _CRT_SECURE_NO_WARNINGS)
else()
    target_compile_options(tooie_cart_decompress PRIVATE -w)
endif()

# --- Main executable ---
add_executable(TooieRecompiled
    ${CMAKE_SOURCE_DIR}/src/main/launcher_animation.cpp
    ${CMAKE_SOURCE_DIR}/src/main/main.cpp
    ${CMAKE_SOURCE_DIR}/src/main/tooie_audio_capture.cpp
    ${CMAKE_SOURCE_DIR}/src/main/register_overlays.cpp
    ${CMAKE_SOURCE_DIR}/src/main/register_patches.cpp
    ${CMAKE_SOURCE_DIR}/src/main/theme.cpp
    ${CMAKE_SOURCE_DIR}/src/game/config.cpp
    ${CMAKE_SOURCE_DIR}/src/game/fps_overlay.cpp
    ${CMAKE_SOURCE_DIR}/src/game/debug.cpp
    ${CMAKE_SOURCE_DIR}/src/game/recomp_api.cpp
    ${CMAKE_SOURCE_DIR}/src/game/recomp_extension_api.cpp
    ${CMAKE_SOURCE_DIR}/src/game/recomp_data_api.cpp
    ${CMAKE_SOURCE_DIR}/src/game/language_paths.cpp
    ${CMAKE_SOURCE_DIR}/src/game/language_pack.cpp
    ${CMAKE_SOURCE_DIR}/src/game/language_import_ui.cpp
    ${CMAKE_SOURCE_DIR}/src/game/text_font_map.cpp
    ${CMAKE_SOURCE_DIR}/src/game/rom_decompression.cpp
    ${CMAKE_SOURCE_DIR}/src/game/syscall_handler.cpp
    ${CMAKE_SOURCE_DIR}/src/game/boot_hw_stubs.cpp
    ${CMAKE_SOURCE_DIR}/src/game/tooie_bgm_volume.cpp
    ${CMAKE_SOURCE_DIR}/src/game/tooie_bgm_hooks.cpp
    ${CMAKE_SOURCE_DIR}/src/game/transform_hooks.cpp
    ${CMAKE_SOURCE_DIR}/src/game/tintro_projection_policy.cpp
    ${CMAKE_SOURCE_DIR}/src/game/tooie_window.cpp
    ${CMAKE_SOURCE_DIR}/src/game/tooie_error.cpp
    ${CMAKE_SOURCE_DIR}/src/game/tooie_diag.cpp
    ${CMAKE_SOURCE_DIR}/src/game/backpack_lookup_diag.cpp
    ${CMAKE_SOURCE_DIR}/src/game/generated/overlay_dispatch.gen.cpp
    ${CMAKE_SOURCE_DIR}/rsp/n_aspMain.cpp
)

target_include_directories(TooieRecompiled PRIVATE
    ${CMAKE_SOURCE_DIR}/include
    ${CMAKE_SOURCE_DIR}/RecompiledFuncs
    ${CMAKE_SOURCE_DIR}/src/game
    ${CMAKE_BINARY_DIR}
    ${N64MR}/N64Recomp/include
    ${N64MR}/thirdparty/sse2neon
    ${N64MR}/thirdparty
    ${N64MR}/thirdparty/xxHash
    ${RT64_ROOT}/src/contrib
    ${RT64_ROOT}/src/contrib/hlslpp/include
    ${RT64_ROOT}/src/contrib/dxc/inc
    ${RT64_ROOT}/src
    ${RT64_ROOT}/src/rhi
    ${RT64_ROOT}/src/render
    ${RECOMP_FRONTEND}/recompinput/include
    ${RECOMP_FRONTEND}/recompui/include
    ${RECOMP_FRONTEND}/recompui/src
    ${RT64_ROOT}/src/contrib/nativefiledialog-extended/src/include
    ${TOOIE_LIB}/SlotMap
)

# main.cpp includes "stb/stb_image.h" (rt64 contrib).
target_include_directories(TooieRecompiled PRIVATE ${RT64_ROOT}/src/contrib)

# App icon: icons/app.png is embedded as icon_bytes (Linux window icon and launcher thumbnail);
# icons/app.ico is the Windows executable/window icon.
set(TOOIE_ICON_PNG "${CMAKE_SOURCE_DIR}/icons/app.png")
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${TOOIE_ICON_PNG}")
file(READ "${TOOIE_ICON_PNG}" TOOIE_ICON_HEX HEX)
string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," TOOIE_ICON_HEX "${TOOIE_ICON_HEX}")
file(WRITE "${CMAKE_BINARY_DIR}/icon_bytes.h.tmp"
    "#pragma once\n// Generated by CMake from icons/app.png.\ninline constexpr unsigned char icon_bytes[] = {${TOOIE_ICON_HEX}};\n")
configure_file("${CMAKE_BINARY_DIR}/icon_bytes.h.tmp" "${CMAKE_BINARY_DIR}/icon_bytes.h" COPYONLY)
if(WIN32)
    target_sources(TooieRecompiled PRIVATE ${CMAKE_SOURCE_DIR}/icons/app.rc)
endif()

target_compile_options(TooieRecompiled PRIVATE
    -fno-strict-aliasing
    -fms-extensions
    -Wno-unused-parameter
)

if(CMAKE_SIZEOF_VOID_P EQUAL 8 AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|AMD64")
    target_compile_options(TooieRecompiled PRIVATE -march=nehalem)
endif()

find_package(Threads REQUIRED)

if(WIN32)
    # freetype comes from RecompFrontend (freetype-windows-binaries); SDL2 from the vendored lib/SDL2-windows.
    target_include_directories(TooieRecompiled PRIVATE ${SDL2_INCLUDE_DIRS})
    target_link_libraries(TooieRecompiled PRIVATE
        PatchesLib
        RecompiledFuncs
        tooie_cart_decompress
        recompui
        recompinput
        librecomp
        ultramodern
        rt64
        nfd
        SDL2::SDL2
        Threads::Threads
    )
    # Identical-code folding would merge functions and break mod function patching (as in BanjoRecomp).
    target_link_options(TooieRecompiled PRIVATE /OPT:NOICF)
    set_target_properties(TooieRecompiled PROPERTIES
        LINK_FLAGS_DEBUG "/SUBSYSTEM:CONSOLE"
        LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup"
        LINK_FLAGS_RELWITHDEBINFO "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup"
        LINK_FLAGS_MINSIZEREL "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")
    add_custom_command(TARGET TooieRecompiled POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy_if_different
            "${sdl2_SOURCE_DIR}/lib/x64/SDL2.dll"
            "${RT64_ROOT}/src/contrib/dxc/bin/x64/dxil.dll"
            "${RT64_ROOT}/src/contrib/dxc/bin/x64/dxcompiler.dll"
            $<TARGET_FILE_DIR:TooieRecompiled>)
else()
    find_package(SDL2 REQUIRED)
    find_package(Freetype REQUIRED)

    target_include_directories(TooieRecompiled PRIVATE ${SDL2_INCLUDE_DIRS} ${FREETYPE_INCLUDE_DIRS})

    target_link_libraries(TooieRecompiled PRIVATE
        PatchesLib
        RecompiledFuncs
        tooie_cart_decompress
        recompui
        recompinput
        librecomp
        ultramodern
        rt64
        nfd
        ${FREETYPE_LIBRARIES}
        SDL2::SDL2
        Threads::Threads
        ${CMAKE_DL_LIBS}
        atomic
    )
endif()

# Runtime resolves <exe dir>/assets. Refresh this managed copy on every app build,
# including deletions, so incremental packages cannot retain retired UI resources.
if(CMAKE_BINARY_DIR STREQUAL CMAKE_SOURCE_DIR)
    message(FATAL_ERROR "Use an out-of-source build directory (cmake -S . -B build-linux).")
endif()
add_custom_target(TooieUIAssets
    COMMAND ${CMAKE_COMMAND} -E rm -rf "${CMAKE_BINARY_DIR}/assets"
    COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/assets" "${CMAKE_BINARY_DIR}/assets"
    VERBATIM
)
add_dependencies(TooieRecompiled TooieUIAssets)

# P09 backpack + player-model witnesses. Wrappers are inert unless
# TOOIE_DIAG_BACKPACK_FLAP=1 / TOOIE_DIAG_SECONDARY_SWAY=1.
# Generated functions remain untouched.
set(TOOIE_WRAPPED_SYMBOLS
    func_800D674C
    func_800DE448
    func_800DE498
    func_800E2AA4
    func_800DE2A4
    func_800DCF48
    func_800ADE2C
    func_80019AA0
    mlMtxApply
    func_800E2180
    func_800E0B8C
    func_800E0E94
    func_800AE8A8
    func_800AE820
    babackpack_entrypoint_3
    func_80098BA8
    func_80092444
    func_80092B04
)
if (WIN32)
    # lld-link /wrap:f has the GNU --wrap semantics (undefined f -> __wrap_f, __real_f -> f).
    foreach(sym IN LISTS TOOIE_WRAPPED_SYMBOLS)
        target_link_options(TooieRecompiled PRIVATE "LINKER:/wrap:${sym}")
    endforeach()
elseif (UNIX AND NOT APPLE)
    foreach(sym IN LISTS TOOIE_WRAPPED_SYMBOLS)
        target_link_options(TooieRecompiled PRIVATE "-Wl,--wrap=${sym}")
    endforeach()
endif()

# Keep controller recognition identical to the upstream DB (provenance: vendor/UPSTREAMS.tsv). Make the canonical DB
# an explicit build dependency so updates are recopied even when the executable
# itself does not need relinking.
set(TOOIE_CONTROLLER_DB "${CMAKE_CURRENT_BINARY_DIR}/recompcontrollerdb.txt")
add_custom_command(
    OUTPUT "${TOOIE_CONTROLLER_DB}"
    COMMAND ${CMAKE_COMMAND} -E copy_if_different
        "${CMAKE_SOURCE_DIR}/recompcontrollerdb.txt"
        "${TOOIE_CONTROLLER_DB}"
    DEPENDS "${CMAKE_SOURCE_DIR}/recompcontrollerdb.txt"
    VERBATIM
)
add_custom_target(TooieControllerDB DEPENDS "${TOOIE_CONTROLLER_DB}")
add_dependencies(TooieRecompiled TooieControllerDB)

# Tooie-owned launcher wordmark. The SVG is copied next to <build>/assets (<build>/ui_assets) and referenced
# from launcher_animation.cpp as "../ui_assets/TooieLogo.svg".
set(TOOIE_LAUNCHER_LOGO "${CMAKE_CURRENT_BINARY_DIR}/ui_assets/TooieLogo.svg")
add_custom_command(
    OUTPUT "${TOOIE_LAUNCHER_LOGO}"
    COMMAND ${CMAKE_COMMAND} -E copy_if_different
        "${CMAKE_SOURCE_DIR}/ui_assets/TooieLogo.svg"
        "${TOOIE_LAUNCHER_LOGO}"
    DEPENDS "${CMAKE_SOURCE_DIR}/ui_assets/TooieLogo.svg"
    VERBATIM
)
add_custom_target(TooieLauncherLogo DEPENDS "${TOOIE_LAUNCHER_LOGO}")
add_dependencies(TooieRecompiled TooieLauncherLogo)

# DXC setup (duplicated from Banjo for RT64 shaders)
set (DXC_COMMON_OPTS "-I${RT64_ROOT}/src")
if(WIN32)
    set (DXC "${RT64_ROOT}/src/contrib/dxc/bin/x64/dxc.exe")
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8 AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|AMD64")
    set (DXC "LD_LIBRARY_PATH=${RT64_ROOT}/src/contrib/dxc/lib/x64" "${RT64_ROOT}/src/contrib/dxc/bin/x64/dxc-linux")
else()
    message(FATAL_ERROR "Only x86_64 Linux/Windows DXC is vendored (arm64/macOS DXC trees were excluded, see vendor/EXCLUDES.txt)")
endif()

set_property(TARGET TooieRecompiled PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")

# PATCH 4 T15: C2AB8-shaped preemption microbenchmark. No guest ROM.
# EXCLUDE_FROM_ALL so default TooieRecompiled builds stay unchanged.
add_executable(preemption_t15
    ${CMAKE_SOURCE_DIR}/tests/preemption_t15.cpp
)
target_include_directories(preemption_t15 PRIVATE
    ${N64MR}/ultramodern/include
    ${N64MR}/include
)
target_link_libraries(preemption_t15 PRIVATE
    ultramodern
    Threads::Threads
)
set_target_properties(preemption_t15 PROPERTIES EXCLUDE_FROM_ALL TRUE)

# P08 BCF28 regression test: proves 0x800BCCC0 and 0x800BCCD8 bindings and semantics.
add_executable(bcf28_helpers_test
    ${CMAKE_SOURCE_DIR}/tests/bcf28_helpers_test.cpp
    ${CMAKE_SOURCE_DIR}/src/game/boot_hw_stubs.cpp
    ${CMAKE_SOURCE_DIR}/src/game/syscall_handler.cpp
    ${CMAKE_SOURCE_DIR}/src/game/tooie_diag.cpp
    ${CMAKE_SOURCE_DIR}/src/game/generated/overlay_dispatch.gen.cpp
)
target_include_directories(bcf28_helpers_test PRIVATE
    ${CMAKE_SOURCE_DIR}/include
    ${CMAKE_SOURCE_DIR}/src/game
    ${CMAKE_SOURCE_DIR}/RecompiledFuncs
    ${N64MR}/ultramodern/include
    ${N64MR}/librecomp/include
    ${N64MR}/N64Recomp/include
    ${N64MR}/thirdparty
    ${RT64_ROOT}/src
    ${RT64_ROOT}/src/contrib
    ${RECOMP_FRONTEND}/recompinput/include
    ${RECOMP_FRONTEND}/recompui/include
    ${RECOMP_FRONTEND}/recompui/src
    ${RECOMP_FRONTEND}/recompui/lib/RmlUi/Include
    ${SDL2_INCLUDE_DIRS}
    $<TARGET_PROPERTY:recompinput,INTERFACE_INCLUDE_DIRECTORIES>
    $<TARGET_PROPERTY:recompui,INTERFACE_INCLUDE_DIRECTORIES>
)
target_compile_options(bcf28_helpers_test PRIVATE
    -fno-strict-aliasing
    -fms-extensions
    -Wno-unused-parameter
)
target_link_libraries(bcf28_helpers_test PRIVATE
    PatchesLib
    RecompiledFuncs
    librecomp
    ultramodern
    Threads::Threads
)
set_target_properties(bcf28_helpers_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

# P08 core1 RA-wrapper regression: 0x800137D4 / 0x800137F4 / 0x80013A5C / 0x80013A7C.
add_executable(core1_ra_wrappers_test
    ${CMAKE_SOURCE_DIR}/tests/core1_ra_wrappers_test.cpp
    ${CMAKE_SOURCE_DIR}/src/game/boot_hw_stubs.cpp
    ${CMAKE_SOURCE_DIR}/src/game/syscall_handler.cpp
    ${CMAKE_SOURCE_DIR}/src/game/tooie_diag.cpp
    ${CMAKE_SOURCE_DIR}/src/game/generated/overlay_dispatch.gen.cpp
)
target_include_directories(core1_ra_wrappers_test PRIVATE
    ${CMAKE_SOURCE_DIR}/include
    ${CMAKE_SOURCE_DIR}/src/game
    ${CMAKE_SOURCE_DIR}/RecompiledFuncs
    ${N64MR}/ultramodern/include
    ${N64MR}/librecomp/include
    ${N64MR}/N64Recomp/include
    ${N64MR}/thirdparty
    ${RT64_ROOT}/src
    ${RT64_ROOT}/src/contrib
    ${RECOMP_FRONTEND}/recompinput/include
    ${RECOMP_FRONTEND}/recompui/include
    ${RECOMP_FRONTEND}/recompui/src
    ${RECOMP_FRONTEND}/recompui/lib/RmlUi/Include
    ${SDL2_INCLUDE_DIRS}
    $<TARGET_PROPERTY:recompinput,INTERFACE_INCLUDE_DIRECTORIES>
    $<TARGET_PROPERTY:recompui,INTERFACE_INCLUDE_DIRECTORIES>
)
target_compile_options(core1_ra_wrappers_test PRIVATE
    -fno-strict-aliasing
    -fms-extensions
    -Wno-unused-parameter
)
target_link_libraries(core1_ra_wrappers_test PRIVATE
    PatchesLib
    RecompiledFuncs
    librecomp
    ultramodern
    Threads::Threads
)
set_target_properties(core1_ra_wrappers_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

# P08 stick-angle secondary-entry: 0x80013B70 native shared-tail override.
add_executable(stick_angle_thunk_test
    ${CMAKE_SOURCE_DIR}/tests/stick_angle_thunk_test.cpp
    ${CMAKE_SOURCE_DIR}/src/game/boot_hw_stubs.cpp
    ${CMAKE_SOURCE_DIR}/src/game/syscall_handler.cpp
    ${CMAKE_SOURCE_DIR}/src/game/tooie_diag.cpp
    ${CMAKE_SOURCE_DIR}/src/game/generated/overlay_dispatch.gen.cpp
)
target_include_directories(stick_angle_thunk_test PRIVATE
    ${CMAKE_SOURCE_DIR}/include
    ${CMAKE_SOURCE_DIR}/src/game
    ${CMAKE_SOURCE_DIR}/RecompiledFuncs
    ${N64MR}/ultramodern/include
    ${N64MR}/librecomp/include
    ${N64MR}/N64Recomp/include
    ${N64MR}/thirdparty
    ${RT64_ROOT}/src
    ${RT64_ROOT}/src/contrib
    ${RECOMP_FRONTEND}/recompinput/include
    ${RECOMP_FRONTEND}/recompui/include
    ${RECOMP_FRONTEND}/recompui/src
    ${RECOMP_FRONTEND}/recompui/lib/RmlUi/Include
    ${SDL2_INCLUDE_DIRS}
    $<TARGET_PROPERTY:recompinput,INTERFACE_INCLUDE_DIRECTORIES>
    $<TARGET_PROPERTY:recompui,INTERFACE_INCLUDE_DIRECTORIES>
)
target_compile_options(stick_angle_thunk_test PRIVATE
    -fno-strict-aliasing
    -fms-extensions
    -Wno-unused-parameter
)
target_link_libraries(stick_angle_thunk_test PRIVATE
    PatchesLib
    RecompiledFuncs
    librecomp
    ultramodern
    Threads::Threads
)
set_target_properties(stick_angle_thunk_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

# These three tests compile boot_hw_stubs.cpp, which references the diag wrappers (__wrap_*),
# the BGM hooks, tooie_window and recompui::get_window_size: give them the same
# definitions, the same --wrap (lld-link /wrap) set (TOOIE_WRAPPED_SYMBOLS) and a window-size stub
# (the real UI library needs main.cpp's SDL window / launcher globals).
foreach(_t bcf28_helpers_test core1_ra_wrappers_test stick_angle_thunk_test)
    target_sources(${_t} PRIVATE
        ${CMAKE_SOURCE_DIR}/src/game/backpack_lookup_diag.cpp
        ${CMAKE_SOURCE_DIR}/src/game/tooie_bgm_hooks.cpp
        ${CMAKE_SOURCE_DIR}/src/game/tooie_bgm_volume.cpp
        ${CMAKE_SOURCE_DIR}/src/game/tooie_window.cpp
        ${CMAKE_SOURCE_DIR}/tests/support/recompui_window_stub.cpp
    )
    if(WIN32)
        foreach(sym IN LISTS TOOIE_WRAPPED_SYMBOLS)
            target_link_options(${_t} PRIVATE "LINKER:/wrap:${sym}")
        endforeach()
    elseif(UNIX AND NOT APPLE)
        foreach(sym IN LISTS TOOIE_WRAPPED_SYMBOLS)
            target_link_options(${_t} PRIVATE "-Wl,--wrap=${sym}")
        endforeach()
    endif()
endforeach()

# P08 matrix-submission regression: proves incremental P LOAD + V MUL equivalence and RT64 classification.
add_executable(matrix_submission_test
    ${CMAKE_SOURCE_DIR}/tests/matrix_submission_test.cpp
)
target_include_directories(matrix_submission_test PRIVATE
    ${CMAKE_SOURCE_DIR}/include
)
target_compile_options(matrix_submission_test PRIVATE
    -fno-strict-aliasing
    -Wno-unused-parameter
)
set_target_properties(matrix_submission_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

# MIPS ROUND.{W,L}.{S,D}: nearest-even must not inherit C lround* ties-away semantics.
add_executable(mips_rounding_test
    ${CMAKE_SOURCE_DIR}/tests/mips_rounding_test.cpp
)
target_include_directories(mips_rounding_test PRIVATE
    ${N64MR}/N64Recomp/include
)
target_compile_definitions(mips_rounding_test PRIVATE
    RECOMP_MIPS_ROUND_COMPAT=1
)
target_compile_options(mips_rounding_test PRIVATE
    -UNDEBUG
)
set_target_properties(mips_rounding_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

# P08 directional-input harness: real convert_to_n64_range + signed-byte + scale identity.
# Compile the runtime converter source directly so the test does not reimplement
# the mapping and does not have to link the full ultramodern archive.
add_executable(input_direction_test
    ${CMAKE_SOURCE_DIR}/tests/input_direction_test.cpp
    ${N64MR}/ultramodern/src/input.cpp
)
target_include_directories(input_direction_test PRIVATE
    ${N64MR}/ultramodern/include
    ${N64MR}/include
    ${N64MR}/N64Recomp/include
    ${N64MR}/thirdparty
    ${N64MR}/thirdparty/concurrentqueue
    ${N64MR}/thirdparty/sse2neon
)
target_compile_options(input_direction_test PRIVATE
    -fno-strict-aliasing
    -Wno-unused-parameter
)
set_target_properties(input_direction_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

# P08-T07 window & display regression test: proves display index validation, dimension sanitization, scale/DPI and aspect ratio contracts.
add_executable(window_display_test
    ${CMAKE_SOURCE_DIR}/tests/window_display_test.cpp
    ${CMAKE_SOURCE_DIR}/src/game/tooie_window.cpp
)
target_include_directories(window_display_test PRIVATE
    ${CMAKE_SOURCE_DIR}/include
    ${N64MR}/ultramodern/include
    ${N64MR}/include
    ${N64MR}/thirdparty
    ${SDL2_INCLUDE_DIRS}
)
target_compile_options(window_display_test PRIVATE
    -fno-strict-aliasing
    -Wno-unused-parameter
)
target_link_libraries(window_display_test PRIVATE
    SDL2::SDL2
)
set_target_properties(window_display_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

# Tooie menu/window policy (forced 30, window aspect sizing, Resolution enum/JSON).
add_executable(tooie_menu_policy_test
    ${CMAKE_SOURCE_DIR}/tests/tooie_menu_policy_test.cpp
)
target_include_directories(tooie_menu_policy_test PRIVATE
    ${CMAKE_SOURCE_DIR}/include
    ${N64MR}/ultramodern/include
    ${N64MR}/librecomp/include
    ${N64MR}/include
    ${N64MR}/N64Recomp/include
    ${N64MR}/thirdparty
)
set_target_properties(tooie_menu_policy_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

# Pure N64 controller port policy, independent of SDL and the runtime.
add_executable(tooie_controller_ports_test
    ${CMAKE_SOURCE_DIR}/tests/tooie_controller_ports_test.cpp
)
target_include_directories(tooie_controller_ports_test PRIVATE
    ${CMAKE_SOURCE_DIR}/include
)
set_target_properties(tooie_controller_ports_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

add_executable(recompinput_player_slots_test
    ${CMAKE_SOURCE_DIR}/tests/recompinput_player_slots_test.cpp
)
target_include_directories(recompinput_player_slots_test PRIVATE
    ${CMAKE_SOURCE_DIR}/lib/RecompFrontend/recompinput/include/recompinput
)
target_link_libraries(recompinput_player_slots_test PRIVATE recompinput SDL2::SDL2)
target_compile_definitions(recompinput_player_slots_test PRIVATE SDL_MAIN_HANDLED NOMINMAX)
set_target_properties(recompinput_player_slots_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

# Real librecomp Config integration (loaded 240 -> 30, registry reallocation, load callback, saved JSON).
add_executable(tooie_menu_config_test
    ${CMAKE_SOURCE_DIR}/tests/tooie_menu_config_test.cpp
    ${N64MR}/librecomp/src/config.cpp
    ${N64MR}/librecomp/src/config_option.cpp
)
target_include_directories(tooie_menu_config_test PRIVATE
    ${CMAKE_SOURCE_DIR}/include
    ${N64MR}/ultramodern/include
    ${N64MR}/librecomp/include
    ${N64MR}/include
    ${N64MR}/thirdparty
    ${N64MR}/thirdparty/concurrentqueue
    ${N64MR}/thirdparty/miniz
    ${N64MR}/N64Recomp/include
    ${CMAKE_BINARY_DIR}/N64ModernRuntime/librecomp/miniz
)
set_target_properties(tooie_menu_config_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

# T_INTRO projection-policy regression: proves source aspect comes from the
# cinematic matrix and rejects the old VI 304/228 compensation at 16:9.
add_executable(tintro_projection_policy_test
    ${CMAKE_SOURCE_DIR}/tests/tintro_projection_policy_test.cpp
)
target_include_directories(tintro_projection_policy_test PRIVATE
    ${CMAKE_SOURCE_DIR}/src/game
)
target_compile_options(tintro_projection_policy_test PRIVATE
    -fno-strict-aliasing
    -Wno-unused-parameter
)
set_target_properties(tintro_projection_policy_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

# Demo7 drift diagnostic: capture gate (stage0 sub8 glidx 0..120) and bs layout.
add_executable(tooie_demo7_drift_test
    ${CMAKE_SOURCE_DIR}/tests/tooie_demo7_drift_test.cpp
)
target_include_directories(tooie_demo7_drift_test PRIVATE
    ${CMAKE_SOURCE_DIR}/src/game
)
set_target_properties(tooie_demo7_drift_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

# USER_DEMO1 parity diagnostic: Tooie row layout/gate must equal the oracle hook mirror.
add_executable(tooie_demo1_parity_test
    ${CMAKE_SOURCE_DIR}/tests/tooie_demo1_parity_test.cpp
)
target_include_directories(tooie_demo1_parity_test PRIVATE
    ${CMAKE_SOURCE_DIR}/src/game
)
set_target_properties(tooie_demo1_parity_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

# USER_DEMO1 projectile diagnostic: Tooie row layout/gate must equal the oracle hook mirror.
add_executable(tooie_demo1_projectile_test
    ${CMAKE_SOURCE_DIR}/tests/tooie_demo1_projectile_test.cpp
)
target_include_directories(tooie_demo1_projectile_test PRIVATE
    ${CMAKE_SOURCE_DIR}/src/game
)
set_target_properties(tooie_demo1_projectile_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

# USER_DEMO1 target selector regression (real PAR3 s_106790 fixtures).
add_executable(tooie_demo1_target_selector_test
    ${CMAKE_SOURCE_DIR}/tests/tooie_demo1_target_selector_test.cpp
)
target_include_directories(tooie_demo1_target_selector_test PRIVATE
    ${CMAKE_SOURCE_DIR}/src/game
)
set_target_properties(tooie_demo1_target_selector_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

# USER_DEMO1 first-writer prefix layout contract (kUpd* constants).
add_executable(tooie_demo1_upd_layout_test
    ${CMAKE_SOURCE_DIR}/tests/tooie_demo1_upd_layout_test.cpp
)
target_include_directories(tooie_demo1_upd_layout_test PRIVATE
    ${CMAKE_SOURCE_DIR}/src/game
)
set_target_properties(tooie_demo1_upd_layout_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

# RT64 host endpoint-current switch (runtime interpolation toggle): header-only precedence/latch test.
add_executable(rt64_host_endpoint_current_test
    ${CMAKE_SOURCE_DIR}/tests/rt64_host_endpoint_current_test.cpp
)
target_include_directories(rt64_host_endpoint_current_test PRIVATE
    ${RT64_ROOT}/src
)
set_target_properties(rt64_host_endpoint_current_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

# RT64 below-native present decimator: host test of the header-only helper.
add_executable(rt64_present_decimator_test
    ${CMAKE_SOURCE_DIR}/tests/rt64_present_decimator_test.cpp
)
target_include_directories(rt64_present_decimator_test PRIVATE
    ${RT64_ROOT}/src
)
set_target_properties(rt64_present_decimator_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

# Top-left present-rate meter: host test of the header-only helper.
add_executable(tooie_fps_meter_test
    ${CMAKE_SOURCE_DIR}/tests/tooie_fps_meter_test.cpp
)
target_include_directories(tooie_fps_meter_test PRIVATE
    ${CMAKE_SOURCE_DIR}/include
)
set_target_properties(tooie_fps_meter_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

# P09 CPU clip helper: SPIR-V-equivalent row-vector action, offline only.
add_executable(p09_cpu_shader_clip_semantics_test
    ${CMAKE_SOURCE_DIR}/tests/p09_cpu_shader_clip_semantics.cpp
    ${RT64_ROOT}/src/common/rt64_math.cpp
)
target_include_directories(p09_cpu_shader_clip_semantics_test PRIVATE
    ${RT64_ROOT}/src
    ${RT64_ROOT}/src/contrib/hlslpp/include
)
target_compile_options(p09_cpu_shader_clip_semantics_test PRIVATE
    -fno-strict-aliasing
    -Wno-unused-parameter
)
set_target_properties(p09_cpu_shader_clip_semantics_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

# P09 exact-use pathology correlation: host test of the production RT64
# header-only classifier/key/budget helper. Offline CPU only.
add_executable(p09_exact_use_correlation_test
    ${CMAKE_SOURCE_DIR}/tests/p09_exact_use_correlation_test.cpp
)
target_include_directories(p09_exact_use_correlation_test PRIVATE
    ${RT64_ROOT}/src
)
target_compile_options(p09_exact_use_correlation_test PRIVATE
    -fno-strict-aliasing
    -Wno-unused-parameter
)
if(WIN32)
    # The test keeps large P09 tie-sample/plan structs on the stack; Linux gives the main thread 8 MiB,
    # the Windows default is 1 MiB (0xC00000FD stack overflow).
    target_link_options(p09_exact_use_correlation_test PRIVATE "LINKER:/STACK:8388608")
endif()
set_target_properties(p09_exact_use_correlation_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

# P09 PREV/CUR local-pair snapshot: host test of the header-only capture/replay.
add_executable(p09_local_pair_snapshot_test
    ${CMAKE_SOURCE_DIR}/tests/p09_local_pair_snapshot_test.cpp
)
target_include_directories(p09_local_pair_snapshot_test PRIVATE
    ${RT64_ROOT}/src
)
target_compile_options(p09_local_pair_snapshot_test PRIVATE
    -fno-strict-aliasing
    -Wno-unused-parameter
)
set_target_properties(p09_local_pair_snapshot_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

add_executable(p09_local_pair_snapshot_io_test
    ${CMAKE_SOURCE_DIR}/tests/p09_local_pair_snapshot_io_test.cpp
)
target_include_directories(p09_local_pair_snapshot_io_test PRIVATE
    ${RT64_ROOT}/src
)
target_compile_options(p09_local_pair_snapshot_io_test PRIVATE
    -fno-strict-aliasing
    -Wno-unused-parameter
)
set_target_properties(p09_local_pair_snapshot_io_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

# P09 articulated WORLD interpolation guards (translation coherence + closure guard): host test on real captured bones.
add_executable(p09_world_interpolation_guard_test
    ${CMAKE_SOURCE_DIR}/tests/p09_world_interpolation_guard_test.cpp
    ${RT64_ROOT}/src/common/rt64_math.cpp
    ${RT64_ROOT}/src/hle/rt64_rigid_body.cpp
)
target_include_directories(p09_world_interpolation_guard_test PRIVATE
    ${RT64_ROOT}/src
    ${RT64_ROOT}/src/contrib/hlslpp/include
)
target_compile_options(p09_world_interpolation_guard_test PRIVATE
    -fno-strict-aliasing
    -Wno-unused-parameter
)
set_target_properties(p09_world_interpolation_guard_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

# P09 ordered WORLD matcher: host test of the header-only rank pairing and scale gate.
add_executable(p09_ordered_match_test ${CMAKE_SOURCE_DIR}/tests/p09_ordered_match_test.cpp)
target_include_directories(p09_ordered_match_test PRIVATE ${RT64_ROOT}/src)
set_target_properties(p09_ordered_match_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

# P08 widescreen frustum: host test of the header-only plane expansion, sphere/AABB tests and census classify.
add_executable(p08_ws_frustum_test ${CMAKE_SOURCE_DIR}/tests/p08_ws_frustum_test.cpp)
target_include_directories(p08_ws_frustum_test PRIVATE ${CMAKE_SOURCE_DIR}/src/game)
set_target_properties(p08_ws_frustum_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

# P09 interpolated-frame burst (hotkey removed; capture infrastructure retained): host test of the header-only controller (miniz from the RT64 pin).
add_executable(p09_interp_burst_test
    ${CMAKE_SOURCE_DIR}/tests/p09_interp_burst_test.cpp
    ${RT64_ROOT}/src/contrib/miniz/miniz.c
)
target_include_directories(p09_interp_burst_test PRIVATE
    ${CMAKE_SOURCE_DIR}/include
    ${RT64_ROOT}/src
)
if(NOT WIN32)
    target_link_libraries(p09_interp_burst_test PRIVATE pthread)
endif()
set_target_properties(p09_interp_burst_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

# P08-T08 graphics failure regression test: proves error classification, message formatting, and simulated failure safety.
add_executable(graphics_failure_test
    ${CMAKE_SOURCE_DIR}/tests/graphics_failure_test.cpp
    ${CMAKE_SOURCE_DIR}/src/game/tooie_error.cpp
)
target_include_directories(graphics_failure_test PRIVATE
    ${CMAKE_SOURCE_DIR}/include
    ${N64MR}/ultramodern/include
    ${N64MR}/include
    ${N64MR}/thirdparty
    ${SDL2_INCLUDE_DIRS}
)
target_compile_options(graphics_failure_test PRIVATE
    -fno-strict-aliasing
    -Wno-unused-parameter
)
target_link_libraries(graphics_failure_test PRIVATE
    SDL2::SDL2
)
set_target_properties(graphics_failure_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

# P07 audio capture diagnostic. Host-only; no SDL and no guest.
add_executable(tooie_audio_capture_test
    ${CMAKE_SOURCE_DIR}/tests/tooie_audio_capture_test.cpp
    ${CMAKE_SOURCE_DIR}/src/main/tooie_audio_capture.cpp
)
target_include_directories(tooie_audio_capture_test PRIVATE
    ${CMAKE_SOURCE_DIR}/include
)
target_compile_options(tooie_audio_capture_test PRIVATE
    -fno-strict-aliasing
    -Wno-unused-parameter
)
target_link_libraries(tooie_audio_capture_test PRIVATE
    Threads::Threads
)
set_target_properties(tooie_audio_capture_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

add_executable(tooie_bgm_volume_test
    ${CMAKE_SOURCE_DIR}/tests/tooie_bgm_volume_test.cpp
    ${CMAKE_SOURCE_DIR}/src/game/tooie_bgm_volume.cpp
)
target_include_directories(tooie_bgm_volume_test PRIVATE
    ${CMAKE_SOURCE_DIR}/include
)
set_target_properties(tooie_bgm_volume_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

add_executable(tooie_bgm_hooks_test
    ${CMAKE_SOURCE_DIR}/tests/tooie_bgm_hooks_test.cpp
    ${CMAKE_SOURCE_DIR}/src/game/tooie_bgm_hooks.cpp
    ${CMAKE_SOURCE_DIR}/src/game/tooie_bgm_volume.cpp
)
target_include_directories(tooie_bgm_hooks_test PRIVATE
    ${CMAKE_SOURCE_DIR}/include
    ${N64MR}/N64Recomp/include
)
target_compile_options(tooie_bgm_hooks_test PRIVATE
    -fno-strict-aliasing
)
set_target_properties(tooie_bgm_hooks_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

# Retail cart import: decompress_tooie turns the cart (.z64 / normalised .n64) into the decompressed image and passes that image through unchanged.
# Needs a private ROM (TOOIE_ROM or <repo>/Banjo-Tooie (USA).z64); SKIPs (exit 0) without one.
add_executable(rom_cart_import_test
    ${CMAKE_SOURCE_DIR}/tests/rom_cart_import_test.cpp
    ${CMAKE_SOURCE_DIR}/src/game/rom_decompression.cpp
)
target_include_directories(rom_cart_import_test PRIVATE
    ${CMAKE_SOURCE_DIR}/include
    ${CMAKE_SOURCE_DIR}/src/game
    ${N64MR}/ultramodern/include
    ${N64MR}/librecomp/include
    ${N64MR}/include
    ${N64MR}/thirdparty
    ${N64MR}/thirdparty/concurrentqueue
    ${N64MR}/N64Recomp/include
)
target_compile_definitions(rom_cart_import_test PRIVATE XXH_INLINE_ALL)
target_link_libraries(rom_cart_import_test PRIVATE tooie_cart_decompress)
set_target_properties(rom_cart_import_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

add_executable(tooie_language_pack_test ${CMAKE_SOURCE_DIR}/tests/tooie_language_pack_test.cpp)
target_include_directories(tooie_language_pack_test PRIVATE ${CMAKE_SOURCE_DIR}/include)
set_target_properties(tooie_language_pack_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

add_executable(tooie_text_font_map_test ${CMAKE_SOURCE_DIR}/tests/tooie_text_font_map_test.cpp)
target_include_directories(tooie_text_font_map_test PRIVATE ${CMAKE_SOURCE_DIR}/include)
set_target_properties(tooie_text_font_map_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

add_executable(tooie_language_import_test ${CMAKE_SOURCE_DIR}/tests/tooie_language_import_test.cpp)
target_include_directories(tooie_language_import_test PRIVATE ${CMAKE_SOURCE_DIR}/include ${N64MR}/thirdparty/miniz ${CMAKE_BINARY_DIR}/N64ModernRuntime/librecomp/miniz)
target_link_libraries(tooie_language_import_test PRIVATE miniz)
set_target_properties(tooie_language_import_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

add_executable(tooie_font_sprite_test ${CMAKE_SOURCE_DIR}/tests/tooie_font_sprite_test.cpp)
target_include_directories(tooie_font_sprite_test PRIVATE ${CMAKE_SOURCE_DIR}/include)
set_target_properties(tooie_font_sprite_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

add_executable(tooie_language_bundle_test ${CMAKE_SOURCE_DIR}/tests/tooie_language_bundle_test.cpp)
target_include_directories(tooie_language_bundle_test PRIVATE ${CMAKE_SOURCE_DIR}/include ${N64MR}/thirdparty/miniz ${CMAKE_BINARY_DIR}/N64ModernRuntime/librecomp/miniz)
target_link_libraries(tooie_language_bundle_test PRIVATE miniz)
set_target_properties(tooie_language_bundle_test PROPERTIES EXCLUDE_FROM_ALL TRUE)

add_executable(tooie_font_preview ${CMAKE_SOURCE_DIR}/tests/tooie_font_preview.cpp)
target_include_directories(tooie_font_preview PRIVATE ${CMAKE_SOURCE_DIR}/include ${N64MR}/thirdparty/miniz ${CMAKE_BINARY_DIR}/N64ModernRuntime/librecomp/miniz)
target_link_libraries(tooie_font_preview PRIVATE miniz)
set_target_properties(tooie_font_preview PROPERTIES EXCLUDE_FROM_ALL TRUE)

add_executable(tooie_language_timing ${CMAKE_SOURCE_DIR}/tests/tooie_language_timing.cpp)
target_include_directories(tooie_language_timing PRIVATE ${CMAKE_SOURCE_DIR}/include ${N64MR}/thirdparty/miniz ${CMAKE_BINARY_DIR}/N64ModernRuntime/librecomp/miniz)
target_link_libraries(tooie_language_timing PRIVATE miniz)
set_target_properties(tooie_language_timing PROPERTIES EXCLUDE_FROM_ALL TRUE)
