add_executable(test_decoder test_decoder.cpp)
target_link_libraries(test_decoder PRIVATE gekko_isa doctest opengp_warnings)
add_test(NAME decoder COMMAND test_decoder)

add_executable(test_semantics test_semantics.cpp)
target_link_libraries(test_semantics PRIVATE ppc_runtime doctest opengp_warnings)
add_test(NAME semantics COMMAND test_semantics)

# Differential test: fixturegen writes a DOL of test functions, gekkorecomp
# recompiles it, and test_diff compares the recompiled code with the interpreter.
add_executable(fixturegen fixturegen.cpp)
target_link_libraries(fixturegen PRIVATE gekkorecomp_lib gekko_isa opengp_warnings)

set(FIXTURE_DIR ${CMAKE_CURRENT_BINARY_DIR}/fixture)
add_custom_command(
  OUTPUT ${FIXTURE_DIR}/fixture.dol ${FIXTURE_DIR}/fixture_symbols.txt ${FIXTURE_DIR}/fixture.toml
         ${FIXTURE_DIR}/fixture_cases.inc ${FIXTURE_DIR}/fixture_layout.h
  COMMAND fixturegen ${FIXTURE_DIR}
  DEPENDS fixturegen
  COMMENT "Generating the differential-test fixture"
  VERBATIM)

add_executable(test_diff test_diff.cpp
  ${FIXTURE_DIR}/fixture_cases.inc ${FIXTURE_DIR}/fixture_layout.h)
opengp_recompile(test_diff
  CONFIG ${FIXTURE_DIR}/fixture.toml
  FILE_COUNT 4
  OUTPUT_DIR ${FIXTURE_DIR}/generated
  DEPENDS ${FIXTURE_DIR}/fixture.dol ${FIXTURE_DIR}/fixture_symbols.txt)
target_include_directories(test_diff PRIVATE ${FIXTURE_DIR})
target_compile_definitions(test_diff PRIVATE
  FIXTURE_DOL="${FIXTURE_DIR}/fixture.dol"
  FIXTURE_GENERATED="${FIXTURE_DIR}/generated")
target_link_libraries(test_diff PRIVATE ppc_runtime doctest opengp_warnings)
add_test(NAME diff COMMAND test_diff)

add_executable(test_recomp_inputs test_recomp_inputs.cpp)
target_link_libraries(test_recomp_inputs PRIVATE gekkorecomp_lib doctest opengp_warnings)
add_test(NAME recomp_inputs COMMAND test_recomp_inputs)

add_executable(test_input test_input.cpp)
target_link_libraries(test_input PRIVATE opengp_machine doctest opengp_warnings)
add_test(NAME input COMMAND test_input)

add_executable(test_dsp test_dsp.cpp)
target_link_libraries(test_dsp PRIVATE opengp_machine doctest opengp_warnings)
add_test(NAME dsp COMMAND test_dsp)

add_executable(test_pause test_pause.cpp)
target_link_libraries(test_pause PRIVATE opengp_machine doctest opengp_warnings)
add_test(NAME pause COMMAND test_pause)

add_executable(test_disc test_disc.cpp)
target_link_libraries(test_disc PRIVATE opengp_machine doctest opengp_warnings)
add_test(NAME disc COMMAND test_disc)

add_executable(test_texture test_texture.cpp)
target_link_libraries(test_texture PRIVATE opengp_machine doctest opengp_warnings)
add_test(NAME texture COMMAND test_texture)

add_executable(test_vertex_pipeline test_vertex_pipeline.cpp)
target_link_libraries(test_vertex_pipeline PRIVATE opengp_machine doctest opengp_warnings)
add_test(NAME vertex_pipeline COMMAND test_vertex_pipeline)

add_executable(test_text test_text.cpp)
target_link_libraries(test_text PRIVATE opengp_machine doctest opengp_warnings)
add_test(NAME text COMMAND test_text)

add_executable(test_settings test_settings.cpp)
target_link_libraries(test_settings PRIVATE opengp_settings doctest opengp_warnings)
add_test(NAME settings COMMAND test_settings)

add_executable(test_performance test_performance.cpp ../runtime/app/profiler.cpp)
target_include_directories(test_performance PRIVATE ../runtime)
target_link_libraries(test_performance PRIVATE gekko_isa doctest opengp_warnings)
add_test(NAME performance COMMAND test_performance)

add_executable(test_menu_back test_menu_back.cpp ../games/common/menu_back.cpp)
target_include_directories(test_menu_back PRIVATE ../games/common)
target_link_libraries(test_menu_back PRIVATE ppc_runtime doctest opengp_warnings)
add_test(NAME menu_back COMMAND test_menu_back)

if(TARGET opengp_input)
  add_executable(test_controls test_controls.cpp)
  target_link_libraries(test_controls PRIVATE opengp_input doctest opengp_warnings)
  add_test(NAME controls COMMAND test_controls)
endif()

if(TARGET opengp_audio)
  add_executable(test_audio test_audio.cpp)
  target_link_libraries(test_audio PRIVATE opengp_audio doctest opengp_warnings)
  add_test(NAME audio COMMAND test_audio)
endif()

add_executable(test_camera test_camera.cpp)
target_link_libraries(test_camera PRIVATE opengp_machine doctest opengp_warnings)
add_test(NAME camera COMMAND test_camera)

add_executable(test_discord test_discord.cpp)
target_link_libraries(test_discord PRIVATE opengp_discord doctest opengp_warnings)
add_test(NAME discord COMMAND test_discord)

add_executable(test_link test_link.cpp)
target_link_libraries(test_link PRIVATE opengp_machine doctest opengp_warnings)
add_test(NAME link COMMAND test_link)

add_executable(test_paths test_paths.cpp)
target_link_libraries(test_paths PRIVATE opengp_settings gekkorecomp_lib doctest opengp_warnings)
add_test(NAME paths COMMAND test_paths)

add_executable(test_installer test_installer.cpp)
target_link_libraries(test_installer PRIVATE opengp_installer_lib doctest opengp_warnings)
if(WIN32)
  target_link_libraries(test_installer PRIVATE ws2_32)
endif()
add_test(NAME installer COMMAND test_installer)
# The download tests' server is on this computer: curl must not send its requests to a proxy.
set_tests_properties(installer PROPERTIES ENVIRONMENT "no_proxy=127.0.0.1;NO_PROXY=127.0.0.1")

# Crash reports: a probe crashes in several ways; each must leave a report.
add_executable(crash_probe crash_probe.cpp)
target_link_libraries(crash_probe PRIVATE opengp_machine opengp_warnings)
add_test(NAME crash_reports
         COMMAND ${CMAKE_COMMAND} -DPROBE=$<TARGET_FILE:crash_probe> -DDIR=${CMAKE_CURRENT_BINARY_DIR}/crash_reports
                 -P ${CMAKE_CURRENT_SOURCE_DIR}/check_crash.cmake)
set_tests_properties(crash_reports PROPERTIES ENVIRONMENT "OPENGP_NO_CRASH_DIALOG=1")
