# ClayTality 64 Windows integration by djultra64.
cmake_minimum_required(VERSION 3.20)
project(ClayTality64Windows LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 20)
get_filename_component(CLAY_ROOT "${CMAKE_CURRENT_LIST_DIR}/../.." ABSOLUTE)
set(RUNTIME "${CLAY_RUNTIME}" CACHE PATH "Pinned N64ModernRuntime source")
set(RT64 "${CLAY_RT64}" CACHE PATH "Pinned RT64 source")
set(RT64_BUILD "${CLAY_RT64_BUILD}" CACHE PATH "Matching Windows RT64 build")
set(SDL "${CLAY_SDL}" CACHE PATH "SDL2 developer package")
if(NOT MSVC)
 message(FATAL_ERROR "This isolated build is for MSVC x64")
endif()
add_compile_definitions(NOMINMAX SDL_MAIN_HANDLED)
add_subdirectory("${RUNTIME}/ultramodern" "${CMAKE_BINARY_DIR}/ultramodern")
set_property(TARGET ultramodern PROPERTY COMPILE_OPTIONS "")
get_target_property(UM_SRC ultramodern SOURCES)
list(FILTER UM_SRC EXCLUDE REGEX "/threadqueue[.]cpp$")
list(APPEND UM_SRC "${CLAY_ROOT}/generated/threadqueue_trace.cpp")
set_property(TARGET ultramodern PROPERTY SOURCES "${UM_SRC}")
file(READ "${RUNTIME}/librecomp/src/ultra_translation.cpp" TRANSLATION)
foreach(SYMBOL osStartThread_recomp osStopThread_recomp)
 string(REPLACE "void ${SYMBOL}(" "void __real_${SYMBOL}(" TRANSLATION "${TRANSLATION}")
endforeach()
file(WRITE "${CMAKE_BINARY_DIR}/ultra_translation_windows.cpp" "${TRANSLATION}")
file(GLOB GUEST "${CLAY_ROOT}/generated/guest/funcs_*.c")
file(GLOB HOST "${CLAY_ROOT}/host/*.cpp")
set_source_files_properties(${GUEST} PROPERTIES LANGUAGE CXX COMPILE_OPTIONS "/w;/O1;/FI${CLAY_ROOT}/host/guest_support.h")
set_source_files_properties("${CLAY_ROOT}/host/runtime.cpp" PROPERTIES COMPILE_DEFINITIONS "__wrap_osStartThread_recomp=osStartThread_recomp;__wrap_osStopThread_recomp=osStopThread_recomp")
add_executable(claytality64 ${HOST} ${GUEST} "${CLAY_ROOT}/generated/graphics_workload_queue.cpp" "${CLAY_ROOT}/generated/fallbacks.cpp" "${CLAY_ROOT}/generated/audio.cpp" "${CMAKE_BINARY_DIR}/ultra_translation_windows.cpp" "${RUNTIME}/librecomp/src/rsp.cpp" "${RUNTIME}/librecomp/src/cont.cpp" "${RUNTIME}/librecomp/src/vi.cpp")
target_compile_options(claytality64 PRIVATE /bigobj /EHs /Zc:preprocessor "/FI${CMAKE_CURRENT_LIST_DIR}/windows_headers.h")
target_compile_definitions(claytality64 PRIVATE HLSL_CPU IMGUI_IMPL_VULKAN_NO_PROTOTYPES)
target_include_directories(claytality64 PRIVATE "${CLAY_ROOT}/host" "${CLAY_ROOT}/generated/guest" "${RUNTIME}/N64Recomp/include" "${RUNTIME}/ultramodern/include" "${RUNTIME}/librecomp/include" "${RUNTIME}/librecomp/include/librecomp" "${RUNTIME}/thirdparty" "${RUNTIME}/thirdparty/concurrentqueue" "${RUNTIME}/thirdparty/json" "${SDL}/include")
foreach(INC src src/hle src/contrib src/contrib/json src/contrib/volk src/contrib/hlslpp/include src/contrib/imgui src/contrib/mupen64plus-core/src/api src/contrib/plume src/contrib/plume/contrib/volk src/contrib/plume/contrib/Vulkan-Headers/include src/contrib/plume/contrib/VulkanMemoryAllocator/include)
 target_include_directories(claytality64 PRIVATE "${RT64}/${INC}")
endforeach()
target_link_libraries(claytality64 PRIVATE ultramodern "${RT64_BUILD}/rt64/Release/rt64.lib" "${RT64_BUILD}/rt64/src/contrib/plume/Release/plume.lib" "${RT64_BUILD}/rt64/src/contrib/re-spirv/Release/re-spirv.lib" "${RT64_BUILD}/rt64/src/contrib/nativefiledialog-extended/src/Release/nfd.lib" "${RT64_BUILD}/rt64/src/contrib/zstd/build/cmake/lib/Release/zstd_static.lib" "${SDL}/lib/x64/SDL2.lib" d3d12 dxgi dxguid user32 shell32 ole32 comdlg32 uuid winmm shcore delayimp "${RT64}/src/contrib/dxc/lib/x64/dxcompiler.lib")
add_custom_command(TARGET claytality64 POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "${RT64_BUILD}/Release/SDL2.dll" "${RT64_BUILD}/Release/dxcompiler.dll" "${RT64_BUILD}/Release/dxil.dll" "$<TARGET_FILE_DIR:claytality64>")
enable_testing()
if(EXISTS "${CLAY_ROOT}/generated/windows_training_position_guest.cpp")
 add_executable(training_position_test "${CLAY_ROOT}/tests/training_position.cpp" "${CLAY_ROOT}/generated/windows_training_position_guest.cpp" "${CLAY_ROOT}/host/training_position.cpp")
 target_include_directories(training_position_test PRIVATE "${CLAY_ROOT}/host" "${RUNTIME}/N64Recomp/include")
 target_compile_options(training_position_test PRIVATE /UNDEBUG /EHs)
 add_test(NAME training_native_position COMMAND training_position_test)
endif()

if(EXISTS "${CLAY_ROOT}/generated/windows_training_selector_guest.cpp")
 add_executable(training_selector_test "${CLAY_ROOT}/tests/training_selector.cpp" "${CLAY_ROOT}/generated/windows_training_selector_guest.cpp")
 target_include_directories(training_selector_test PRIVATE "${CLAY_ROOT}/host" "${RUNTIME}/N64Recomp/include")
 target_compile_options(training_selector_test PRIVATE /UNDEBUG /EHs)
 add_test(NAME training_native_selector COMMAND training_selector_test)
endif()
if(EXISTS "${CLAY_ROOT}/generated/windows_training_moves_markers.cpp")
 add_executable(training_moves_test "${CLAY_ROOT}/tests/training_moves.cpp" "${CLAY_ROOT}/host/move_list.cpp" "${CLAY_ROOT}/generated/windows_training_moves_markers.cpp")
 target_include_directories(training_moves_test PRIVATE "${CLAY_ROOT}/host" "${RUNTIME}/N64Recomp/include")
 target_compile_options(training_moves_test PRIVATE /UNDEBUG /EHs)
 add_test(NAME training_native_moves COMMAND training_moves_test)
endif()

if(EXISTS "${CLAY_ROOT}/generated/windows_training_stage_guest.cpp")
 add_executable(training_stage_test "${CLAY_ROOT}/tests/training_stage.cpp" "${CLAY_ROOT}/generated/windows_training_stage_guest.cpp" "${CLAY_ROOT}/host/training_stage.cpp")
 target_include_directories(training_stage_test PRIVATE "${CLAY_ROOT}/host" "${RUNTIME}/N64Recomp/include")
 target_compile_options(training_stage_test PRIVATE /UNDEBUG /EHs)
 add_test(NAME training_native_stage COMMAND training_stage_test "${CMAKE_CURRENT_BINARY_DIR}/training-stage.cfg")
endif()

add_executable(training_menu_ui_test "${CLAY_ROOT}/tests/training_menu_ui.cpp" "${CLAY_ROOT}/host/training_options.cpp" "${CLAY_ROOT}/host/training_hud.cpp")
target_include_directories(training_menu_ui_test PRIVATE "${CLAY_ROOT}/host" "${RUNTIME}/N64Recomp/include" "${RUNTIME}/librecomp/include")
target_compile_options(training_menu_ui_test PRIVATE /UNDEBUG /EHs)
add_test(NAME training_native_menu COMMAND training_menu_ui_test)
if(EXISTS "${CLAY_ROOT}/generated/windows_training_guest.cpp")
 add_executable(training_guest_test "${CLAY_ROOT}/tests/training_guest.cpp" "${CLAY_ROOT}/generated/windows_training_guest.cpp" "${CLAY_ROOT}/host/training_guest.cpp" "${CLAY_ROOT}/host/training_position.cpp" "${CLAY_ROOT}/host/training_session.cpp" "${CLAY_ROOT}/host/training_preferences.cpp" "${CLAY_ROOT}/host/main_menu.cpp")
 target_include_directories(training_guest_test PRIVATE "${CLAY_ROOT}/host" "${RUNTIME}/N64Recomp/include")
 target_compile_options(training_guest_test PRIVATE /UNDEBUG /EHs)
 add_test(NAME training_original_contract COMMAND training_guest_test "${CLAY_ROOT}/probe-output/base.z64")
 add_test(NAME training_active_contract COMMAND training_guest_test "${CLAY_ROOT}/probe-output/base.z64" training)
endif()

add_executable(training_options_test "${CLAY_ROOT}/tests/training_options.cpp" "${CLAY_ROOT}/host/training_preferences.cpp")
target_include_directories(training_options_test PRIVATE "${CLAY_ROOT}/host")
target_compile_options(training_options_test PRIVATE /UNDEBUG /EHs)
add_test(NAME training_options_persistence COMMAND training_options_test "${CMAKE_CURRENT_BINARY_DIR}/training-options.cfg")
add_executable(training_session_test "${CLAY_ROOT}/tests/training_session.cpp" "${CLAY_ROOT}/host/training_session.cpp")
target_include_directories(training_session_test PRIVATE "${CLAY_ROOT}/host")
target_compile_options(training_session_test PRIVATE /UNDEBUG /EHs)
add_test(NAME training_session_rules COMMAND training_session_test)
add_executable(portable_paths_test "${CLAY_ROOT}/tests/portable_paths.cpp" "${CLAY_ROOT}/host/portable_paths.cpp")
target_include_directories(portable_paths_test PRIVATE "${CLAY_ROOT}/host")
target_compile_options(portable_paths_test PRIVATE /UNDEBUG /EHs)
add_test(NAME portable_settings_paths COMMAND portable_paths_test)
foreach(CASE graphics_config input)
 add_executable(${CASE}_test "${CLAY_ROOT}/tests/${CASE}.cpp" "${CLAY_ROOT}/host/${CASE}.cpp")
 target_include_directories(${CASE}_test PRIVATE "${CLAY_ROOT}/host")
 target_compile_options(${CASE}_test PRIVATE /UNDEBUG)
 add_test(NAME ${CASE} COMMAND ${CASE}_test)
endforeach()
add_executable(thread_lifecycle_test "${CLAY_ROOT}/tests/thread_lifecycle.cpp" "${CLAY_ROOT}/generated/threadqueue_trace.cpp")
target_include_directories(thread_lifecycle_test PRIVATE "${CLAY_ROOT}/host" "${RUNTIME}/ultramodern/include" "${RUNTIME}/thirdparty" "${RUNTIME}/thirdparty/concurrentqueue")
foreach(CASE stop stop_nonhead stop_running remove)
 add_test(NAME thread_${CASE} COMMAND thread_lifecycle_test ${CASE})
endforeach()
add_executable(sdl_input_test "${CLAY_ROOT}/tests/input_sdl.cpp" "${CLAY_ROOT}/host/input.cpp" "${CLAY_ROOT}/host/input_sdl.cpp")
target_include_directories(sdl_input_test PRIVATE "${CLAY_ROOT}/host" "${SDL}/include")
target_compile_options(sdl_input_test PRIVATE /UNDEBUG)
target_link_libraries(sdl_input_test PRIVATE "${SDL}/lib/x64/SDL2.lib")
add_custom_command(TARGET sdl_input_test POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "${RT64_BUILD}/Release/SDL2.dll" "$<TARGET_FILE_DIR:sdl_input_test>")
add_test(NAME sdl_input COMMAND sdl_input_test)
set_tests_properties(sdl_input PROPERTIES ENVIRONMENT "SDL_VIDEODRIVER=dummy;SDL_AUDIODRIVER=dummy")
add_executable(async_resource_wait_test "${CLAY_ROOT}/tests/async_resource_wait.cpp" "${CLAY_ROOT}/generated/windows_wait_guest.cpp" "${CLAY_ROOT}/generated/threadqueue_trace.cpp" "${RUNTIME}/ultramodern/src/threads.cpp" "${RUNTIME}/ultramodern/src/scheduling.cpp" "${RUNTIME}/ultramodern/src/mesgqueue.cpp")
target_compile_options(async_resource_wait_test PRIVATE /Gy)
target_link_options(async_resource_wait_test PRIVATE /OPT:REF)
target_include_directories(async_resource_wait_test PRIVATE "${CLAY_ROOT}/host" "${RUNTIME}/N64Recomp/include" "${RUNTIME}/ultramodern/include" "${RUNTIME}/thirdparty" "${RUNTIME}/thirdparty/concurrentqueue")
add_test(NAME framebuffer_wait_green COMMAND async_resource_wait_test yield)
set_tests_properties(framebuffer_wait_green PROPERTIES TIMEOUT 5)
add_executable(native_prompts_test "${CLAY_ROOT}/tests/native_prompts.cpp" "${CLAY_ROOT}/host/native_prompts.cpp" "${CLAY_ROOT}/host/input.cpp" "${CLAY_ROOT}/host/input_hud.cpp" "${CLAY_ROOT}/generated/windows_native_font_guest.cpp" "${CLAY_ROOT}/generated/windows_native_font_cleanup_guest.cpp" "${CMAKE_CURRENT_LIST_DIR}/stb.cpp")
target_include_directories(native_prompts_test PRIVATE "${CLAY_ROOT}/host" "${CLAY_ROOT}/generated/guest" "${RUNTIME}/N64Recomp/include" "${RUNTIME}/thirdparty/json" "${RT64}/src/contrib")
target_compile_options(native_prompts_test PRIVATE /UNDEBUG /EHs)
add_test(NAME native_game_font_prompts COMMAND native_prompts_test)
set_tests_properties(native_game_font_prompts PROPERTIES WORKING_DIRECTORY "${CLAY_ROOT}")
add_executable(sc_asset_scope_test "${CLAY_ROOT}/tests/sc_assets.cpp" "${CLAY_ROOT}/host/sc_assets.cpp")
target_include_directories(sc_asset_scope_test PRIVATE "${CLAY_ROOT}/host" "${RUNTIME}/N64Recomp/include")
target_compile_options(sc_asset_scope_test PRIVATE /EHs)
add_test(NAME sc_asset_scope COMMAND sc_asset_scope_test "${CLAY_ROOT}/analysis/sc_assets/asset-image.z64")
if(EXISTS "${CLAY_ROOT}/local/sc_roster/guest.cpp")
 add_executable(sc_roster_test "${CLAY_ROOT}/tests/sc_roster.cpp" "${CLAY_ROOT}/host/sc_assets.cpp" "${CLAY_ROOT}/host/sc_roster.cpp" "${CLAY_ROOT}/local/sc_roster/guest.cpp")
 target_include_directories(sc_roster_test PRIVATE "${CLAY_ROOT}/host" "${CLAY_ROOT}/generated/guest" "${RUNTIME}/N64Recomp/include")
 target_compile_options(sc_roster_test PRIVATE /EHs /bigobj)
 add_test(NAME sc_roster_native COMMAND sc_roster_test "${CLAY_ROOT}/local/sc_roster/asset-image-roster.z64" "${CLAY_ROOT}/probe-output/base.z64")
 set_tests_properties(sc_roster_native PROPERTIES WORKING_DIRECTORY "${CLAY_ROOT}" TIMEOUT 30)
endif()
if(EXISTS "${CLAY_ROOT}/host/port_options.cpp")
 file(READ "${CLAY_ROOT}/tests/options.cpp" OPTIONS_TEST)
 string(REPLACE "/tmp/clay-options-fixture.cfg" "${CMAKE_BINARY_DIR}/clay-options-fixture.cfg" OPTIONS_TEST "${OPTIONS_TEST}")
 file(WRITE "${CMAKE_BINARY_DIR}/options_windows.cpp" "${OPTIONS_TEST}")
 add_executable(native_options_test "${CMAKE_BINARY_DIR}/options_windows.cpp" "${CLAY_ROOT}/host/port_options.cpp" "${CLAY_ROOT}/host/graphics_config.cpp" "${CLAY_ROOT}/generated/windows_native_font_guest.cpp" "${CLAY_ROOT}/generated/windows_options_letters_guest.cpp")
 target_include_directories(native_options_test PRIVATE "${CLAY_ROOT}/host" "${CLAY_ROOT}/generated/guest" "${RUNTIME}/N64Recomp/include")
 target_compile_options(native_options_test PRIVATE /UNDEBUG /EHs)
 add_test(NAME native_options COMMAND native_options_test "${CLAY_ROOT}/analysis/font_private/font.bin" "${CLAY_ROOT}/probe-output/base.z64")
endif()
if(EXISTS "${CLAY_ROOT}/generated/sc_dispatch_compare/base.cpp" AND EXISTS "${CLAY_ROOT}/generated/sc_dispatch_compare/guest/funcs_0.c")
 set_source_files_properties("${CLAY_ROOT}/generated/sc_dispatch_compare/guest/funcs_0.c" PROPERTIES LANGUAGE CXX)
 add_executable(sc_combat_dispatch_test "${CLAY_ROOT}/tests/sc_combat_dispatch.cpp" "${CLAY_ROOT}/generated/sc_dispatch_compare/base.cpp" "${CLAY_ROOT}/generated/sc_dispatch_compare/guest/funcs_0.c")
 target_include_directories(sc_combat_dispatch_test PRIVATE "${RUNTIME}/N64Recomp/include")
 target_compile_definitions(sc_combat_dispatch_test PRIVATE CLAY_COMPARE_SC)
 target_compile_options(sc_combat_dispatch_test PRIVATE /EHs /bigobj)
 foreach(ID 3 6 11 12 16)
  if(ID EQUAL 3)
   set(DEFINITION "base_3.decoded")
  else()
   set(DEFINITION "sc_${ID}.decoded")
  endif()
  add_test(NAME sc_dispatch_${ID} COMMAND sc_combat_dispatch_test "${CLAY_ROOT}/analysis/sc_assets/${DEFINITION}")
 endforeach()
 add_test(NAME sc_dispatch_wrong_frosty COMMAND sc_combat_dispatch_test "${CLAY_ROOT}/analysis/sc_assets/sc_6.decoded" "${CLAY_ROOT}/analysis/sc_assets/base_0.decoded")
 set_tests_properties(sc_dispatch_wrong_frosty PROPERTIES WILL_FAIL TRUE)
endif()
foreach(CASE body guards payload)
 if(CASE STREQUAL "body")
  set(TEST_SOURCE "${CLAY_ROOT}/tests/interpolation_body.cpp")
  set(TEST_GUEST "${CLAY_ROOT}/generated/windows_interpolation_body.cpp")
 elseif(CASE STREQUAL "payload")
  set(TEST_SOURCE "${CLAY_ROOT}/tests/interpolation_payload.cpp")
  set(TEST_GUEST "${CLAY_ROOT}/generated/windows_interpolation_payload.cpp")
 else()
  set(TEST_SOURCE "${CLAY_ROOT}/tests/interpolation.cpp")
  set(TEST_GUEST "")
 endif()
 add_executable(interpolation_${CASE}_test ${TEST_SOURCE} ${TEST_GUEST})
 if(CASE STREQUAL "payload")
  target_sources(interpolation_${CASE}_test PRIVATE "${CLAY_ROOT}/host/sprite_seams.cpp")
 endif()
 if(NOT CASE STREQUAL "payload")
  target_sources(interpolation_${CASE}_test PRIVATE "${CLAY_ROOT}/host/interpolation.cpp" "${CLAY_ROOT}/host/graphics_config.cpp")
 endif()
 target_include_directories(interpolation_${CASE}_test PRIVATE "${CLAY_ROOT}/host" "${CLAY_ROOT}/generated/guest" "${RUNTIME}/N64Recomp/include")
 target_compile_options(interpolation_${CASE}_test PRIVATE /UNDEBUG /EHs /bigobj)
 add_test(NAME interpolation_${CASE} COMMAND interpolation_${CASE}_test)
endforeach()
add_executable(input_two_player_test "${CLAY_ROOT}/tests/input_two_player.cpp" "${CLAY_ROOT}/host/input.cpp" "${CLAY_ROOT}/host/input_sdl.cpp")
target_include_directories(input_two_player_test PRIVATE "${CLAY_ROOT}/host" "${SDL}/include")
target_compile_options(input_two_player_test PRIVATE /UNDEBUG /EHs)
target_link_libraries(input_two_player_test PRIVATE "${SDL}/lib/x64/SDL2.lib")
add_test(NAME two_player_controller_routing COMMAND input_two_player_test)
set_tests_properties(two_player_controller_routing PROPERTIES ENVIRONMENT "SDL_VIDEODRIVER=dummy;SDL_AUDIODRIVER=dummy")
add_executable(test_input_driver_test "${CLAY_ROOT}/tests/test_input.cpp" "${CLAY_ROOT}/host/test_input.cpp")
target_include_directories(test_input_driver_test PRIVATE "${CLAY_ROOT}/host" "${SDL}/include" "${RUNTIME}/thirdparty/json")
target_compile_options(test_input_driver_test PRIVATE /UNDEBUG /EHs)
target_link_libraries(test_input_driver_test PRIVATE "${SDL}/lib/x64/SDL2.lib")
add_test(NAME two_player_validation_driver COMMAND test_input_driver_test "${CMAKE_BINARY_DIR}/two-player-input.json")
set_tests_properties(two_player_validation_driver PROPERTIES ENVIRONMENT "SDL_VIDEODRIVER=dummy;SDL_AUDIODRIVER=dummy")
# Final original native allocator/UI/sound/VS regressions, by djultra64.
foreach(CASE memory_budget ui_background options_border sc_sound)
 if(CASE STREQUAL "memory_budget")
  set(GUEST_NAME memory_budget)
 elseif(CASE STREQUAL "sc_sound")
  set(GUEST_NAME sound)
 else()
  set(GUEST_NAME ${CASE})
 endif()
 add_executable(${CASE}_native_test "${CLAY_ROOT}/tests/${CASE}.cpp" "${CLAY_ROOT}/generated/windows_${GUEST_NAME}_guest.cpp")
 if(NOT CASE STREQUAL "sc_sound")
  target_sources(${CASE}_native_test PRIVATE "${CLAY_ROOT}/host/${CASE}.cpp")
 endif()
 if(CASE STREQUAL "ui_background")
  target_sources(${CASE}_native_test PRIVATE "${CLAY_ROOT}/host/graphics_config.cpp")
 endif()
 target_include_directories(${CASE}_native_test PRIVATE "${CLAY_ROOT}/host" "${CLAY_ROOT}/generated/guest" "${RUNTIME}/N64Recomp/include")
 target_compile_options(${CASE}_native_test PRIVATE /UNDEBUG /EHs /bigobj)
 if(CASE STREQUAL "ui_background")
  add_test(NAME ${CASE}_native COMMAND ${CASE}_native_test "${CLAY_ROOT}/probe-output/base.z64" "${CLAY_ROOT}/local/sc_roster/mesh-rdram.bin")
 elseif(CASE STREQUAL "sc_sound")
  add_test(NAME ${CASE}_native COMMAND ${CASE}_native_test "${CLAY_ROOT}/probe-output/base.z64")
 else()
  add_test(NAME ${CASE}_native COMMAND ${CASE}_native_test)
 endif()
endforeach()
add_executable(vs_alignment_native_test "${CLAY_ROOT}/tests/vs_alignment.cpp" "${CLAY_ROOT}/host/vs_alignment.cpp" "${CLAY_ROOT}/host/sc_assets.cpp" "${CLAY_ROOT}/generated/windows_vs_alignment_guest.cpp")
target_include_directories(vs_alignment_native_test PRIVATE "${CLAY_ROOT}/host" "${CLAY_ROOT}/generated/guest" "${RUNTIME}/N64Recomp/include")
target_compile_options(vs_alignment_native_test PRIVATE /UNDEBUG /EHs /bigobj)
foreach(ID 1 2 3 4 5 8 9 13 14 15 6 11 12 16)
 if(ID EQUAL 6 OR ID EQUAL 11 OR ID EQUAL 12 OR ID EQUAL 16)
  set(VS_ROM "${CLAY_ROOT}/analysis/sc_assets/asset-image.z64")
 else()
  set(VS_ROM "${CLAY_ROOT}/probe-output/base.z64")
 endif()
 add_test(NAME vs_alignment_${ID} COMMAND vs_alignment_native_test "${VS_ROM}" ${ID})
endforeach()

# User-provided private title announcement; djultra64.
add_executable(title_audio_test "${CLAY_ROOT}/tests/title_audio.cpp" "${CLAY_ROOT}/host/title_audio.cpp")
add_executable(title_audio_native_test "${CLAY_ROOT}/tests/title_audio_native.cpp" "${CLAY_ROOT}/host/title_audio.cpp" "${CLAY_ROOT}/generated/windows_title_audio_guest.cpp")
foreach(TARGET title_audio_test title_audio_native_test)
 target_include_directories(${TARGET} PRIVATE "${CLAY_ROOT}/host" "${CLAY_ROOT}/generated/guest" "${RUNTIME}/N64Recomp/include")
 target_compile_options(${TARGET} PRIVATE /UNDEBUG /EHs /bigobj)
endforeach()
add_test(NAME title_audio_dsp COMMAND title_audio_test "${CMAKE_BINARY_DIR}/title-audio-fixture.pcm")
add_test(NAME title_audio_native COMMAND title_audio_native_test "${CLAY_ROOT}/probe-output/base.z64" "${CLAY_ROOT}/local/audio/title64.s16le")
add_executable(logo64_native_test "${CLAY_ROOT}/tests/logo64.cpp" "${CLAY_ROOT}/host/logo64.cpp")
target_include_directories(logo64_native_test PRIVATE "${CLAY_ROOT}/host" "${RUNTIME}/N64Recomp/include")
target_compile_options(logo64_native_test PRIVATE /UNDEBUG /EHs)
add_test(NAME logo64_native COMMAND logo64_native_test "${CLAY_ROOT}/local/logo64/resource1.bin")

add_executable(selector_layout_native_test "${CLAY_ROOT}/tests/selector_layout.cpp" "${CLAY_ROOT}/host/selector_layout.cpp" "${CLAY_ROOT}/host/graphics_config.cpp" "${CLAY_ROOT}/generated/windows_selector_layout_guest.cpp")
target_include_directories(selector_layout_native_test PRIVATE "${CLAY_ROOT}/host" "${CLAY_ROOT}/generated/guest" "${RUNTIME}/N64Recomp/include")
target_compile_options(selector_layout_native_test PRIVATE /UNDEBUG /EHs /bigobj)
add_test(NAME selector_layout_native COMMAND selector_layout_native_test "${CLAY_ROOT}/probe-output/base.z64")
add_test(NAME selector_layout_original_red COMMAND selector_layout_native_test "${CLAY_ROOT}/probe-output/base.z64" baseline)
set_tests_properties(selector_layout_original_red PROPERTIES WILL_FAIL TRUE)

# Private authentic SC text, rendered and timed entirely by original guest routines.
add_executable(sc_bios_native_test "${CLAY_ROOT}/tests/sc_bios.cpp" "${CLAY_ROOT}/host/sc_bios.cpp" "${CLAY_ROOT}/generated/windows_sc_bios_guest.cpp")
target_include_directories(sc_bios_native_test PRIVATE "${CLAY_ROOT}/host" "${CLAY_ROOT}/generated/guest" "${RUNTIME}/N64Recomp/include")
target_compile_options(sc_bios_native_test PRIVATE /UNDEBUG /EHs /bigobj)
add_test(NAME sc_bios_native COMMAND sc_bios_native_test "${CLAY_ROOT}/probe-output/base.z64" "${CLAY_ROOT}/analysis/font_private/font.bin" "${CLAY_ROOT}/local/sc_bios/bios.bin")

# Native reused-selector constructor must retain its live shifted mesh/column.
add_executable(selector_mesh_reentry_test "${CLAY_ROOT}/tests/sc_roster_mesh.cpp" "${CLAY_ROOT}/host/sc_assets.cpp" "${CLAY_ROOT}/host/sc_roster.cpp" "${CLAY_ROOT}/local/sc_roster/mesh-guest.cpp")
target_include_directories(selector_mesh_reentry_test PRIVATE "${CLAY_ROOT}/host" "${CLAY_ROOT}/generated/guest" "${RUNTIME}/N64Recomp/include")
target_compile_options(selector_mesh_reentry_test PRIVATE /UNDEBUG /EHs /bigobj)
add_test(NAME selector_mesh_reentry COMMAND selector_mesh_reentry_test)
set_tests_properties(selector_mesh_reentry PROPERTIES WORKING_DIRECTORY "${CLAY_ROOT}")

add_executable(main_menu_native_test "${CLAY_ROOT}/tests/main_menu.cpp" "${CLAY_ROOT}/host/main_menu.cpp" "${CLAY_ROOT}/generated/windows_main_menu_guest.cpp")
target_include_directories(main_menu_native_test PRIVATE "${CLAY_ROOT}/host" "${CLAY_ROOT}/generated/guest" "${RUNTIME}/N64Recomp/include")
target_compile_options(main_menu_native_test PRIVATE /UNDEBUG /EHs /bigobj)
add_test(NAME main_menu_native_exit COMMAND main_menu_native_test "${CLAY_ROOT}/probe-output/base.z64")

add_test(NAME main_menu_native_exit_start COMMAND main_menu_native_test "${CLAY_ROOT}/probe-output/base.z64" start)

add_executable(native_preferences_test "${CLAY_ROOT}/tests/native_preferences.cpp" "${CLAY_ROOT}/host/native_preferences.cpp")
target_include_directories(native_preferences_test PRIVATE "${CLAY_ROOT}/host" "${RUNTIME}/N64Recomp/include")
target_compile_options(native_preferences_test PRIVATE /UNDEBUG /EHs)
add_test(NAME native_options_persistence COMMAND native_preferences_test "${CMAKE_CURRENT_BINARY_DIR}/native-options-test.cfg")
if(EXISTS "${CLAY_ROOT}/generated/windows_native_preferences_defaults.cpp")
 add_executable(native_preferences_defaults_test "${CLAY_ROOT}/generated/windows_native_preferences_defaults.cpp" "${CLAY_ROOT}/host/native_preferences.cpp")
 target_include_directories(native_preferences_defaults_test PRIVATE "${CLAY_ROOT}/host" "${RUNTIME}/N64Recomp/include")
 target_compile_options(native_preferences_defaults_test PRIVATE /UNDEBUG /EHs)
 add_test(NAME native_options_original_defaults COMMAND native_preferences_defaults_test)
endif()
