Просмотр исходного кода

cmake: export SDL3 dependency such that using physfs' config files "just work"

Anonymous Maarten 2 дней назад
Родитель
Сommit
fba28fd82a
3 измененных файлов с 19 добавлено и 9 удалено
  1. 10 9
      CMakeLists.txt
  2. 8 0
      cmake/PhysFSConfig.cmake.in
  3. 1 0
      cmake/physfs.pc.in

+ 10 - 9
CMakeLists.txt

@@ -24,6 +24,8 @@ include("${PROJECT_SOURCE_DIR}/cmake/sdlmanpages.cmake")
 # Increment this if/when we break backwards compatibility.
 set(PHYSFS_SOVERSION 1)
 
+set(PC_PRIVATE_REQUIRES "")
+
 set(PHYSFS_M_SRCS)
 set(PHYSFS_CPP_SRCS)
 
@@ -196,8 +198,8 @@ endif()
 
 option(PHYSFS_PLATFORM_SDL3 "Enable building for the SDL3 file system" FALSE)
 if(PHYSFS_PLATFORM_SDL3)
-    find_package(SDL3 REQUIRED CONFIG REQUIRED COMPONENTS SDL3)
-    add_definitions(-DPHYSFS_PLATFORM_SDL3=1)
+    find_package(SDL3 REQUIRED CONFIG REQUIRED COMPONENTS Headers SDL3)
+    list(APPEND PC_PRIVATE_REQUIRES "sdl3")
 endif()
 
 if(EMSCRIPTEN)
@@ -230,6 +232,7 @@ if(PHYSFS_BUILD_STATIC)
         target_compile_definitions(physfs-static PRIVATE "PHYSFS_STATIC")
     endif()
     if(PHYSFS_PLATFORM_SDL3)
+        target_compile_definitions(physfs-static PRIVATE PHYSFS_PLATFORM_SDL3=1)
         target_link_libraries(physfs-static PUBLIC SDL3::Headers)
     endif()
     target_include_directories(physfs-static PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>")
@@ -260,7 +263,9 @@ if(PHYSFS_BUILD_SHARED)
         set_property(TARGET physfs-shared PROPERTY VS_WINRT_COMPONENT TRUE)
     endif()
     if(PHYSFS_PLATFORM_SDL3)
-        target_link_libraries(physfs-shared PUBLIC SDL3::SDL3-shared)
+        target_compile_definitions(physfs-shared PRIVATE PHYSFS_PLATFORM_SDL3=1)
+        target_link_libraries(physfs-shared PUBLIC SDL3::Headers)
+        target_link_libraries(physfs-shared PRIVATE SDL3::SDL3-shared)
     endif()
     target_include_directories(physfs-shared PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>")
     target_link_libraries(physfs-shared PRIVATE ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS})
@@ -283,9 +288,6 @@ if(PHYSFS_BUILD_TEST)
     add_executable(test_physfs test/test_physfs.c)
     target_link_libraries(test_physfs PRIVATE PhysFS::PhysFS)
     sdl_add_warning_options(test_physfs WARNING_AS_ERROR ${PHYSFS_WERROR})
-    if(PHYSFS_PLATFORM_SDL3)
-        target_link_libraries(test_physfs PRIVATE SDL3::SDL3)
-    endif()
     if(DOS)
         set_target_properties(test_physfs PROPERTIES OUTPUT_NAME "TESTPHYS")   # 8.3 file names!
     endif()
@@ -305,9 +307,6 @@ if(PHYSFS_BUILD_TEST)
     if(UNIX)
         add_executable(physfshttpd extras/physfshttpd.c)
         target_link_libraries(physfshttpd PRIVATE PhysFS::PhysFS)
-        if(PHYSFS_PLATFORM_SDL3)
-            target_link_libraries(physfshttpd PRIVATE SDL3::SDL3)
-        endif()
         sdl_add_warning_options(physfshttpd WARNING_AS_ERROR ${PHYSFS_WERROR})
     endif()
 endif()
@@ -375,6 +374,7 @@ if(PHYSFS_INSTALL)
     install(FILES LICENSE.txt
         DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/licenses/PhysicsFS${PROJECT_VERSION_MAJOR}")
 
+    string(REPLACE ";" " " PC_PRIVATE_REQUIRES "${PC_PRIVATE_REQUIRES}")
     configure_file(cmake/cmake_uninstall.cmake.in cmake_uninstall.cmake IMMEDIATE @ONLY)
     add_custom_target(uninstall-physfs
         COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
@@ -450,6 +450,7 @@ message_bool_option("VDF support" PHYSFS_ARCHIVE_VDF)
 message_bool_option("ISO9660 support" PHYSFS_ARCHIVE_ISO9660)
 message_bool_option("GOB/LAB/LFD support" PHYSFS_ARCHIVE_LECARCHIVES)
 message_bool_option("POD support" PHYSFS_ARCHIVE_POD)
+message_bool_option("SDL3 filesystem support" PHYSFS_PLATFORM_SDL3)
 message_bool_option("Build static library" PHYSFS_BUILD_STATIC)
 message_bool_option("Build shared library" PHYSFS_BUILD_SHARED)
 message_bool_option("Build stdio test program" PHYSFS_BUILD_TEST)

+ 8 - 0
cmake/PhysFSConfig.cmake.in

@@ -6,6 +6,8 @@ set_package_properties(PhysicsFS PROPERTIES
 
 @PACKAGE_INIT@
 
+set(PHYSFS_PLATFORM_SDL3 @PHYSFS_PLATFORM_SDL3@)
+
 set(PhysFS_PhysFS_FOUND)
 
 set(PhysFS_PhysFS-shared_FOUND)
@@ -17,6 +19,12 @@ endif()
 
 set(PhysFS_PhysFS-static_FOUND)
 if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/PhysFS-static-targets.cmake")
+
+    if(PHYSFS_PLATFORM_SDL3)
+        include(CMakeFindDependencyMacro)
+        find_dependency(SDL3)
+    endif()
+
     include("${CMAKE_CURRENT_LIST_DIR}/PhysFS-static-targets.cmake")
     set(PhysFS_PhysFS-static_FOUND TRUE)
     set(PhysFS_PhysFS_FOUND TRUE)

+ 1 - 0
cmake/physfs.pc.in

@@ -7,5 +7,6 @@ Name: PhysicsFS
 Description: PhysicsFS is a library to provide abstract access to various archives.
 URL: https://icculus.org/physfs/
 Version: @PHYSFS_VERSION@
+Requires.private: @PC_PRIVATE_REQUIRES@
 Libs: -L${libdir} -lphysfs
 Cflags: -I${includedir}