cmake_minimum_required(VERSION 3.20)
project(FPS_DRUID LANGUAGES C)

set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)

# Default build type for single-config generators
if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
  set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build type" FORCE)
endif()

# ---------- Fetch raylib ----------
include(FetchContent)
set(FETCHCONTENT_QUIET FALSE)
set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(BUILD_GAMES    OFF CACHE BOOL "" FORCE)

FetchContent_Declare(
  raylib
  GIT_REPOSITORY https://github.com/raysan5/raylib.git
  GIT_TAG 5.5            # stable release
  GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(raylib)

# ---------- Paths (match your tree) ----------
set(SRC_DIR     "${CMAKE_CURRENT_LIST_DIR}/src")
set(INC_DIR     "${CMAKE_CURRENT_LIST_DIR}/include")
set(ASSETS_DIR  "${CMAKE_CURRENT_LIST_DIR}/assets")

# ---------- Sources ----------
file(GLOB_RECURSE PROJECT_SOURCES CONFIGURE_DEPENDS "${SRC_DIR}/*.c")

add_executable(${PROJECT_NAME} ${PROJECT_SOURCES})
target_include_directories(${PROJECT_NAME} PRIVATE "${SRC_DIR}" "${INC_DIR}")
target_link_libraries(${PROJECT_NAME} PRIVATE raylib)

# ---------- Warnings / ASan ----------
if(MSVC)
  target_compile_options(${PROJECT_NAME} PRIVATE /W4 /permissive-)
else()
  target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wshadow -Wconversion -Wno-unused-parameter)
  if(CMAKE_BUILD_TYPE STREQUAL "Debug")
    target_compile_options(${PROJECT_NAME} PRIVATE -fsanitize=address -fno-omit-frame-pointer)
    target_link_options(${PROJECT_NAME} PRIVATE -fsanitize=address)
  endif()
endif()

# ---------- Assets: copy next to the exe ----------
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
  COMMAND ${CMAKE_COMMAND} -E copy_directory
          "${ASSETS_DIR}" "$<TARGET_FILE_DIR:${PROJECT_NAME}>/assets"
  COMMENT "Copying assets next to the executable"
)

# Compile-time asset root: absolute in Debug; relative otherwise
target_compile_definitions(${PROJECT_NAME} PRIVATE
  $<$<CONFIG:Debug>:ASSETS_PATH="${ASSETS_DIR}/">
  $<$<NOT:$<CONFIG:Debug>>:ASSETS_PATH="./assets/">
)