🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

345 lines
12 KiB

  1. # PhysicsFS; a portable, flexible file i/o abstraction.
  2. #
  3. # Please see the file LICENSE.txt in the source's root directory.
  4. # The CMake project file is meant to get this compiling on all sorts of
  5. # platforms quickly, and serve as the way Unix platforms and Linux distros
  6. # package up official builds, but you don't _need_ to use this; we have
  7. # built PhysicsFS to (hopefully) be able to drop into your project and
  8. # compile, using preprocessor checks for platform-specific bits instead of
  9. # testing in here.
  10. set(PHYSFS_VERSION 3.2.0)
  11. cmake_minimum_required(VERSION 3.0)
  12. project(PhysicsFS VERSION ${PHYSFS_VERSION} LANGUAGES C )
  13. include(GNUInstallDirs)
  14. # Increment this if/when we break backwards compatibility.
  15. set(PHYSFS_SOVERSION 1)
  16. set(PHYSFS_M_SRCS)
  17. set(PHYSFS_CPP_SRCS)
  18. # I hate that they define "WIN32" ... we're about to move to Win64...I hope!
  19. if(APPLE)
  20. set(OTHER_LDFLAGS ${OTHER_LDFLAGS} "-framework IOKit -framework Foundation")
  21. list(APPEND PHYSFS_M_SRCS src/physfs_platform_apple.m)
  22. endif()
  23. if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
  24. add_compile_options(-Wall)
  25. # Don't use -rpath.
  26. set(CMAKE_SKIP_RPATH ON CACHE BOOL "Skip RPATH" FORCE)
  27. endif()
  28. if(CMAKE_C_COMPILER_ID STREQUAL "SunPro")
  29. add_definitions(-erroff=E_EMPTY_TRANSLATION_UNIT)
  30. add_definitions(-xldscope=hidden)
  31. endif()
  32. if(HAIKU)
  33. # We add this explicitly, since we don't want CMake to think this
  34. # is a C++ project unless we're on Haiku.
  35. list(APPEND PHYSFS_CPP_SRCS src/physfs_platform_haiku.cpp)
  36. find_library(BE_LIBRARY be)
  37. find_library(ROOT_LIBRARY root)
  38. list(APPEND OPTIONAL_LIBRARY_LIBS ${BE_LIBRARY} ${ROOT_LIBRARY})
  39. endif()
  40. if(CMAKE_SYSTEM_NAME STREQUAL "WindowsPhone" OR CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
  41. set(WINRT TRUE)
  42. endif()
  43. if(WINRT)
  44. list(APPEND PHYSFS_CPP_SRCS src/physfs_platform_winrt.cpp)
  45. endif()
  46. if(UNIX AND NOT WIN32 AND NOT APPLE) # (MingW and such might be UNIX _and_ WINDOWS!)
  47. find_library(PTHREAD_LIBRARY pthread)
  48. if(PTHREAD_LIBRARY)
  49. set(OPTIONAL_LIBRARY_LIBS ${OPTIONAL_LIBRARY_LIBS} ${PTHREAD_LIBRARY})
  50. endif()
  51. endif()
  52. if(PHYSFS_CPP_SRCS)
  53. enable_language(CXX)
  54. endif()
  55. # Almost everything is "compiled" here, but things that don't apply to the
  56. # build are #ifdef'd out. This is to make it easy to embed PhysicsFS into
  57. # another project or bring up a new build system: just compile all the source
  58. # code and #define the things you want.
  59. set(PHYSFS_SRCS
  60. src/physfs.c
  61. src/physfs_byteorder.c
  62. src/physfs_unicode.c
  63. src/physfs_platform_posix.c
  64. src/physfs_platform_unix.c
  65. src/physfs_platform_windows.c
  66. src/physfs_platform_os2.c
  67. src/physfs_platform_qnx.c
  68. src/physfs_platform_android.c
  69. src/physfs_archiver_dir.c
  70. src/physfs_archiver_unpacked.c
  71. src/physfs_archiver_grp.c
  72. src/physfs_archiver_hog.c
  73. src/physfs_archiver_7z.c
  74. src/physfs_archiver_mvl.c
  75. src/physfs_archiver_qpak.c
  76. src/physfs_archiver_wad.c
  77. src/physfs_archiver_zip.c
  78. src/physfs_archiver_slb.c
  79. src/physfs_archiver_iso9660.c
  80. src/physfs_archiver_vdf.c
  81. ${PHYSFS_CPP_SRCS}
  82. ${PHYSFS_M_SRCS}
  83. )
  84. # Archivers ...
  85. # These are (mostly) on by default now, so these options are only useful for
  86. # disabling them.
  87. option(PHYSFS_ARCHIVE_ZIP "Enable ZIP support" TRUE)
  88. if(NOT PHYSFS_ARCHIVE_ZIP)
  89. add_definitions(-DPHYSFS_SUPPORTS_ZIP=0)
  90. endif()
  91. option(PHYSFS_ARCHIVE_7Z "Enable 7zip support" TRUE)
  92. if(NOT PHYSFS_ARCHIVE_7Z)
  93. add_definitions(-DPHYSFS_SUPPORTS_7Z=0)
  94. endif()
  95. option(PHYSFS_ARCHIVE_GRP "Enable Build Engine GRP support" TRUE)
  96. if(NOT PHYSFS_ARCHIVE_GRP)
  97. add_definitions(-DPHYSFS_SUPPORTS_GRP=0)
  98. endif()
  99. option(PHYSFS_ARCHIVE_WAD "Enable Doom WAD support" TRUE)
  100. if(NOT PHYSFS_ARCHIVE_WAD)
  101. add_definitions(-DPHYSFS_SUPPORTS_WAD=0)
  102. endif()
  103. option(PHYSFS_ARCHIVE_HOG "Enable Descent I/II HOG support" TRUE)
  104. if(NOT PHYSFS_ARCHIVE_HOG)
  105. add_definitions(-DPHYSFS_SUPPORTS_HOG=0)
  106. endif()
  107. option(PHYSFS_ARCHIVE_MVL "Enable Descent I/II MVL support" TRUE)
  108. if(NOT PHYSFS_ARCHIVE_MVL)
  109. add_definitions(-DPHYSFS_SUPPORTS_MVL=0)
  110. endif()
  111. option(PHYSFS_ARCHIVE_QPAK "Enable Quake I/II QPAK support" TRUE)
  112. if(NOT PHYSFS_ARCHIVE_QPAK)
  113. add_definitions(-DPHYSFS_SUPPORTS_QPAK=0)
  114. endif()
  115. option(PHYSFS_ARCHIVE_SLB "Enable I-War / Independence War SLB support" TRUE)
  116. if(NOT PHYSFS_ARCHIVE_SLB)
  117. add_definitions(-DPHYSFS_SUPPORTS_SLB=0)
  118. endif()
  119. option(PHYSFS_ARCHIVE_ISO9660 "Enable ISO9660 support" TRUE)
  120. if(NOT PHYSFS_ARCHIVE_ISO9660)
  121. add_definitions(-DPHYSFS_SUPPORTS_ISO9660=0)
  122. endif()
  123. option(PHYSFS_ARCHIVE_VDF "Enable Gothic I/II VDF archive support" TRUE)
  124. if(NOT PHYSFS_ARCHIVE_VDF)
  125. add_definitions(-DPHYSFS_SUPPORTS_VDF=0)
  126. endif()
  127. option(PHYSFS_BUILD_STATIC "Build static library" TRUE)
  128. if(PHYSFS_BUILD_STATIC)
  129. add_library(physfs-static STATIC ${PHYSFS_SRCS})
  130. add_library(PhysFS::PhysFS-static ALIAS physfs-static)
  131. set_target_properties(physfs-static PROPERTIES EXPORT_NAME PhysFS-static)
  132. # Don't rename this on Windows, since DLLs will also produce an import
  133. # library named "physfs.lib" which would conflict; Unix tend to like the
  134. # same library name with a different extension for static libs, but
  135. # Windows can just have a separate name.
  136. if(NOT MSVC)
  137. set_target_properties(physfs-static PROPERTIES OUTPUT_NAME "physfs")
  138. endif()
  139. if(WINRT)
  140. # Ignore LNK4264 warnings; we don't author any WinRT components, just consume them, so we're okay in a static library.
  141. set_target_properties(physfs-static PROPERTIES VS_WINRT_COMPONENT True)
  142. set_target_properties(physfs-static PROPERTIES STATIC_LIBRARY_FLAGS "/ignore:4264")
  143. endif()
  144. if(WIN32 OR WINRT OR OS2)
  145. # no dll exports from the static library
  146. target_compile_definitions(physfs-static PRIVATE "PHYSFS_STATIC")
  147. endif()
  148. target_include_directories(physfs-static PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>")
  149. target_link_libraries(physfs-static PRIVATE ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS})
  150. set(PHYSFS_LIB_TARGET physfs-static)
  151. list(APPEND PHYSFS_INSTALL_TARGETS "physfs-static")
  152. endif()
  153. option(PHYSFS_BUILD_SHARED "Build shared library" TRUE)
  154. if(PHYSFS_BUILD_SHARED)
  155. add_library(physfs SHARED ${PHYSFS_SRCS})
  156. add_library(PhysFS::PhysFS ALIAS physfs)
  157. set_target_properties(physfs PROPERTIES MACOSX_RPATH 1)
  158. set_target_properties(physfs PROPERTIES VERSION ${PHYSFS_VERSION})
  159. set_target_properties(physfs PROPERTIES SOVERSION ${PHYSFS_SOVERSION})
  160. set_target_properties(physfs PROPERTIES EXPORT_NAME PhysFS)
  161. if(WINRT)
  162. set_target_properties(physfs PROPERTIES VS_WINRT_COMPONENT True)
  163. endif()
  164. if(OS2) # OS/2 does not support a DLL name longer than 8 characters.
  165. set_target_properties(physfs PROPERTIES OUTPUT_NAME "physfs")
  166. endif()
  167. target_include_directories(physfs PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>")
  168. target_link_libraries(physfs PRIVATE ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS})
  169. set(PHYSFS_LIB_TARGET physfs)
  170. list(APPEND PHYSFS_INSTALL_TARGETS "physfs")
  171. endif()
  172. if(NOT PHYSFS_BUILD_SHARED AND NOT PHYSFS_BUILD_STATIC)
  173. message(FATAL "Both shared and static libraries are disabled!")
  174. endif()
  175. # CMake FAQ says I need this...
  176. if(PHYSFS_BUILD_SHARED AND PHYSFS_BUILD_STATIC AND NOT WIN32)
  177. set_target_properties(physfs PROPERTIES CLEAN_DIRECT_OUTPUT 1)
  178. set_target_properties(physfs-static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
  179. endif()
  180. option(PHYSFS_BUILD_TEST "Build stdio test program." TRUE)
  181. mark_as_advanced(PHYSFS_BUILD_TEST)
  182. if(PHYSFS_BUILD_TEST)
  183. find_path(READLINE_H readline/readline.h)
  184. find_path(HISTORY_H readline/history.h)
  185. if(READLINE_H AND HISTORY_H)
  186. find_library(CURSES_LIBRARY NAMES curses ncurses)
  187. if(CURSES_LIBRARY)
  188. set(CMAKE_REQUIRED_LIBRARIES ${CURSES_LIBRARY})
  189. find_library(READLINE_LIBRARY readline)
  190. if(READLINE_LIBRARY)
  191. set(HAVE_SYSTEM_READLINE TRUE)
  192. list(APPEND TEST_PHYSFS_LIBS ${READLINE_LIBRARY} ${CURSES_LIBRARY})
  193. include_directories(SYSTEM ${READLINE_H} ${HISTORY_H})
  194. add_definitions(-DPHYSFS_HAVE_READLINE=1)
  195. endif()
  196. endif()
  197. endif()
  198. add_executable(test_physfs test/test_physfs.c)
  199. target_link_libraries(test_physfs PRIVATE ${PHYSFS_LIB_TARGET} ${TEST_PHYSFS_LIBS} ${OTHER_LDFLAGS})
  200. list(APPEND PHYSFS_INSTALL_TARGETS test_physfs)
  201. endif()
  202. option(PHYSFS_DISABLE_INSTALL "Disable installing PhysFS" OFF)
  203. if(NOT PHYSFS_DISABLE_INSTALL)
  204. install(TARGETS ${PHYSFS_INSTALL_TARGETS} EXPORT PhysFSExport
  205. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  206. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  207. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  208. INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
  209. install(FILES src/physfs.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
  210. install(EXPORT PhysFSExport
  211. DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/PhysFS"
  212. FILE PhysFSConfig.cmake
  213. NAMESPACE PhysFS::
  214. )
  215. if(NOT MSVC)
  216. configure_file(
  217. "extras/physfs.pc.in"
  218. "extras/physfs.pc"
  219. @ONLY
  220. )
  221. install(
  222. FILES "${CMAKE_CURRENT_BINARY_DIR}/extras/physfs.pc"
  223. DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
  224. )
  225. endif()
  226. endif()
  227. option(PHYSFS_BUILD_DOCS "Build doxygen based documentation" TRUE)
  228. if(PHYSFS_BUILD_DOCS)
  229. find_package(Doxygen)
  230. if(DOXYGEN_FOUND)
  231. set(PHYSFS_OUTPUT_DOXYFILE "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile")
  232. configure_file(
  233. "${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile"
  234. "${PHYSFS_OUTPUT_DOXYFILE}"
  235. COPYONLY
  236. )
  237. file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "\n\n# Below auto-generated by cmake...\n\n")
  238. file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "PROJECT_NUMBER = \"${PHYSFS_VERSION}\"\n")
  239. file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "OUTPUT_DIRECTORY = \"${CMAKE_CURRENT_BINARY_DIR}/docs\"\n")
  240. file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "\n# End auto-generated section.\n\n")
  241. set(PHYSFS_TARGETNAME_DOCS "docs" CACHE STRING "Name of 'docs' build target")
  242. add_custom_target(
  243. ${PHYSFS_TARGETNAME_DOCS}
  244. ${DOXYGEN_EXECUTABLE} "${PHYSFS_OUTPUT_DOXYFILE}"
  245. WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
  246. COMMENT "Building documentation in 'docs' directory..."
  247. )
  248. else()
  249. message(STATUS "Doxygen not found. You won't be able to build documentation.")
  250. endif()
  251. endif()
  252. if(UNIX)
  253. set(PHYSFS_TARBALL "${CMAKE_CURRENT_SOURCE_DIR}/../physfs-${PHYSFS_VERSION}.tar.gz")
  254. set(PHYSFS_TARGETNAME_DIST "dist" CACHE STRING "Name of 'dist' build target")
  255. add_custom_target(
  256. ${PHYSFS_TARGETNAME_DIST}
  257. git archive --prefix="physfs-${PHYSFS_VERSION}/" --output="${PHYSFS_TARBALL}" HEAD
  258. WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
  259. COMMENT "Building source tarball '${PHYSFS_TARBALL}'..."
  260. )
  261. set(PHYSFS_TARGETNAME_UNINSTALL "uninstall" CACHE STRING "Name of 'uninstall' build target")
  262. add_custom_target(
  263. ${PHYSFS_TARGETNAME_UNINSTALL}
  264. "${CMAKE_CURRENT_SOURCE_DIR}/extras/uninstall.sh"
  265. WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
  266. COMMENT "Uninstall the project..."
  267. )
  268. endif()
  269. macro(message_bool_option _NAME _VALUE)
  270. if(${_VALUE})
  271. message(STATUS " ${_NAME}: enabled")
  272. else()
  273. message(STATUS " ${_NAME}: disabled")
  274. endif()
  275. endmacro()
  276. message(STATUS "PhysicsFS will build with the following options:")
  277. message_bool_option("ZIP support" PHYSFS_ARCHIVE_ZIP)
  278. message_bool_option("7zip support" PHYSFS_ARCHIVE_7Z)
  279. message_bool_option("GRP support" PHYSFS_ARCHIVE_GRP)
  280. message_bool_option("WAD support" PHYSFS_ARCHIVE_WAD)
  281. message_bool_option("HOG support" PHYSFS_ARCHIVE_HOG)
  282. message_bool_option("MVL support" PHYSFS_ARCHIVE_MVL)
  283. message_bool_option("QPAK support" PHYSFS_ARCHIVE_QPAK)
  284. message_bool_option("SLB support" PHYSFS_ARCHIVE_SLB)
  285. message_bool_option("VDF support" PHYSFS_ARCHIVE_VDF)
  286. message_bool_option("ISO9660 support" PHYSFS_ARCHIVE_ISO9660)
  287. message_bool_option("Build static library" PHYSFS_BUILD_STATIC)
  288. message_bool_option("Build shared library" PHYSFS_BUILD_SHARED)
  289. message_bool_option("Build stdio test program" PHYSFS_BUILD_TEST)
  290. message_bool_option("Build Doxygen documentation" PHYSFS_BUILD_DOCS)
  291. if(PHYSFS_BUILD_TEST)
  292. message_bool_option(" Use readline in test program" HAVE_SYSTEM_READLINE)
  293. endif()
  294. # end of CMakeLists.txt ...