PhysFSConfig.cmake 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # PhysicsFS CMake configuration file:
  2. # This file is meant to be placed in lib/cmake/PhysFS subfolder of a reconstructed Android PhysFS SDK
  3. cmake_minimum_required(VERSION 3.0...4.0)
  4. include(FeatureSummary)
  5. set_package_properties(PhysicsFS PROPERTIES
  6. URL "https://icculus.org/physfs/"
  7. DESCRIPTION "Library to provide abstract access to various archives"
  8. )
  9. # Copied from `configure_package_config_file`
  10. macro(set_and_check _var _file)
  11. set(${_var} "${_file}")
  12. if(NOT EXISTS "${_file}")
  13. message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
  14. endif()
  15. endmacro()
  16. # Copied from `configure_package_config_file`
  17. macro(check_required_components _NAME)
  18. foreach(comp ${${_NAME}_FIND_COMPONENTS})
  19. if(NOT ${_NAME}_${comp}_FOUND)
  20. if(${_NAME}_FIND_REQUIRED_${comp})
  21. set(${_NAME}_FOUND FALSE)
  22. endif()
  23. endif()
  24. endforeach()
  25. endmacro()
  26. set(PhysFS_FOUND TRUE)
  27. if(SDL_CPU_X86)
  28. set(_sdl_arch_subdir "x86")
  29. elseif(SDL_CPU_X64)
  30. set(_sdl_arch_subdir "x86_64")
  31. elseif(SDL_CPU_ARM32)
  32. set(_sdl_arch_subdir "armeabi-v7a")
  33. elseif(SDL_CPU_ARM64)
  34. set(_sdl_arch_subdir "arm64-v8a")
  35. else()
  36. set(PhysFS_FOUND FALSE)
  37. return()
  38. endif()
  39. get_filename_component(_physfs_prefix "${CMAKE_CURRENT_LIST_DIR}/../../.." ABSOLUTE)
  40. set_and_check(_physfs_prefix "${_physfs_prefix}")
  41. set_and_check(_physfs_include_dirs "${_physfs_prefix}/include")
  42. set_and_check(_physfs_lib "${_physfs_prefix}/lib/${_sdl_arch_subdir}/libphysfs.so")
  43. unset(_sdl_arch_subdir)
  44. unset(_physfs_prefix)
  45. # All targets are created, even when some might not be requested though COMPONENTS.
  46. # This is done for compatibility with CMake generated PhysFS-target.cmake files.
  47. if(EXISTS "${_physfs_lib}")
  48. if(NOT TARGET PhysFS::PhysFS-shared)
  49. add_library(PhysFS::PhysFS-shared SHARED IMPORTED)
  50. set_target_properties(PhysFS::PhysFS-shared
  51. PROPERTIES
  52. INTERFACE_INCLUDE_DIRECTORIES "${_physfs_include_dirs}"
  53. IMPORTED_LOCATION "${_physfs_lib}"
  54. )
  55. endif()
  56. set(PhysFS_PhysFS-shared_FOUND TRUE)
  57. else()
  58. set(PhysFS_PhysFS-shared_FOUND FALSE)
  59. endif()
  60. unset(_physfs_lib)
  61. unset(_physfs_include_dirs)
  62. set(PhysFS_PhysFS-static_FOUND FALSE)
  63. if(PhysFS_PhysFS-shared_FOUND)
  64. set(PhysFS_PhysFS_FOUND TRUE)
  65. endif()
  66. function(_sdl_create_target_alias_compat NEW_TARGET TARGET)
  67. if(CMAKE_VERSION VERSION_LESS "3.18")
  68. # Aliasing local targets is not supported on CMake < 3.18, so make it global.
  69. add_library(${NEW_TARGET} INTERFACE IMPORTED)
  70. set_target_properties(${NEW_TARGET} PROPERTIES INTERFACE_LINK_LIBRARIES "${TARGET}")
  71. else()
  72. add_library(${NEW_TARGET} ALIAS ${TARGET})
  73. endif()
  74. endfunction()
  75. # Make sure PhysFS::PhysFS always exists
  76. if(NOT TARGET PhysFS::PhysFS)
  77. if(TARGET PhysFS::PhysFS-shared)
  78. _sdl_create_target_alias_compat(PhysFS::PhysFS PhysFS::PhysFS-shared)
  79. endif()
  80. endif()
  81. check_required_components(PhysFS)