Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CMake support #27

Merged
merged 1 commit into from Oct 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions projects/CMake/.gitignore
@@ -0,0 +1 @@
build
40 changes: 40 additions & 0 deletions 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()
27 changes: 27 additions & 0 deletions 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
```
17 changes: 17 additions & 0 deletions 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()