cmake_minimum_required(VERSION 3.18)
project(GameEngine VERSION 0.1.0 LANGUAGES C CXX)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# --- Validate preset variables ---
if(NOT DEFINED SDL_LINK_TYPE OR NOT SDL_LINK_TYPE MATCHES "^(static|dynamic)$")
    message(FATAL_ERROR "SDL_LINK_TYPE must be 'static' or 'dynamic'. Use a CMake preset.")
endif()

if(NOT DEFINED PLATFORM OR NOT PLATFORM MATCHES "^(windows|linux)$")
    message(FATAL_ERROR "PLATFORM must be 'windows' or 'linux'. Use a CMake preset.")
endif()

message(STATUS "Build config: PLATFORM=${PLATFORM}, SDL_LINK_TYPE=${SDL_LINK_TYPE}, BUILD_TYPE=${CMAKE_BUILD_TYPE}")

# --- Resolve SDL ---
include(cmake/SDLSetup.cmake)

# --- Apply Linux dynamic RPATH globally so all targets can find libSDL3.so.0
# at runtime. SDL_LINUX_RPATH is set by SDLSetup.cmake only on Linux + dynamic.
if(DEFINED SDL_LINUX_RPATH)
    message(STATUS "Setting CMAKE_BUILD_RPATH to: ${SDL_LINUX_RPATH}")
    set(CMAKE_BUILD_RPATH "${SDL_LINUX_RPATH}")
endif()

# --- Subdirectories ---
add_subdirectory(engine)
add_subdirectory(game)