Skip to content
DanielG edited this page May 23, 2021 · 11 revisions

Requiring raylib to be installed

If you installed raylib with a package manager, or used make install, a simple CMakeLists.txt could look like this:

cmake_minimum_required(VERSION 3.15)
project(my_project)

find_package(raylib 3.0 REQUIRED) # Requires at least version 3.0

set(CMAKE_C_STANDARD 11) # Requires C11 standard

add_executable(${PROJECT_NAME} main.c)

target_link_libraries(${PROJECT_NAME} raylib)

# Checks if OSX and links appropriate frameworks (Only required on MacOS)
if (APPLE)
    target_link_libraries(${PROJECT_NAME} "-framework IOKit")
    target_link_libraries(${PROJECT_NAME} "-framework Cocoa")
    target_link_libraries(${PROJECT_NAME} "-framework OpenGL")
endif()

To build, use these commands:

mkdir build # Create a build directory
cd build && cmake .. # Build from that directory so the build files are in one place
cmake --build . # Build the project

Loading raylib inside cmake

If you want someone who builds your project to be able to download and build raylib with it, the CMakeLists.txt at projects/CMake will help you.

Use from within an IDE

CMake supports a range of generators, which can be used to generate project files for IDEs/Build-Tools such as Visual Studio, Ninja or Sublime Text 2. e.g. for Xcode you can run cmake -G 'Xcode' .. to have it generate project files for import into Xcode.

Clone this wiki locally