Skip to content

Instantly share code, notes, and snippets.

@erikyuzwa
Last active November 18, 2024 15:54
Show Gist options
  • Save erikyuzwa/98305851fc6f948805a92768c7e82705 to your computer and use it in GitHub Desktop.
Save erikyuzwa/98305851fc6f948805a92768c7e82705 to your computer and use it in GitHub Desktop.
CMakeLists.txt for Raylib projects
# CMakeLists.txt project file for Raylib projects
#
cmake_minimum_required(VERSION 3.30)
project(hello_raylib_with_cmake C)
set(CMAKE_C_STANDARD 23)
# Include the command that downloads libraries
include(FetchContent)
# define a function for adding git dependencies
function(include_dependency libName gitURL gitTag)
# setup the declare
FetchContent_Declare(${libName}
GIT_REPOSITORY ${gitURL}
GIT_TAG ${gitTag}
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(${libName})
endfunction()
# add raylib support
set(LIB1 raylib)
find_package(${LIB1} QUIET)
if (NOT ${LIB1}_FOUND)
message(STATUS "Getting ${LIB1} from Github")
include_dependency(${LIB1} https://github.com/raysan5/raylib.git 5.5)
else()
message(STATUS "Using local ${LIB1}")
endif()
add_executable(hello_raylib_with_cmake main.c)
# set the include directory
target_include_directories(hello_raylib_with_cmake PRIVATE ${raylib_INCLUDE_DIRS})
# link all libraries to the project
target_link_libraries(hello_raylib_with_cmake PRIVATE ${LIB1})
#include <stdio.h>
#include "raylib.h"
int main(void) {
// 800x450 is 16:9
InitWindow(800, 450, "Raylib");
SetTargetFPS(60);
while (!WindowShouldClose()) {
BeginDrawing();
ClearBackground(SKYBLUE);
EndDrawing();
}
CloseWindow();
return 0;
}
@erikyuzwa
Copy link
Author

Updated on 2024-11-18 for Raylib 5.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment