Basic CMake and hello world with raylib.

This commit is contained in:
Yohan Boujon 2025-03-09 21:26:07 +01:00
parent adc056bffe
commit 049470b508
5 changed files with 90 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
# Build folder
build/**

14
CMakeLists.txt Normal file
View file

@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.21)
# C/C++ Standard
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
# Dependencies
set(RAYLIB_VERSION 5.5)
include(dependencies.cmake)
# Game source file
include(game.cmake)

18
dependencies.cmake Normal file
View file

@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.11)
# Raylib
find_package(raylib ${RAYLIB_VERSION} QUIET) # QUIET or REQUIRED
if (NOT raylib_FOUND) # If there's none, fetch and build raylib
include(FetchContent)
FetchContent_Declare(
raylib
DOWNLOAD_EXTRACT_TIMESTAMP OFF
URL https://github.com/raysan5/raylib/archive/refs/tags/${RAYLIB_VERSION}.tar.gz
)
FetchContent_GetProperties(raylib)
if (NOT raylib_POPULATED) # Have we downloaded raylib yet?
set(FETCHCONTENT_QUIET NO)
FetchContent_MakeAvailable(raylib)
set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) # don't build the supplied examples
endif()
endif()

37
game.cmake Normal file
View file

@ -0,0 +1,37 @@
# Project
project(
yoyo_card
VERSION 1.0.0
DESCRIPTION "Gabo card game recreation."
HOMEPAGE_URL "https://www.etheryo.fr"
LANGUAGES CXX C
)
set(TARGET game)
# Source files
set(SOURCES "${PROJECT_SOURCE_DIR}/src")
add_executable(${TARGET}
${SOURCES}/main.cpp
)
# Include folders
target_include_directories(${TARGET} PRIVATE "${PROJECT_SOURCE_DIR}/include")
target_include_directories(${TARGET} PRIVATE "${raylib_INCLUDE_DIRS}")
# Libraries
target_link_libraries(${TARGET} raylib)
# Compilation depending on the platform
if(MSVC)
target_compile_options(${TARGET} PUBLIC /W3 /WX /DEBUG )
else()
target_compile_options(${TARGET} PUBLIC -Wall -Wextra -Wpedantic -Werror)
endif()
# Output folder
set_target_properties(${TARGET}
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/game"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/game"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/game"
)

19
src/main.cpp Normal file
View file

@ -0,0 +1,19 @@
#include <raylib.h>
int main(void)
{
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib hello world");
SetTargetFPS(60);
while (!WindowShouldClose())
{
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText("Hello world from raylib.", 190, 200, 20, LIGHTGRAY);
EndDrawing();
}
CloseWindow();
return 0;
}