cmake_minimum_required(VERSION 3.25)
project(TopSpinNativeWindowsRenderer LANGUAGES C)
# djultra64. A native compilation gate for the current renderer, not the game.
if(NOT WIN32 OR NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
    message(FATAL_ERROR "This gate requires a native 64-bit Windows toolchain.")
endif()
if(NOT CMAKE_C_COMPILER_ID MATCHES "Clang")
    message(FATAL_ERROR "Use native Windows Clang for the current C11 runtime sources.")
endif()
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(TOPSPIN_SDK_ROOT "" CACHE PATH "SDK tree with the reviewed Windows Vulkan patch applied")
if(NOT EXISTS "${TOPSPIN_SDK_ROOT}/src/d3d/visual_scene_recorder.c")
    message(FATAL_ERROR "TOPSPIN_SDK_ROOT must point to the current C SDK; the historical C++ runtime is incompatible.")
endif()
add_compile_definitions(WIN32_LEAN_AND_MEAN NOMINMAX _CRT_SECURE_NO_WARNINGS)
set(XBOXRECOMP_VULKAN ON CACHE BOOL "Use the shared Vulkan renderer" FORCE)
# No dependency download, no game assets and no host/save stubs. The kernel is
# configured as its real target so the renderer receives its original metadata;
# compiling the renderer gate does not assert that the whole kernel/host links.
add_subdirectory("${TOPSPIN_SDK_ROOT}/src/settings" sdk-settings)
add_subdirectory("${TOPSPIN_SDK_ROOT}/src/platform" sdk-platform)
add_subdirectory("${TOPSPIN_SDK_ROOT}/src/kernel" sdk-kernel)
add_subdirectory("${TOPSPIN_SDK_ROOT}/src/d3d" sdk-d3d)
add_subdirectory("${TOPSPIN_SDK_ROOT}/src/nv2a" sdk-nv2a)
get_target_property(backend xbox_d3d8 INTERFACE_COMPILE_DEFINITIONS)
get_target_property(sources xbox_d3d8 SOURCES)
if(NOT "XBOXRECOMP_HAVE_VULKAN=1" IN_LIST backend OR NOT "d3d8_vk.c" IN_LIST sources)
    message(FATAL_ERROR "The selected SDK did not provide Vulkan; apply the reviewed backend patch first.")
endif()
add_custom_target(topspin_windows_renderer_compile DEPENDS xbox_d3d8 xbox_nv2a)
message(STATUS "Renderer compilation gate only: no Top Spin executable or native host acceptance.")
add_executable(topspin_windows_renderer_smoke renderer_smoke.c)
target_link_libraries(topspin_windows_renderer_smoke PRIVATE xbox_d3d8)
