CMakeLists.txt 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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.3.0)
  11. cmake_minimum_required(VERSION 3.5...4.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. if(WIN32)
  19. list(APPEND OPTIONAL_LIBRARY_LIBS advapi32 shell32)
  20. endif()
  21. if(APPLE)
  22. set(OTHER_LDFLAGS ${OTHER_LDFLAGS} "-framework IOKit -framework Foundation")
  23. list(APPEND PHYSFS_M_SRCS src/physfs_platform_apple.m)
  24. endif()
  25. if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
  26. add_compile_options(-Wall)
  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. list(APPEND 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_ogc.c
  67. src/physfs_platform_os2.c
  68. src/physfs_platform_qnx.c
  69. src/physfs_platform_android.c
  70. src/physfs_platform_libretro.c
  71. src/physfs_platform_playdate.c
  72. src/physfs_archiver_dir.c
  73. src/physfs_archiver_unpacked.c
  74. src/physfs_archiver_grp.c
  75. src/physfs_archiver_hog.c
  76. src/physfs_archiver_7z.c
  77. src/physfs_archiver_mvl.c
  78. src/physfs_archiver_qpak.c
  79. src/physfs_archiver_wad.c
  80. src/physfs_archiver_csm.c
  81. src/physfs_archiver_zip.c
  82. src/physfs_archiver_slb.c
  83. src/physfs_archiver_iso9660.c
  84. src/physfs_archiver_vdf.c
  85. src/physfs_archiver_lec3d.c
  86. src/physfs_version.rc
  87. ${PHYSFS_CPP_SRCS}
  88. ${PHYSFS_M_SRCS}
  89. )
  90. # Archivers ...
  91. # These are (mostly) on by default now, so these options are only useful for
  92. # disabling them.
  93. option(PHYSFS_ARCHIVE_ZIP "Enable ZIP support" TRUE)
  94. if(NOT PHYSFS_ARCHIVE_ZIP)
  95. add_definitions(-DPHYSFS_SUPPORTS_ZIP=0)
  96. endif()
  97. option(PHYSFS_ARCHIVE_7Z "Enable 7zip support" TRUE)
  98. if(NOT PHYSFS_ARCHIVE_7Z)
  99. add_definitions(-DPHYSFS_SUPPORTS_7Z=0)
  100. endif()
  101. option(PHYSFS_ARCHIVE_GRP "Enable Build Engine GRP support" TRUE)
  102. if(NOT PHYSFS_ARCHIVE_GRP)
  103. add_definitions(-DPHYSFS_SUPPORTS_GRP=0)
  104. endif()
  105. option(PHYSFS_ARCHIVE_WAD "Enable Doom WAD support" TRUE)
  106. if(NOT PHYSFS_ARCHIVE_WAD)
  107. add_definitions(-DPHYSFS_SUPPORTS_WAD=0)
  108. endif()
  109. option(PHYSFS_ARCHIVE_CSM "Enable Chasm: The Rift CSM.BIN support" TRUE)
  110. if(NOT PHYSFS_ARCHIVE_CSM)
  111. add_definitions(-DPHYSFS_SUPPORTS_CSM=0)
  112. endif()
  113. option(PHYSFS_ARCHIVE_HOG "Enable Descent I/II HOG support" TRUE)
  114. if(NOT PHYSFS_ARCHIVE_HOG)
  115. add_definitions(-DPHYSFS_SUPPORTS_HOG=0)
  116. endif()
  117. option(PHYSFS_ARCHIVE_MVL "Enable Descent I/II MVL support" TRUE)
  118. if(NOT PHYSFS_ARCHIVE_MVL)
  119. add_definitions(-DPHYSFS_SUPPORTS_MVL=0)
  120. endif()
  121. option(PHYSFS_ARCHIVE_QPAK "Enable Quake I/II QPAK support" TRUE)
  122. if(NOT PHYSFS_ARCHIVE_QPAK)
  123. add_definitions(-DPHYSFS_SUPPORTS_QPAK=0)
  124. endif()
  125. option(PHYSFS_ARCHIVE_SLB "Enable I-War / Independence War SLB support" TRUE)
  126. if(NOT PHYSFS_ARCHIVE_SLB)
  127. add_definitions(-DPHYSFS_SUPPORTS_SLB=0)
  128. endif()
  129. option(PHYSFS_ARCHIVE_ISO9660 "Enable ISO9660 support" TRUE)
  130. if(NOT PHYSFS_ARCHIVE_ISO9660)
  131. add_definitions(-DPHYSFS_SUPPORTS_ISO9660=0)
  132. endif()
  133. option(PHYSFS_ARCHIVE_VDF "Enable Gothic I/II VDF archive support" TRUE)
  134. if(NOT PHYSFS_ARCHIVE_VDF)
  135. add_definitions(-DPHYSFS_SUPPORTS_VDF=0)
  136. endif()
  137. option(PHYSFS_ARCHIVE_LECARCHIVES "Enable LucasArts GOB/LAB/LFD Archive support" TRUE)
  138. if(NOT PHYSFS_ARCHIVE_LECARCHIVES)
  139. add_definitions(-DPHYSFS_SUPPORTS_LECARCHIVES=0)
  140. endif()
  141. option(PHYSFS_BUILD_STATIC "Build static library" TRUE)
  142. if(PHYSFS_BUILD_STATIC)
  143. add_library(physfs-static STATIC ${PHYSFS_SRCS})
  144. add_library(PhysFS::PhysFS-static ALIAS physfs-static)
  145. set_property(TARGET physfs-static PROPERTY EXPORT_NAME PhysFS-static)
  146. # Don't rename this on Windows, since DLLs will also produce an import
  147. # library named "physfs.lib" which would conflict; Unix tend to like the
  148. # same library name with a different extension for static libs, but
  149. # Windows can just have a separate name.
  150. if(NOT MSVC)
  151. set_property(TARGET physfs-static PROPERTY OUTPUT_NAME "physfs")
  152. endif()
  153. if(WINRT)
  154. # Ignore LNK4264 warnings; we don't author any WinRT components, just consume them, so we're okay in a static library.
  155. set_property(TARGET physfs-static PROPERTY VS_WINRT_COMPONENT TRUE)
  156. set_property(TARGET physfs-static PROPERTY STATIC_LIBRARY_FLAGS "/ignore:4264")
  157. endif()
  158. if(WIN32 OR WINRT OR OS2)
  159. # no dll exports from the static library
  160. target_compile_definitions(physfs-static PRIVATE "PHYSFS_STATIC")
  161. endif()
  162. target_include_directories(physfs-static PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>")
  163. target_link_libraries(physfs-static PRIVATE ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS})
  164. list(APPEND PHYSFS_INSTALL_TARGETS "physfs-static")
  165. endif()
  166. option(PHYSFS_BUILD_SHARED "Build shared library" TRUE)
  167. if(PHYSFS_BUILD_SHARED)
  168. add_library(physfs-shared SHARED ${PHYSFS_SRCS})
  169. add_library(PhysFS::PhysFS-shared ALIAS physfs-shared)
  170. set_property(TARGET physfs-shared PROPERTY OUTPUT_NAME "physfs")
  171. set_property(TARGET physfs-shared PROPERTY MACOSX_RPATH 1)
  172. set_property(TARGET physfs-shared PROPERTY VERSION ${PHYSFS_VERSION})
  173. set_property(TARGET physfs-shared PROPERTY SOVERSION ${PHYSFS_SOVERSION})
  174. set_property(TARGET physfs-shared PROPERTY EXPORT_NAME PhysFS-shared)
  175. if(WIN32)
  176. set_property(TARGET physfs-shared PROPERTY PREFIX "")
  177. endif()
  178. if(MINGW)
  179. target_link_options(physfs-shared PRIVATE -static-libgcc)
  180. endif()
  181. if(WINRT)
  182. set_property(TARGET physfs-shared PROPERTY VS_WINRT_COMPONENT TRUE)
  183. endif()
  184. target_include_directories(physfs-shared PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>")
  185. target_link_libraries(physfs-shared PRIVATE ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS})
  186. list(APPEND PHYSFS_INSTALL_TARGETS "physfs-shared")
  187. endif()
  188. if(NOT PHYSFS_BUILD_SHARED AND NOT PHYSFS_BUILD_STATIC)
  189. message(FATAL "Both shared and static libraries are disabled!")
  190. endif()
  191. if(TARGET physfs-shared)
  192. add_library(PhysFS::PhysFS ALIAS physfs-shared)
  193. elseif(TARGET PhysFS::PhysFS-static)
  194. add_library(PhysFS::PhysFS ALIAS physfs-static)
  195. endif()
  196. option(PHYSFS_BUILD_TEST "Build stdio test program." TRUE)
  197. mark_as_advanced(PHYSFS_BUILD_TEST)
  198. if(PHYSFS_BUILD_TEST)
  199. add_executable(test_physfs test/test_physfs.c)
  200. target_link_libraries(test_physfs PRIVATE PhysFS::PhysFS ${OTHER_LDFLAGS})
  201. find_path(READLINE_H readline/readline.h)
  202. find_path(HISTORY_H readline/history.h)
  203. find_library(READLINE_LIBRARY readline)
  204. find_package(Curses)
  205. if(READLINE_H AND HISTORY_H AND READLINE_LIBRARY AND CURSES_FOUND)
  206. set(HAVE_SYSTEM_READLINE TRUE)
  207. target_link_libraries(test_physfs PRIVATE ${READLINE_LIBRARY} ${CURSES_LIBRARIES})
  208. target_include_directories(test_physfs SYSTEM PRIVATE ${READLINE_H} ${HISTORY_H})
  209. target_compile_definitions(test_physfs PRIVATE PHYSFS_HAVE_READLINE=1)
  210. endif()
  211. list(APPEND PHYSFS_INSTALL_TARGETS test_physfs)
  212. if(UNIX)
  213. add_executable(physfshttpd extras/physfshttpd.c)
  214. target_link_libraries(physfshttpd PRIVATE PhysFS::PhysFS)
  215. sdl_add_warning_options(physfshttpd WARNING_AS_ERROR ${PHYSFS_WERROR})
  216. endif()
  217. endif()
  218. option(PHYSFS_INSTALL "Enable PhysFS installation" ON)
  219. if(PHYSFS_INSTALL)
  220. if(MSVC)
  221. set(PHYSFS_INSTALL_CMAKEDIR "cmake")
  222. else()
  223. set(PHYSFS_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/PhysFS")
  224. endif()
  225. if(TARGET physfs-shared)
  226. install(TARGETS physfs-shared EXPORT physfs-shared-exports
  227. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  228. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  229. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  230. INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
  231. install(EXPORT physfs-shared-exports
  232. DESTINATION "${PHYSFS_INSTALL_CMAKEDIR}"
  233. FILE PhysFS-shared-targets.cmake
  234. NAMESPACE PhysFS::
  235. )
  236. export(TARGETS physfs-shared NAMESPACE PhysFS:: FILE PhysFS-shared-targets.cmake)
  237. endif()
  238. if(TARGET physfs-static)
  239. install(TARGETS physfs-static EXPORT physfs-static-exports
  240. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  241. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  242. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  243. INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
  244. install(EXPORT physfs-static-exports
  245. DESTINATION "${PHYSFS_INSTALL_CMAKEDIR}"
  246. FILE PhysFS-static-targets.cmake
  247. NAMESPACE PhysFS::
  248. )
  249. export(TARGETS physfs-static NAMESPACE PhysFS:: FILE PhysFS-static-targets.cmake)
  250. endif()
  251. if(TARGET test_physfs)
  252. install(TARGETS test_physfs RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
  253. endif()
  254. install(FILES src/physfs.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
  255. include(CMakePackageConfigHelpers)
  256. configure_package_config_file(extras/PhysFSConfig.cmake.in PhysFSConfig.cmake
  257. NO_SET_AND_CHECK_MACRO
  258. PATH_VARS CMAKE_INSTALL_PREFIX
  259. INSTALL_DESTINATION "${PHYSFS_INSTALL_CMAKEDIR}"
  260. )
  261. write_basic_package_version_file(PhysFSConfigVersion.cmake
  262. COMPATIBILITY SameMajorVersion
  263. )
  264. install(FILES
  265. "${CMAKE_CURRENT_BINARY_DIR}/PhysFSConfig.cmake"
  266. "${CMAKE_CURRENT_BINARY_DIR}/PhysFSConfigVersion.cmake"
  267. DESTINATION "${PHYSFS_INSTALL_CMAKEDIR}"
  268. )
  269. install(FILES LICENSE.txt
  270. DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/licenses/PhysicsFS${PROJECT_VERSION_MAJOR}")
  271. configure_file(extras/cmake_uninstall.cmake.in cmake_uninstall.cmake IMMEDIATE @ONLY)
  272. add_custom_target(uninstall-physfs
  273. COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
  274. if(NOT MSVC)
  275. configure_file(
  276. "extras/physfs.pc.in"
  277. "extras/physfs.pc"
  278. @ONLY
  279. )
  280. install(
  281. FILES "${CMAKE_CURRENT_BINARY_DIR}/extras/physfs.pc"
  282. DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
  283. )
  284. endif()
  285. endif()
  286. option(PHYSFS_BUILD_DOCS "Build doxygen based documentation" TRUE)
  287. if(PHYSFS_BUILD_DOCS)
  288. find_package(Doxygen)
  289. if(DOXYGEN_FOUND)
  290. set(PHYSFS_OUTPUT_DOXYFILE "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile")
  291. configure_file(
  292. "${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile"
  293. "${PHYSFS_OUTPUT_DOXYFILE}"
  294. COPYONLY
  295. )
  296. file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "\n\n# Below auto-generated by cmake...\n\n")
  297. file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "PROJECT_NUMBER = \"${PHYSFS_VERSION}\"\n")
  298. file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "OUTPUT_DIRECTORY = \"${CMAKE_CURRENT_BINARY_DIR}/docs\"\n")
  299. file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "\n# End auto-generated section.\n\n")
  300. set(PHYSFS_TARGETNAME_DOCS "docs" CACHE STRING "Name of 'docs' build target")
  301. add_custom_target(
  302. ${PHYSFS_TARGETNAME_DOCS}
  303. ${DOXYGEN_EXECUTABLE} "${PHYSFS_OUTPUT_DOXYFILE}"
  304. WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
  305. COMMENT "Building documentation in 'docs' directory..."
  306. )
  307. else()
  308. message(STATUS "Doxygen not found. You won't be able to build documentation.")
  309. endif()
  310. endif()
  311. if(UNIX)
  312. set(PHYSFS_TARBALL "${CMAKE_CURRENT_SOURCE_DIR}/../physfs-${PHYSFS_VERSION}.tar.gz")
  313. set(PHYSFS_TARGETNAME_DIST "dist" CACHE STRING "Name of 'dist' build target")
  314. add_custom_target(
  315. ${PHYSFS_TARGETNAME_DIST}
  316. git archive --prefix="physfs-${PHYSFS_VERSION}/" --output="${PHYSFS_TARBALL}" HEAD
  317. WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
  318. COMMENT "Building source tarball '${PHYSFS_TARBALL}'..."
  319. )
  320. endif()
  321. macro(message_bool_option _NAME _VALUE)
  322. if(${_VALUE})
  323. message(STATUS " ${_NAME}: enabled")
  324. else()
  325. message(STATUS " ${_NAME}: disabled")
  326. endif()
  327. endmacro()
  328. message(STATUS "PhysicsFS will build with the following options:")
  329. message_bool_option("ZIP support" PHYSFS_ARCHIVE_ZIP)
  330. message_bool_option("7zip support" PHYSFS_ARCHIVE_7Z)
  331. message_bool_option("GRP support" PHYSFS_ARCHIVE_GRP)
  332. message_bool_option("WAD support" PHYSFS_ARCHIVE_WAD)
  333. message_bool_option("CSM support" PHYSFS_ARCHIVE_CSM)
  334. message_bool_option("HOG support" PHYSFS_ARCHIVE_HOG)
  335. message_bool_option("MVL support" PHYSFS_ARCHIVE_MVL)
  336. message_bool_option("QPAK support" PHYSFS_ARCHIVE_QPAK)
  337. message_bool_option("SLB support" PHYSFS_ARCHIVE_SLB)
  338. message_bool_option("VDF support" PHYSFS_ARCHIVE_VDF)
  339. message_bool_option("ISO9660 support" PHYSFS_ARCHIVE_ISO9660)
  340. message_bool_option("GOB/LAB/LFD support" PHYSFS_ARCHIVE_LECARCHIVES)
  341. message_bool_option("Build static library" PHYSFS_BUILD_STATIC)
  342. message_bool_option("Build shared library" PHYSFS_BUILD_SHARED)
  343. message_bool_option("Build stdio test program" PHYSFS_BUILD_TEST)
  344. message_bool_option("Build Doxygen documentation" PHYSFS_BUILD_DOCS)
  345. if(PHYSFS_BUILD_TEST)
  346. message_bool_option(" Use readline in test program" HAVE_SYSTEM_READLINE)
  347. endif()
  348. # end of CMakeLists.txt ...