Aim is to scaffold a C++ project that uses Raylib and can be built with CMake.
raylib_project/
├── CMakeLists.txt
└── main.cpp
CMakeLists.txt : All of these are needed, nothing is optional here.
cmake_minimum_required(VERSION 4.1.1) # can just use `cmake --version` to check your version
project(MyRaylibGame) # Name of the project
# these tree commands are always needed
include(FetchContent)
FetchContent_Declare(
my_raylib # this is the cmake variable name, can be anything like my_raylib
GIT_REPOSITORY https://github.com/raysan5/raylib.git
GIT_TAG master
)
FetchContent_MakeAvailable(my_raylib) # this should match the variable name above
# my_game is the name of the executable
# main.cpp is the source file
add_executable(my_game main.cpp)
# linking raylib to my_game
target_link_libraries(my_game PRIVATE raylib)
# Private means only my_game can use raylib
# Public means any target that links to my_game can also use raylib
# this here must be raylib as it comes from the raylib's cmake
# https://github.com/raysan5/raylib/blob/master/src/CMakeLists.txt has
# add_library(raylib ${raylib_sources} ${raylib_public_headers})