From a775f4d7e4cff90128ec869d03dd026f3d46a8f4 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Mon, 17 Jan 2022 00:24:37 -0500 Subject: [PATCH] Use CMake to download raylib -- fixes #6 --- .gitmodules | 4 ---- CMakeLists.txt | 29 ++++++++++++++-------------- README.md | 1 - examples/CMakeLists.txt | 19 ++++++++++++++---- examples/audio/audio_sound_loading.c | 6 +++--- include/CMakeLists.txt | 10 ++-------- lib/CMakeLists.txt | 4 ---- lib/raylib-physfs.c | 13 ------------- test/CMakeLists.txt | 2 +- test/raylib-physfs-test.c | 3 +-- vendor/raylib | 1 - 11 files changed, 37 insertions(+), 55 deletions(-) delete mode 100644 lib/CMakeLists.txt delete mode 100644 lib/raylib-physfs.c delete mode 160000 vendor/raylib diff --git a/.gitmodules b/.gitmodules index e0b66a6..a3bd9e2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 213cd4b..ac98903 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 @@ -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() diff --git a/README.md b/README.md index 33ba8b2..34a9801 100644 --- a/README.md +++ b/README.md @@ -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 .. diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 54c17e4..19f3840 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -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 @@ -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 diff --git a/examples/audio/audio_sound_loading.c b/examples/audio/audio_sound_loading.c index 103a80b..50c51ca 100644 --- a/examples/audio/audio_sound_loading.c +++ b/examples/audio/audio_sound_loading.c @@ -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 diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 7ec8f69..b3fde78 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -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 diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt deleted file mode 100644 index 81adad4..0000000 --- a/lib/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -# Static Library -add_library(raylib-physfs-static STATIC raylib-physfs.c) -target_link_libraries(raylib-physfs-static PUBLIC raylib_static raylib-physfs) -#target_compile_definitions(raylib-physfs-static PUBLIC RAYLIB_PHYSFS_STATIC) diff --git a/lib/raylib-physfs.c b/lib/raylib-physfs.c deleted file mode 100644 index a0d26c1..0000000 --- a/lib/raylib-physfs.c +++ /dev/null @@ -1,13 +0,0 @@ -/********************************************************************************************** -* -* raylib-physfs-static - Pre-compiled static library for raylib-physfs. -* -* Copyright 2021 Rob Loach (@RobLoach) -* -* DEPENDENCIES: -* raylib 4 https://www.raylib.com/ -* -**********************************************************************************************/ - -#define RAYLIB_PHYSFS_IMPLEMENTATION -#include "raylib-physfs.h" diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 1f8ebd0..e1b9a8e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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 diff --git a/test/raylib-physfs-test.c b/test/raylib-physfs-test.c index c613a8d..2b55bc7 100644 --- a/test/raylib-physfs-test.c +++ b/test/raylib-physfs-test.c @@ -1,8 +1,7 @@ #include #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[]) { diff --git a/vendor/raylib b/vendor/raylib deleted file mode 160000 index 0851960..0000000 --- a/vendor/raylib +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 0851960397f02a477d80eda2239f90fae14dec64