cmake_minimum_required(VERSION 3.20)
project(tje3 CXX)

# The recompiled game. Lifted sources are generated by tools/recomp/build_game.py
# into LIFTED_DIR (git-ignored); the runtime and HLE layer live in runtime/.
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(LIFTED_DIR "${CMAKE_SOURCE_DIR}/build/recomp_all" CACHE PATH "Generated lifted C++")

# Vulkan and shaderc are loaded at run time; only their headers are needed here.
find_path(VULKAN_INCLUDE_DIR vulkan/vulkan.h
    HINTS "$ENV{VULKAN_SDK}/Include" "G:/DevTools/VulkanSDK/1.4.363.0/Include")
if(NOT VULKAN_INCLUDE_DIR)
    message(FATAL_ERROR "Vulkan headers not found: set VULKAN_SDK")
endif()

file(GLOB LIFTED_SOURCES CONFIGURE_DEPENDS "${LIFTED_DIR}/lifted_*.cpp")
file(GLOB HLE_SOURCES CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/runtime/hle/*.cpp")
file(GLOB GPU_SOURCES CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/runtime/gpu/*.cpp")

add_executable(tje3
    runtime/main.cpp
    runtime/runtime.cpp
    runtime/kernel.cpp
    runtime/trace.cpp
    runtime/sched.cpp
    runtime/settings.cpp
    runtime/audio_out.cpp
    ${HLE_SOURCES}
    ${GPU_SOURCES}
    "${LIFTED_DIR}/hle_libs_generated.cpp"
    ${LIFTED_SOURCES})
target_include_directories(tje3 PRIVATE runtime "${LIFTED_DIR}" "${VULKAN_INCLUDE_DIR}")
# Generated code: quiet, and moderately optimised to keep build times short.
set_source_files_properties(${LIFTED_SOURCES} PROPERTIES COMPILE_OPTIONS "-O2;-w")
if(MINGW)
    target_link_options(tje3 PRIVATE -static)
endif()
if(WIN32)
    target_link_libraries(tje3 PRIVATE winmm)
endif()
