IF (BUILD_TESTING)

    # Each test links the shared libraries built under src/ (kat_core,
    # kat_interface, kat_minizip).  kat_interface PUBLIC-propagates core,
    # minizip, SDL3, zlib and the KAT_DATADIR define, so a single
    # link line covers the heavier tests.  Static libraries resolve lazily,
    # so each test only pulls the objects it actually references.
    #
    # GUI and top-level (main/run_system) symbols live only in the binary, so
    # tests that touch the interface layer provide test_support_stubs.c.

    # toml is intentionally dependency-free: compile the one source directly
    # rather than dragging in the whole interface library + SDL.
    add_executable(test_toml test_toml.c ${CMAKE_SOURCE_DIR}/src/interface/toml.c)

    add_executable(test_cpu test_cpu.c)
    target_link_libraries(test_cpu kat_core)

    add_executable(test_pokey_timer test_pokey_timer.c)
    target_link_libraries(test_pokey_timer kat_core)

    add_executable(test_gtia test_gtia.c)
    target_link_libraries(test_gtia kat_core)

    add_executable(test_states test_states.c)
    target_link_libraries(test_states kat_interface)

    add_executable(test_input test_input.c test_support_stubs.c)
    target_link_libraries(test_input kat_interface)

    add_executable(test_config_ui_input test_config_ui_input.c test_support_stubs.c)
    target_link_libraries(test_config_ui_input kat_interface)

    add_executable(test_media test_media.c test_support_stubs.c)
    target_link_libraries(test_media kat_interface)

    add_executable(test_profile_seed test_profile_seed.c)
    target_link_libraries(test_profile_seed kat_interface)

    add_executable(test_manual_uri test_manual_uri.c)
    target_link_libraries(test_manual_uri kat_interface)

    add_executable(test_shader_config test_shader_config.c test_support_stubs.c)
    target_link_libraries(test_shader_config kat_interface)
    target_compile_definitions(test_shader_config PRIVATE
        KAT_SOURCE_DIR="${CMAKE_SOURCE_DIR}")

    add_executable(test_palette test_palette.c test_support_stubs.c)
    target_link_libraries(test_palette kat_interface)

    add_executable(test_args test_args.c test_support_stubs.c)
    target_link_libraries(test_args kat_interface)

    add_executable(test_window_geometry test_window_geometry.c test_support_stubs.c)
    target_link_libraries(test_window_geometry kat_interface)

    add_executable(test_rom_browser_start_dir test_rom_browser_start_dir.c test_support_stubs.c)
    target_link_libraries(test_rom_browser_start_dir kat_interface)

    ADD_TEST( toml test_toml kat5200.conf )
    ADD_TEST( states1 test_states 5200 )
    ADD_TEST( states2 test_states 800 )
    ADD_TEST( states3 test_states XL )
    ADD_TEST( input1 test_input 5200 )
    ADD_TEST( input2 test_input 800 )
    ADD_TEST( config_ui_input test_config_ui_input )
    ADD_TEST( media test_media )
    ADD_TEST( media_hybrid test_media hybrid )
    ADD_TEST( profile_seed test_profile_seed )
    ADD_TEST( manual_uri test_manual_uri )
    ADD_TEST( shader_config test_shader_config )
    ADD_TEST( palette test_palette )
    ADD_TEST( args test_args )
    ADD_TEST( window_geometry test_window_geometry )
    ADD_TEST( rom_browser_start_dir test_rom_browser_start_dir )
    ADD_TEST( cpu1 test_cpu 6502_functional_test.bin )
    ADD_TEST( pokey_timer test_pokey_timer )
    ADD_TEST( gtia test_gtia )

    # Stage the test data into the build tree at configure time so tests run
    # against build/tests/ and never write back into the source tree.
    file(COPY
            kat5200.conf
            6502_functional_test.bin
            roms
            profiles.5200
            profiles.8bit
        DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

ENDIF(BUILD_TESTING)
