# A build for a game running under Turret's game mode, on the raylib backend. Copy this to the
# project root, rename the target, and point it at your own source file. A game on the SDL
# backend fetches SDL3, SDL3_image and SDL3_ttf in place of raylib and links all three; see
# SKILL.md, step 3.
#
# raylib is pinned rather than tracked: the harness uses ExportImageToMemory, which 5.5 has, and a
# game that reproduces a run today should still reproduce it after a `git pull`. The first
# configure fetches raylib and needs network; CMake caches it in the build directory afterwards.
cmake_minimum_required(VERSION 3.20)
project(my_game CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(NOT CMAKE_BUILD_TYPE)
  set(CMAKE_BUILD_TYPE Release)
endif()

include(FetchContent)

# raylib's examples and games are a large share of its build time and nothing here uses them.
# The modules left on are what the harness itself needs: shapes, textures and text.
set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(BUILD_GAMES OFF CACHE BOOL "" FORCE)
set(CUSTOMIZE_BUILD ON CACHE BOOL "" FORCE)
set(SUPPORT_MODULE_RSHAPES ON CACHE BOOL "" FORCE)
set(SUPPORT_MODULE_RTEXTURES ON CACHE BOOL "" FORCE)
set(SUPPORT_MODULE_RTEXT ON CACHE BOOL "" FORCE)
# Turn these on if the game loads 3D models or plays audio itself.
set(SUPPORT_MODULE_RMODELS OFF CACHE BOOL "" FORCE)
set(SUPPORT_MODULE_RAUDIO OFF CACHE BOOL "" FORCE)

FetchContent_Declare(
  raylib
  GIT_REPOSITORY https://github.com/raysan5/raylib.git
  GIT_TAG 5.5
  GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(raylib)

add_executable(my_game main.cpp)
# Wherever the harness headers were vendored — all three of them live in one directory.
target_include_directories(my_game PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/harness)
target_link_libraries(my_game PRIVATE raylib)

# turret_game_raylib.h's DisplayAvailable() asks CoreGraphics directly on macOS, rather than
# through GLFW — see its own comment for why. turret_game.h's live play (harness version 8)
# calls the Objective-C runtime to bring the window forward, so the target links objc itself:
# raylib and SDL usually pull it in through Cocoa, but a target without a Cocoa-using
# dependency does not link without it.
if(APPLE)
  target_link_libraries(my_game PRIVATE "-framework CoreGraphics" objc)
endif()
