PhysFSConfig.cmake.in 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # @<@PROJECT_NAME@>@ CMake configuration file:
  2. # This file is meant to be placed in a cmake subfolder of @<@PROJECT_NAME@>@-devel-@<@PROJECT_VERSION@>@-VC.zip
  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 OR SDL_CPU_ARM64EC)
  30. set(_sdl_arch_subdir "x64")
  31. elseif(SDL_CPU_ARM64)
  32. set(_sdl_arch_subdir "arm64")
  33. else()
  34. set(PhysFS_FOUND FALSE)
  35. return()
  36. endif()
  37. get_filename_component(_physfs_prefix "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE)
  38. set_and_check(_physfs_prefix "${_physfs_prefix}")
  39. set(_physfs_include_dirs "${_physfs_prefix}/include")
  40. set(_physfs_implib "${_physfs_prefix}/lib/${_sdl_arch_subdir}/physfs.lib")
  41. set(_physfs_dll "${_physfs_prefix}/lib/${_sdl_arch_subdir}/physfs.dll")
  42. unset(_sdl_arch_subdir)
  43. unset(_physfs_prefix)
  44. # All targets are created, even when some might not be requested though COMPONENTS.
  45. # This is done for compatibility with CMake generated PhysFS-target.cmake files.
  46. if(EXISTS "${_physfs_implib}" AND EXISTS "${_physfs_dll}")
  47. if(NOT TARGET PhysFS::PhysFS-shared)
  48. add_library(PhysFS::PhysFS-shared SHARED IMPORTED)
  49. set_target_properties(PhysFS::PhysFS-shared
  50. PROPERTIES
  51. INTERFACE_INCLUDE_DIRECTORIES "${_physfs_include_dirs}"
  52. IMPORTED_IMPLIB "${_physfs_implib}"
  53. IMPORTED_LOCATION "${_physfs_dll}"
  54. )
  55. endif()
  56. set(PhysFS_PhysFS-shared_FOUND TRUE)
  57. else()
  58. set(PhysFS_PhysFS-shared_FOUND FALSE)
  59. endif()
  60. unset(_physfs_implib)
  61. unset(_physfs_dll)
  62. unset(_physfs_include_dirs)
  63. set(PhysFS_PhysFS-static_FOUND FALSE)
  64. if(PhysFS_PhysFS-shared_FOUND OR PhysFS_PhysFS-static_FOUND)
  65. set(PhysFS_PhysFS_FOUND TRUE)
  66. endif()
  67. function(_sdl_create_target_alias_compat NEW_TARGET TARGET)
  68. if(CMAKE_VERSION VERSION_LESS "3.18")
  69. # Aliasing local targets is not supported on CMake < 3.18, so make it global.
  70. add_library(${NEW_TARGET} INTERFACE IMPORTED)
  71. set_target_properties(${NEW_TARGET} PROPERTIES INTERFACE_LINK_LIBRARIES "${TARGET}")
  72. else()
  73. add_library(${NEW_TARGET} ALIAS ${TARGET})
  74. endif()
  75. endfunction()
  76. # Make sure PhysFS::PhysFS always exists
  77. if(NOT TARGET PhysFS::PhysFS)
  78. if(TARGET PhysFS::PhysFS-shared)
  79. _sdl_create_target_alias_compat(PhysFS::PhysFS PhysFS::PhysFS-shared)
  80. endif()
  81. endif()
  82. check_required_components(PhysFS)