From 0fdacc87f6de77146850fcaf88c582cbd7219220 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Thu, 16 Apr 2020 07:24:03 -0400 Subject: [PATCH] Add CMake definitions (#79) --- .gitignore | 2 ++ CMakeLists.txt | 16 ++++++++++++++ cmake/FindRaylib.cmake | 17 +++++++++++++++ examples/CMakeLists.txt | 46 +++++++++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 10 +++++++++ 5 files changed, 91 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 cmake/FindRaylib.cmake create mode 100644 examples/CMakeLists.txt create mode 100644 src/CMakeLists.txt diff --git a/.gitignore b/.gitignore index 68eb164..18c01c5 100644 --- a/.gitignore +++ b/.gitignore @@ -60,3 +60,5 @@ *.cache *.ilk *.log + +build \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..c04d7e4 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.11) +set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) + +project(raygui C) + +# Config options +option(BUILD_EXAMPLES "Build the examples." ON) + +add_subdirectory(src) + +if (${BUILD_EXAMPLES}) + add_subdirectory(examples) +endif() + +# TODO: Add automated testing. +# enable_testing() \ No newline at end of file diff --git a/cmake/FindRaylib.cmake b/cmake/FindRaylib.cmake new file mode 100644 index 0000000..291472b --- /dev/null +++ b/cmake/FindRaylib.cmake @@ -0,0 +1,17 @@ +find_package(raylib 3.0.0 QUIET) +if (NOT raylib_FOUND) + include(FetchContent) + FetchContent_Declare( + raylib + GIT_REPOSITORY https://github.com/raysan5/raylib.git + GIT_TAG 6a8b1079c13b7d5e1bddc0ecc86ad7e16fc2556d + ) + 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() \ No newline at end of file diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000..ed75fb3 --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,46 @@ +find_package(Raylib) + +# Get the sources together +set(example_dirs + custom_file_dialog + image_raw_importer + portable_window + scroll_panel + text_box_selection + controls_test_suite + image_exporter + property_list + standalone + text_editor +) + +set(example_sources) +set(example_resources) + +foreach(example_dir ${example_dirs}) + # Get the .c files + file(GLOB sources ${example_dir}/*.c) + list(APPEND example_sources ${sources}) + + # Any any resources + file(GLOB resources ${example_dir}/resources/*) + list(APPEND example_resources ${resources}) +endforeach() + +# Do each example +foreach(example_source ${example_sources}) + # Create the basename for the example + get_filename_component(example_name ${example_source} NAME) + string(REPLACE ".c" "${OUTPUT_EXT}" example_name ${example_name}) + + # Setup the example + add_executable(${example_name} ${example_source}) + + target_link_libraries(${example_name} PUBLIC raylib raygui) + + string(REGEX MATCH ".*/.*/" resources_dir ${example_source}) + string(APPEND resources_dir "resources") +endforeach() + +# Copy all of the resource files to the destination +file(COPY ${example_resources} DESTINATION "resources/") \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..a842f5a --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,10 @@ +add_library(raygui INTERFACE) + +file(GLOB sources *.h) +set(RAYGUI_HEADERS, ${sources}) + +install(FILES + ${RAYGUI_HEADERS} DESTINATION include/ +) + +target_include_directories(raygui INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/) \ No newline at end of file