-
-
Save axel18bsm/4a872265b99137b58807372ccc81e839 to your computer and use it in GitHub Desktop.
CMakeLists.txt for Raylib projects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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}) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment