From 4e72f41c292afa5db893b382fe34d53104aaaa0c Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Mon, 19 Aug 2019 21:29:02 -0400 Subject: [PATCH 1/2] Add Project example --- projects/CMake/CMakeLists.txt | 46 ++++++++++++++++++++++ projects/CMake/core_basic_window.cpp | 58 ++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 projects/CMake/CMakeLists.txt create mode 100644 projects/CMake/core_basic_window.cpp diff --git a/projects/CMake/CMakeLists.txt b/projects/CMake/CMakeLists.txt new file mode 100644 index 0000000..9b06981 --- /dev/null +++ b/projects/CMake/CMakeLists.txt @@ -0,0 +1,46 @@ +cmake_minimum_required(VERSION 3.11) # FetchContent is available in 3.11+ +project(example) + +find_package(raylib 2.0 QUIET) +if (NOT raylib_FOUND) + include(FetchContent) + FetchContent_Declare( + raylib + GIT_REPOSITORY https://github.com/raysan5/raylib.git + GIT_TAG 6f2f09947f5456cefb3d91d3f667f4d72fa55be6 + ) + FetchContent_GetProperties(raylib) + if (NOT raylib_POPULATED) # Have we downloaded raylib yet? + set(FETCHCONTENT_QUIET NO) + FetchContent_Populate(raylib) + set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) # don't build the supplied examples + set(BUILD_GAMES OFF CACHE BOOL "" FORCE) # or games + add_subdirectory(${raylib_SOURCE_DIR} ${raylib_BINARY_DIR}) + endif() +endif() + +find_package(raylibcpp 2.0 QUIET) +if (NOT raylibcpp_FOUND) + include(FetchContent) + FetchContent_Declare( + raylibcpp + GIT_REPOSITORY https://github.com/RobLoach/raylib-cpp.git + GIT_TAG de5e6184d043e9ae3e5a16836bc810b7485e95f2 + ) + FetchContent_GetProperties(raylib) + if (NOT raylib_POPULATED) # Have we downloaded raylib yet? + set(FETCHCONTENT_QUIET NO) + FetchContent_Populate(raylib) + set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) # don't build the supplied examples + set(BUILD_GAMES OFF CACHE BOOL "" FORCE) # or games + add_subdirectory(${raylibcpp_SOURCE_DIR} ${raylibcpp_BINARY_DIR}) + endif() +endif() + +# This is the main part: +set(PROJECT_NAME core_basic_window) +add_executable(${PROJECT_NAME} core_basic_window.cpp) +#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.cpp b/projects/CMake/core_basic_window.cpp new file mode 100644 index 0000000..9a78f1f --- /dev/null +++ b/projects/CMake/core_basic_window.cpp @@ -0,0 +1,58 @@ +/******************************************************************************************* +* +* 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) 2014 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib/raylib.hpp" + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + raylib::Color background(RAYWHITE); + raylib::Color textColor(LIGHTGRAY); + raylib::Window w(screenWidth, screenHeight, "raylib [core] example - basic window"); + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!w.ShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + // TODO: Update your variables here + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + background.ClearBackground(); + + textColor.DrawText("Congrats! You created your first window!", 190, 200, 20); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + return 0; +} From f505d7fabc648b012524152614169643eae72985 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Mon, 19 Aug 2019 21:57:59 -0400 Subject: [PATCH 2/2] Update CMake example --- CMakeLists.txt | 2 ++ projects/CMake/CMakeLists.txt | 32 +++++++++++++++++++------------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c592aa..3438652 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,8 @@ project (raylib-cpp) option(BUILD_EXAMPLES "Examples" TRUE) set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) add_subdirectory(include) diff --git a/projects/CMake/CMakeLists.txt b/projects/CMake/CMakeLists.txt index 9b06981..2590f83 100644 --- a/projects/CMake/CMakeLists.txt +++ b/projects/CMake/CMakeLists.txt @@ -13,34 +13,40 @@ if (NOT raylib_FOUND) if (NOT raylib_POPULATED) # Have we downloaded raylib yet? set(FETCHCONTENT_QUIET NO) FetchContent_Populate(raylib) - set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) # don't build the supplied examples - set(BUILD_GAMES OFF CACHE BOOL "" FORCE) # or games + set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) + set(BUILD_GAMES OFF CACHE BOOL "" FORCE) + set(BUILD_TESTING OFF CACHE BOOL "" FORCE) add_subdirectory(${raylib_SOURCE_DIR} ${raylib_BINARY_DIR}) endif() endif() -find_package(raylibcpp 2.0 QUIET) -if (NOT raylibcpp_FOUND) +find_package(raylib-cpp 2.0 QUIET) +if (NOT raylib-cpp_FOUND) include(FetchContent) FetchContent_Declare( - raylibcpp + raylib-cpp GIT_REPOSITORY https://github.com/RobLoach/raylib-cpp.git GIT_TAG de5e6184d043e9ae3e5a16836bc810b7485e95f2 ) - FetchContent_GetProperties(raylib) - if (NOT raylib_POPULATED) # Have we downloaded raylib yet? + FetchContent_GetProperties(raylib-cpp) + if (NOT raylib-cpp_POPULATED) # Have we downloaded raylib yet? set(FETCHCONTENT_QUIET NO) - FetchContent_Populate(raylib) - set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) # don't build the supplied examples - set(BUILD_GAMES OFF CACHE BOOL "" FORCE) # or games - add_subdirectory(${raylibcpp_SOURCE_DIR} ${raylibcpp_BINARY_DIR}) + FetchContent_Populate(raylib-cpp) + set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) + set(BUILD_GAMES OFF CACHE BOOL "" FORCE) + set(BUILD_TESTING OFF CACHE BOOL "" FORCE) + add_subdirectory(${raylib-cpp_SOURCE_DIR} ${raylib-cpp_BINARY_DIR}) endif() endif() +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + # This is the main part: set(PROJECT_NAME core_basic_window) -add_executable(${PROJECT_NAME} core_basic_window.cpp) +set(PROJECT_SOURCES core_basic_window.cpp) +add_executable(${PROJECT_NAME} ${PROJECT_SOURCES}) #set(raylib_VERBOSE 1) -target_link_libraries(${PROJECT_NAME} raylib) +target_link_libraries(${PROJECT_NAME} PUBLIC raylib raylib-cpp) # That's it! You should have an example executable that you can run. Have fun!