Skip to content

Commit a775f4d

Browse files
committed
Use CMake to download raylib -- fixes #6
1 parent 6081d91 commit a775f4d

File tree

11 files changed

+37
-55
lines changed

11 files changed

+37
-55
lines changed

.gitmodules

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
[submodule "vendor/raylib"]
2-
path = vendor/raylib
3-
url = https://github.com/raysan5/raylib.git
4-
ignore = dirty
51
[submodule "vendor/physfs"]
62
path = vendor/physfs
73
url = https://github.com/icculus/physfs.git

CMakeLists.txt

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.11)
22
project (raylib-physfs
3-
VERSION 4.0.1
3+
VERSION 4.0.2
44
DESCRIPTION "raylib-physfs"
55
HOMEPAGE_URL "https://github.com/robloach/raylib-physfs"
66
LANGUAGES C
@@ -9,23 +9,24 @@ project (raylib-physfs
99
# Include Directory
1010
add_subdirectory(include)
1111

12-
# Static Library
13-
option(BUILD_RAYLIB_PHYSFS_LIB "Library" ON)
14-
if(BUILD_RAYLIB_PHYSFS_LIB)
15-
add_subdirectory(lib)
12+
# Options
13+
if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
14+
set(RAYLIB_PHYSFS_IS_MAIN TRUE)
15+
else()
16+
set(RAYLIB_PHYSFS_IS_MAIN FALSE)
1617
endif()
18+
option(RAYLIB_PHYSFS_BUILD_EXAMPLES "Examples" ${RAYLIB_PHYSFS_IS_MAIN})
1719

1820
# Examples
19-
option(BUILD_RAYLIB_PHYSFS_EXAMPLES "Examples" ON)
20-
if(BUILD_RAYLIB_PHYSFS_EXAMPLES)
21+
if (RAYLIB_PHYSFS_BUILD_EXAMPLES)
2122
add_subdirectory(examples)
22-
endif()
2323

24-
# Testing
25-
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
26-
include(CTest)
27-
enable_testing()
28-
if(BUILD_TESTING AND BUILD_RAYLIB_PHYSFS_LIB)
29-
add_subdirectory(test)
24+
# Testing
25+
if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
26+
include(CTest)
27+
enable_testing()
28+
if (BUILD_TESTING)
29+
add_subdirectory(test)
30+
endif()
3031
endif()
3132
endif()

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ To build the examples locally, and run tests, use [cmake](https://cmake.org/).
8282
``` bash
8383
git clone https://github.com/RobLoach/raylib-physfs.git
8484
cd raylib-physfs
85-
git submodule update --init
8685
mkdir build
8786
cd build
8887
cmake ..

examples/CMakeLists.txt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,20 @@ set(example_resources)
66
# raylib
77
find_package(raylib QUIET)
88
if (NOT raylib_FOUND)
9-
set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) # don't build the supplied examples
10-
set(BUILD_GAMES OFF CACHE BOOL "" FORCE) # or games
11-
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../vendor/raylib ${CMAKE_CURRENT_SOURCE_DIR}/../vendor/raylib)
9+
include(FetchContent)
10+
FetchContent_Declare(
11+
raylib
12+
GIT_REPOSITORY https://github.com/raysan5/raylib.git
13+
GIT_TAG 4.0.0
14+
)
15+
FetchContent_GetProperties(raylib)
16+
if (NOT raylib_POPULATED) # Have we downloaded raylib yet?
17+
set(FETCHCONTENT_QUIET NO)
18+
FetchContent_Populate(raylib)
19+
set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
20+
set(BUILD_GAMES OFF CACHE BOOL "" FORCE)
21+
add_subdirectory(${raylib_SOURCE_DIR} ${raylib_BINARY_DIR})
22+
endif()
1223
endif()
1324

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

3344
# Link raylib and raylib-cpp
34-
target_link_libraries(${example_name} PUBLIC raylib raylib-physfs)
45+
target_link_libraries(${example_name} PUBLIC raylib raylib_physfs)
3546

3647
target_compile_definitions(${example_name} PUBLIC
3748
PHYSFS_SUPPORTS_NO_ZIP

examples/audio/audio_sound_loading.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ int main(void)
2626
InitAudioDevice(); // Initialize audio device
2727

2828
InitPhysFS(); // Initialize PhysFS
29-
MountPhysFS("resources", ""); // Mount the resources directory.
29+
MountPhysFS("resources", "res"); // Mount the resources directory.
3030

31-
Wave wav = LoadWaveFromPhysFS("sound.wav");
32-
Wave ogg = LoadWaveFromPhysFS("target.ogg");
31+
Wave wav = LoadWaveFromPhysFS("res/sound.wav");
32+
Wave ogg = LoadWaveFromPhysFS("res/target.ogg");
3333

3434
Sound fxWav = LoadSoundFromWave(wav); // Load WAV audio file
3535
Sound fxOgg = LoadSoundFromWave(ogg); // Load OGG audio file

include/CMakeLists.txt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
add_library(raylib-physfs INTERFACE)
1+
add_library(raylib_physfs INTERFACE)
22

33
# Include Directory
4-
target_include_directories(raylib-physfs INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/)
5-
6-
# Options
7-
option(RAYLIB_PHYSFS_STATIC "Static Definition" OFF)
8-
if (RAYLIB_PHYSFS_STATIC)
9-
target_compile_definitions(raylib-physfs INTERFACE RAYLIB_PHYSFS_STATIC)
10-
endif()
4+
target_include_directories(raylib_physfs INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/)
115

126
# Set the header files as install files.
137
install(FILES raylib-physfs.h miniphysfs.h

lib/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

lib/raylib-physfs.c

Lines changed: 0 additions & 13 deletions
This file was deleted.

test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
add_executable(raylib-physfs-test raylib-physfs-test.c)
33
target_link_libraries(raylib-physfs-test PUBLIC
44
raylib
5-
raylib-physfs-static
5+
raylib_physfs
66
)
77

88
# Copy the resources

test/raylib-physfs-test.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#include <assert.h>
22
#include "raylib.h"
33

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

87
int main(int argc, char *argv[]) {

0 commit comments

Comments
 (0)