Setting up raylib and raygui with cmake
Hey there. Back from the dead to add some useful scaffold. Recently I’ve been making small prototypes in c/c++, and after playing lots with SDL, SFML and even OpenGL, I found out that Raylib is the best fun I had in doing those prototypes. Setting it up is straight-forward if you know cmake documentation, but who does, right? Well, that’s why I made this post. This is my script to build my small drawing program having raylib and raygui both as a dependency, in a subdirectory called thirdparty.
cmake_minimum_required(VERSION 3.5)
project(raylib_game CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) # don't build the supplied examples
add_subdirectory(thirdparty/raylib thirdparty/raylib/bin)
set(BUILD_RAYGUI_EXAMPLES OFF CACHE BOOL "" FORCE) # don't build raygui examples
add_subdirectory(thirdparty/raygui/projects/CMake)
set(SOURCES
main.cpp
)
add_executable(${PROJECT_NAME} ${SOURCES})
target_link_libraries(${PROJECT_NAME} raylib raygui)
target_include_directories(${PROJECT_NAME} PRIVATE include/)
It will presume raylib and raygui sources are both under thirdparty/ Your files can reside anywhere in the project and you’ll be able to include both raylib.h and raygui.h anywhere in the project tree withouth using relative paths. Have a look at main.cpp to see an example basically stracted directly from raygui examples.
Building:
Be sure to have all dependencies raylib requires to build itself with. At the root of the project, just do:
mkdir build && cd build && cmake .. && make
Happy coding ;)
Footnotes:
The repository with this template can be found here.