CMake
July 5, 2025•221 words
Great CMake Tutorial from Kea Sigma Delta
https://keasigmadelta.com/blog/cmake-tutorial-getting-started/
Update:
Made two changes to get it to work
1 - In CMakeLists.txt change first line from cmake_minimum_required(VERSION 3.24)
to cmake_minimum_required(VERSION 3.20...4.0.2)
2- Changed Raylib version to 5.5.
Contents:
/** Main.cpp
*
* A simple Raylib example.
*/
#include "raylib.h"
#include <cstdlib>
int main(int argc, const char **argv) {
// Initialization
const int screenWidth = 1280;
const int screenHeight = 768;
const char *windowTitle = "Hello world!";
const char *message = "Hello world! It's great to be here.";
const int fontSize = 40;
const float msgSpacing = 1.0f;
InitWindow(screenWidth, screenHeight, windowTitle);
// NOTE: The following only works after calling InitWindow() (i.e,. Raylib is initialized)
const Font font = GetFontDefault();
const Vector2 msgSize = MeasureTextEx(font, message, fontSize, msgSpacing);
const Vector2 msgPos = Vector2{(screenWidth - msgSize.x) / 2, (screenHeight - msgSize.y) / 2};
SetTargetFPS(60);
// Main loop
while(!WindowShouldClose()) {
// Update the display
BeginDrawing();
ClearBackground(RAYWHITE);
DrawTextEx(font, message, msgPos, fontSize, msgSpacing, RED);
EndDrawing();
}
// Cleanup
CloseWindow();
return EXIT_SUCCESS;
}
CmakeLists.txt
cmake_minimum_required(VERSION 3.20...4.0.2)
project(hello_raylib)
# Workaround for CLang and Raylib's compound literals
# See: https://github.com/raysan5/raylib/issues/1343
set(CMAKE_CXX_STANDARD 11)
# Dependencies
include(FetchContent)
set(RAYLIB_VERSION 5.5)
FetchContent_Declare(
raylib
URL https://github.com/raysan5/raylib/archive/refs/tags/${RAYLIB_VERSION}.tar.gz
FIND_PACKAGE_ARGS ${RAYLIB_VERSION} EXACT
)
set(BUILD_EXAMPLES OFF CACHE INTERNAL "")
FetchContent_MakeAvailable(raylib)
# Our Project
set(SOURCE_FILES
Main.cpp
)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} raylib)