Skip to content

Commit

Permalink
Use CMake to download raylib -- fixes #6
Browse files Browse the repository at this point in the history
  • Loading branch information
RobLoach committed Jan 17, 2022
1 parent 6081d91 commit a775f4d
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 55 deletions.
4 changes: 0 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
[submodule "vendor/raylib"]
path = vendor/raylib
url = https://github.com/raysan5/raylib.git
ignore = dirty
[submodule "vendor/physfs"]
path = vendor/physfs
url = https://github.com/icculus/physfs.git
Expand Down
29 changes: 15 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.11)
project (raylib-physfs
VERSION 4.0.1
VERSION 4.0.2
DESCRIPTION "raylib-physfs"
HOMEPAGE_URL "https://github.com/robloach/raylib-physfs"
LANGUAGES C
Expand All @@ -9,23 +9,24 @@ project (raylib-physfs
# Include Directory
add_subdirectory(include)

# Static Library
option(BUILD_RAYLIB_PHYSFS_LIB "Library" ON)
if(BUILD_RAYLIB_PHYSFS_LIB)
add_subdirectory(lib)
# Options
if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
set(RAYLIB_PHYSFS_IS_MAIN TRUE)
else()
set(RAYLIB_PHYSFS_IS_MAIN FALSE)
endif()
option(RAYLIB_PHYSFS_BUILD_EXAMPLES "Examples" ${RAYLIB_PHYSFS_IS_MAIN})

# Examples
option(BUILD_RAYLIB_PHYSFS_EXAMPLES "Examples" ON)
if(BUILD_RAYLIB_PHYSFS_EXAMPLES)
if (RAYLIB_PHYSFS_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

# Testing
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(CTest)
enable_testing()
if(BUILD_TESTING AND BUILD_RAYLIB_PHYSFS_LIB)
add_subdirectory(test)
# Testing
if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(CTest)
enable_testing()
if (BUILD_TESTING)
add_subdirectory(test)
endif()
endif()
endif()
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ To build the examples locally, and run tests, use [cmake](https://cmake.org/).
``` bash
git clone https://github.com/RobLoach/raylib-physfs.git
cd raylib-physfs
git submodule update --init
mkdir build
cd build
cmake ..
Expand Down
19 changes: 15 additions & 4 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,20 @@ set(example_resources)
# raylib
find_package(raylib QUIET)
if (NOT raylib_FOUND)
set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) # don't build the supplied examples
set(BUILD_GAMES OFF CACHE BOOL "" FORCE) # or games
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../vendor/raylib ${CMAKE_CURRENT_SOURCE_DIR}/../vendor/raylib)
include(FetchContent)
FetchContent_Declare(
raylib
GIT_REPOSITORY https://github.com/raysan5/raylib.git
GIT_TAG 4.0.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)
set(BUILD_GAMES OFF CACHE BOOL "" FORCE)
add_subdirectory(${raylib_SOURCE_DIR} ${raylib_BINARY_DIR})
endif()
endif()

# Find all examples
Expand All @@ -31,7 +42,7 @@ foreach(example_source ${example_sources})
add_executable(${example_name} ${example_source})

# Link raylib and raylib-cpp
target_link_libraries(${example_name} PUBLIC raylib raylib-physfs)
target_link_libraries(${example_name} PUBLIC raylib raylib_physfs)

target_compile_definitions(${example_name} PUBLIC
PHYSFS_SUPPORTS_NO_ZIP
Expand Down
6 changes: 3 additions & 3 deletions examples/audio/audio_sound_loading.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ int main(void)
InitAudioDevice(); // Initialize audio device

InitPhysFS(); // Initialize PhysFS
MountPhysFS("resources", ""); // Mount the resources directory.
MountPhysFS("resources", "res"); // Mount the resources directory.

Wave wav = LoadWaveFromPhysFS("sound.wav");
Wave ogg = LoadWaveFromPhysFS("target.ogg");
Wave wav = LoadWaveFromPhysFS("res/sound.wav");
Wave ogg = LoadWaveFromPhysFS("res/target.ogg");

Sound fxWav = LoadSoundFromWave(wav); // Load WAV audio file
Sound fxOgg = LoadSoundFromWave(ogg); // Load OGG audio file
Expand Down
10 changes: 2 additions & 8 deletions include/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
add_library(raylib-physfs INTERFACE)
add_library(raylib_physfs INTERFACE)

# Include Directory
target_include_directories(raylib-physfs INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/)

# Options
option(RAYLIB_PHYSFS_STATIC "Static Definition" OFF)
if (RAYLIB_PHYSFS_STATIC)
target_compile_definitions(raylib-physfs INTERFACE RAYLIB_PHYSFS_STATIC)
endif()
target_include_directories(raylib_physfs INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/)

# Set the header files as install files.
install(FILES raylib-physfs.h miniphysfs.h
Expand Down
4 changes: 0 additions & 4 deletions lib/CMakeLists.txt

This file was deleted.

13 changes: 0 additions & 13 deletions lib/raylib-physfs.c

This file was deleted.

2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
add_executable(raylib-physfs-test raylib-physfs-test.c)
target_link_libraries(raylib-physfs-test PUBLIC
raylib
raylib-physfs-static
raylib_physfs
)

# Copy the resources
Expand Down
3 changes: 1 addition & 2 deletions test/raylib-physfs-test.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include <assert.h>
#include "raylib.h"

// Tests use the raylib-physfs-static library, so don't need to define RAYLIB_PHYSFS_IMPLEMENTATION.
// #define RAYLIB_PHYSFS_IMPLEMENTATION
#define RAYLIB_PHYSFS_IMPLEMENTATION
#include "raylib-physfs.h"

int main(int argc, char *argv[]) {
Expand Down
1 change: 0 additions & 1 deletion vendor/raylib
Submodule raylib deleted from 085196

0 comments on commit a775f4d

Please sign in to comment.