From 3d73a473a58485587e9ab7024e969f6ae7400223 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Sat, 1 Oct 2022 16:26:14 -0400 Subject: [PATCH] Add CMake support --- projects/CMake/.gitignore | 1 + projects/CMake/CMakeLists.txt | 40 +++++++++++++++++++++++++++ projects/CMake/README.md | 27 ++++++++++++++++++ projects/CMake/cmake/FindRaylib.cmake | 17 ++++++++++++ 4 files changed, 85 insertions(+) create mode 100644 projects/CMake/.gitignore create mode 100644 projects/CMake/CMakeLists.txt create mode 100644 projects/CMake/README.md create mode 100644 projects/CMake/cmake/FindRaylib.cmake diff --git a/projects/CMake/.gitignore b/projects/CMake/.gitignore new file mode 100644 index 0000000..c795b05 --- /dev/null +++ b/projects/CMake/.gitignore @@ -0,0 +1 @@ +build \ No newline at end of file diff --git a/projects/CMake/CMakeLists.txt b/projects/CMake/CMakeLists.txt new file mode 100644 index 0000000..ccaa481 --- /dev/null +++ b/projects/CMake/CMakeLists.txt @@ -0,0 +1,40 @@ +cmake_minimum_required(VERSION 3.11) +set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) +project(rfxgen C) + +# Options +if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}") + set(RFXGEN_IS_MAIN TRUE) +else() + set(RFXGEN_IS_MAIN FALSE) +endif() +option(BUILD_RFXGEN "Build ${PROJECT_NAME}" ${RFXGEN_IS_MAIN}) + +# Directory Variables +set(RFXGEN_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..) +set(RFXGEN_SRC ${RFXGEN_ROOT}/src) + +# Application +if(${BUILD_RFXGEN}) + find_package(Raylib) + + add_executable(${PROJECT_NAME} + ${RFXGEN_SRC}/rfxgen.c + ${RFXGEN_SRC}/external/tinyfiledialogs.c + ) + + target_include_directories(${PROJECT_NAME} PUBLIC ${RFXGEN_SRC}/external) + target_link_libraries(${PROJECT_NAME} PUBLIC raylib) + + # Web Configurations + if (${PLATFORM} STREQUAL "Web") + set_target_properties(${PROJECT_NAME} PROPERTIES SUFFIX ".html") + endif() + + # MacOS + if (APPLE) + target_link_libraries(${PROJECT_NAME} "-framework IOKit") + target_link_libraries(${PROJECT_NAME} "-framework Cocoa") + target_link_libraries(${PROJECT_NAME} "-framework OpenGL") + endif() +endif() \ No newline at end of file diff --git a/projects/CMake/README.md b/projects/CMake/README.md new file mode 100644 index 0000000..b1544df --- /dev/null +++ b/projects/CMake/README.md @@ -0,0 +1,27 @@ +# rFXGen CMake + +This allows building [rFXGen](https://raylibtech.itch.io/rfxgen) with [CMake](https://cmake.org). + +## Usage + +To compile the example, use one of the following dependending on your build target... + +### Desktop + +Use the following to build for desktop: + +``` bash +cmake -B build +cmake --build build +``` + +### Web + +Compiling for the web requires the [Emscripten SDK](https://emscripten.org/docs/getting_started/downloads.html): + +``` bash +mkdir build +cd build +emcmake cmake .. -DPLATFORM=Web -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXE_LINKER_FLAGS="-s USE_GLFW=3" -DCMAKE_EXECUTABLE_SUFFIX=".html" +emmake make +``` \ No newline at end of file diff --git a/projects/CMake/cmake/FindRaylib.cmake b/projects/CMake/cmake/FindRaylib.cmake new file mode 100644 index 0000000..dd4c89e --- /dev/null +++ b/projects/CMake/cmake/FindRaylib.cmake @@ -0,0 +1,17 @@ +find_package(raylib 4.2.0 QUIET CONFIG) +if (NOT raylib_FOUND) + include(FetchContent) + FetchContent_Declare( + raylib + GIT_REPOSITORY https://github.com/raysan5/raylib.git + GIT_TAG 4.2.0 + ) + 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