From e82505b873370b8f3a914a079062c21e64353210 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Sun, 29 Jul 2018 18:23:23 +0200 Subject: [PATCH] Add projects/CMake example The CMakeLists.txt checks for an installed raylib and downloads and installs one if none is found. Afterwards, it builds core_basic_window.c --- projects/CMake/CMakeLists.txt | 37 ++++++++++++++++++ projects/CMake/core_basic_window.c | 62 ++++++++++++++++++++++++++++++ src/CMakeLists.txt | 2 +- 3 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 projects/CMake/CMakeLists.txt create mode 100644 projects/CMake/core_basic_window.c diff --git a/projects/CMake/CMakeLists.txt b/projects/CMake/CMakeLists.txt new file mode 100644 index 00000000..68c976e5 --- /dev/null +++ b/projects/CMake/CMakeLists.txt @@ -0,0 +1,37 @@ +cmake_minimum_required(VERSION 3.11) # FetchContent is available in 3.11+ +project(example) + +find_package(raylib 2.0 QUIET) # Let CMake search for a raylib-config.cmake + +# You could change the QUIET above to REQUIRED and remove this if() clause +# This part downloads raylib and builds it if it's not installed on your system +if (NOT raylib_FOUND) # If there's none, fetch and build raylib + include(FetchContent) + + FetchContent_Declare( + raylib + URL https://github.com/raysan5/raylib/archive/master.tar.gz + ) + + FetchContent_GetProperties(raylib) + if (NOT raylib_POPULATED) # Have we downloaded raylib yet? + set(FETCHCONTENT_QUIET NO) + FetchContent_Populate(raylib) + + set(BUILD_EXAMPLES OFF) # don't build the supplied examples + set(BUILD_GAMES OFF) # or games + + # build raylib + add_subdirectory(${raylib_SOURCE_DIR} ${raylib_BINARY_DIR}) + + endif() + +endif() + +# This is the main part: + +add_executable(${PROJECT_NAME} core_basic_window.c) +#set(raylib_VERBOSE 1) +target_link_libraries(${PROJECT_NAME} raylib) + +# That's it! You should have an example executable that you can run. Have fun! diff --git a/projects/CMake/core_basic_window.c b/projects/CMake/core_basic_window.c new file mode 100644 index 00000000..176f46c9 --- /dev/null +++ b/projects/CMake/core_basic_window.c @@ -0,0 +1,62 @@ +/******************************************************************************************* +* +* raylib [core] example - Basic window +* +* Welcome to raylib! +* +* To test examples, just press F6 and execute raylib_compile_execute script +* Note that compiled executable is placed in the same folder as .c file +* +* You can find all basic examples on C:\raylib\raylib\examples folder or +* raylib official webpage: www.raylib.com +* +* Enjoy using raylib. :) +* +* This example has been created using raylib 1.0 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2013-2016 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window"); + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + // TODO: Update your variables here + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ceee761f..2e561fc5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -43,7 +43,7 @@ if(NOT glfw3_FOUND AND NOT USE_EXTERNAL_GLFW STREQUAL "ON" AND "${PLATFORM}" MAT list(APPEND raylib_sources $) else() MESSAGE(STATUS "Using external GLFW") - set(GLFW_PKG_DEPS glfw) + set(GLFW_PKG_DEPS glfw3) endif() add_definitions("-DRAYLIB_CMAKE=1")