CMakeLists.txt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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)
  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_playdate.c
  71. src/physfs_archiver_dir.c
  72. src/physfs_archiver_unpacked.c
  73. src/physfs_archiver_grp.c
  74. src/physfs_archiver_hog.c
  75. src/physfs_archiver_7z.c
  76. src/physfs_archiver_mvl.c
  77. src/physfs_archiver_qpak.c
  78. src/physfs_archiver_wad.c
  79. src/physfs_archiver_csm.c
  80. src/physfs_archiver_zip.c
  81. src/physfs_archiver_slb.c
  82. src/physfs_archiver_iso9660.c
  83. src/physfs_archiver_vdf.c
  84. src/physfs_archiver_lec3d.c
  85. ${PHYSFS_CPP_SRCS}
  86. ${PHYSFS_M_SRCS}
  87. )
  88. # Archivers ...
  89. # These are (mostly) on by default now, so these options are only useful for
  90. # disabling them.
  91. option(PHYSFS_ARCHIVE_ZIP "Enable ZIP support" TRUE)
  92. if(NOT PHYSFS_ARCHIVE_ZIP)
  93. add_definitions(-DPHYSFS_SUPPORTS_ZIP=0)
  94. endif()
  95. option(PHYSFS_ARCHIVE_7Z "Enable 7zip support" TRUE)
  96. if(NOT PHYSFS_ARCHIVE_7Z)
  97. add_definitions(-DPHYSFS_SUPPORTS_7Z=0)
  98. endif()
  99. option(PHYSFS_ARCHIVE_GRP "Enable Build Engine GRP support" TRUE)
  100. if(NOT PHYSFS_ARCHIVE_GRP)
  101. add_definitions(-DPHYSFS_SUPPORTS_GRP=0)
  102. endif()
  103. option(PHYSFS_ARCHIVE_WAD "Enable Doom WAD support" TRUE)
  104. if(NOT PHYSFS_ARCHIVE_WAD)
  105. add_definitions(-DPHYSFS_SUPPORTS_WAD=0)
  106. endif()
  107. option(PHYSFS_ARCHIVE_CSM "Enable Chasm: The Rift CSM.BIN support" TRUE)
  108. if(NOT PHYSFS_ARCHIVE_CSM)
  109. add_definitions(-DPHYSFS_SUPPORTS_CSM=0)
  110. endif()
  111. option(PHYSFS_ARCHIVE_HOG "Enable Descent I/II HOG support" TRUE)
  112. if(NOT PHYSFS_ARCHIVE_HOG)
  113. add_definitions(-DPHYSFS_SUPPORTS_HOG=0)
  114. endif()
  115. option(PHYSFS_ARCHIVE_MVL "Enable Descent I/II MVL support" TRUE)
  116. if(NOT PHYSFS_ARCHIVE_MVL)
  117. add_definitions(-DPHYSFS_SUPPORTS_MVL=0)
  118. endif()
  119. option(PHYSFS_ARCHIVE_QPAK "Enable Quake I/II QPAK support" TRUE)
  120. if(NOT PHYSFS_ARCHIVE_QPAK)
  121. add_definitions(-DPHYSFS_SUPPORTS_QPAK=0)
  122. endif()
  123. option(PHYSFS_ARCHIVE_SLB "Enable I-War / Independence War SLB support" TRUE)
  124. if(NOT PHYSFS_ARCHIVE_SLB)
  125. add_definitions(-DPHYSFS_SUPPORTS_SLB=0)
  126. endif()
  127. option(PHYSFS_ARCHIVE_ISO9660 "Enable ISO9660 support" TRUE)
  128. if(NOT PHYSFS_ARCHIVE_ISO9660)
  129. add_definitions(-DPHYSFS_SUPPORTS_ISO9660=0)
  130. endif()
  131. option(PHYSFS_ARCHIVE_VDF "Enable Gothic I/II VDF archive support" TRUE)
  132. if(NOT PHYSFS_ARCHIVE_VDF)
  133. add_definitions(-DPHYSFS_SUPPORTS_VDF=0)
  134. endif()
  135. option(PHYSFS_ARCHIVE_LECARCHIVES "Enable LucasArts GOB/LAB/LFD Archive support" TRUE)
  136. if(NOT PHYSFS_ARCHIVE_LECARCHIVES)
  137. add_definitions(-DPHYSFS_SUPPORTS_LECARCHIVES=0)
  138. endif()
  139. option(PHYSFS_BUILD_STATIC "Build static library" TRUE)
  140. if(PHYSFS_BUILD_STATIC)
  141. add_library(physfs-static STATIC ${PHYSFS_SRCS})
  142. add_library(PhysFS::PhysFS-static ALIAS physfs-static)
  143. set_target_properties(physfs-static PROPERTIES EXPORT_NAME PhysFS-static)
  144. # Don't rename this on Windows, since DLLs will also produce an import
  145. # library named "physfs.lib" which would conflict; Unix tend to like the
  146. # same library name with a different extension for static libs, but
  147. # Windows can just have a separate name.
  148. if(NOT MSVC)
  149. set_target_properties(physfs-static PROPERTIES OUTPUT_NAME "physfs")
  150. endif()
  151. if(WINRT)
  152. # Ignore LNK4264 warnings; we don't author any WinRT components, just consume them, so we're okay in a static library.
  153. set_target_properties(physfs-static PROPERTIES VS_WINRT_COMPONENT True)
  154. set_target_properties(physfs-static PROPERTIES STATIC_LIBRARY_FLAGS "/ignore:4264")
  155. endif()
  156. if(WIN32 OR WINRT OR OS2)
  157. # no dll exports from the static library
  158. target_compile_definitions(physfs-static PRIVATE "PHYSFS_STATIC")
  159. endif()
  160. target_include_directories(physfs-static PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>")
  161. target_link_libraries(physfs-static PRIVATE ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS})
  162. set(PHYSFS_LIB_TARGET PhysFS::PhysFS-static)
  163. list(APPEND PHYSFS_INSTALL_TARGETS "physfs-static")
  164. endif()
  165. option(PHYSFS_BUILD_SHARED "Build shared library" TRUE)
  166. if(PHYSFS_BUILD_SHARED)
  167. add_library(physfs SHARED ${PHYSFS_SRCS})
  168. add_library(PhysFS::PhysFS ALIAS physfs)
  169. set_target_properties(physfs PROPERTIES MACOSX_RPATH 1)
  170. set_target_properties(physfs PROPERTIES VERSION ${PHYSFS_VERSION})
  171. set_target_properties(physfs PROPERTIES SOVERSION ${PHYSFS_SOVERSION})
  172. set_target_properties(physfs PROPERTIES EXPORT_NAME PhysFS)
  173. if(WINRT)
  174. set_target_properties(physfs PROPERTIES VS_WINRT_COMPONENT TRUE)
  175. endif()
  176. if(OS2) # OS/2 does not support a DLL name longer than 8 characters.
  177. set_target_properties(physfs PROPERTIES OUTPUT_NAME "physfs")
  178. endif()
  179. target_include_directories(physfs PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>")
  180. target_link_libraries(physfs PRIVATE ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS})
  181. set(PHYSFS_LIB_TARGET PhysFS::PhysFS)
  182. list(APPEND PHYSFS_INSTALL_TARGETS "physfs")
  183. endif()
  184. if(NOT PHYSFS_BUILD_SHARED AND NOT PHYSFS_BUILD_STATIC)
  185. message(FATAL "Both shared and static libraries are disabled!")
  186. endif()
  187. option(PHYSFS_BUILD_TEST "Build stdio test program." TRUE)
  188. mark_as_advanced(PHYSFS_BUILD_TEST)
  189. if(PHYSFS_BUILD_TEST)
  190. add_executable(test_physfs test/test_physfs.c)
  191. target_link_libraries(test_physfs PRIVATE ${PHYSFS_LIB_TARGET} ${OTHER_LDFLAGS})
  192. find_path(READLINE_H readline/readline.h)
  193. find_path(HISTORY_H readline/history.h)
  194. find_library(READLINE_LIBRARY readline)
  195. find_package(Curses)
  196. if(READLINE_H AND HISTORY_H AND READLINE_LIBRARY AND CURSES_FOUND)
  197. set(HAVE_SYSTEM_READLINE TRUE)
  198. target_link_libraries(test_physfs PRIVATE ${READLINE_LIBRARY} ${CURSES_LIBRARIES})
  199. target_include_directories(test_physfs SYSTEM PRIVATE ${READLINE_H} ${HISTORY_H})
  200. target_compile_definitions(test_physfs PRIVATE PHYSFS_HAVE_READLINE=1)
  201. endif()
  202. list(APPEND PHYSFS_INSTALL_TARGETS test_physfs)
  203. endif()
  204. option(PHYSFS_DISABLE_INSTALL "Disable installing PhysFS" OFF)
  205. if(NOT PHYSFS_DISABLE_INSTALL)
  206. install(TARGETS ${PHYSFS_INSTALL_TARGETS} EXPORT PhysFSExport
  207. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  208. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  209. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  210. INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
  211. install(FILES src/physfs.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
  212. install(EXPORT PhysFSExport
  213. DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/PhysFS"
  214. FILE PhysFSConfig.cmake
  215. NAMESPACE PhysFS::
  216. )
  217. if(NOT MSVC)
  218. configure_file(
  219. "extras/physfs.pc.in"
  220. "extras/physfs.pc"
  221. @ONLY
  222. )
  223. install(
  224. FILES "${CMAKE_CURRENT_BINARY_DIR}/extras/physfs.pc"
  225. DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
  226. )
  227. endif()
  228. endif()
  229. option(PHYSFS_BUILD_DOCS "Build doxygen based documentation" TRUE)
  230. if(PHYSFS_BUILD_DOCS)
  231. find_package(Doxygen)
  232. if(DOXYGEN_FOUND)
  233. set(PHYSFS_OUTPUT_DOXYFILE "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile")
  234. configure_file(
  235. "${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile"
  236. "${PHYSFS_OUTPUT_DOXYFILE}"
  237. COPYONLY
  238. )
  239. file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "\n\n# Below auto-generated by cmake...\n\n")
  240. file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "PROJECT_NUMBER = \"${PHYSFS_VERSION}\"\n")
  241. file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "OUTPUT_DIRECTORY = \"${CMAKE_CURRENT_BINARY_DIR}/docs\"\n")
  242. file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "\n# End auto-generated section.\n\n")
  243. set(PHYSFS_TARGETNAME_DOCS "docs" CACHE STRING "Name of 'docs' build target")
  244. add_custom_target(
  245. ${PHYSFS_TARGETNAME_DOCS}
  246. ${DOXYGEN_EXECUTABLE} "${PHYSFS_OUTPUT_DOXYFILE}"
  247. WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
  248. COMMENT "Building documentation in 'docs' directory..."
  249. )
  250. else()
  251. message(STATUS "Doxygen not found. You won't be able to build documentation.")
  252. endif()
  253. endif()
  254. if(UNIX)
  255. set(PHYSFS_TARBALL "${CMAKE_CURRENT_SOURCE_DIR}/../physfs-${PHYSFS_VERSION}.tar.gz")
  256. set(PHYSFS_TARGETNAME_DIST "dist" CACHE STRING "Name of 'dist' build target")
  257. add_custom_target(
  258. ${PHYSFS_TARGETNAME_DIST}
  259. git archive --prefix="physfs-${PHYSFS_VERSION}/" --output="${PHYSFS_TARBALL}" HEAD
  260. WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
  261. COMMENT "Building source tarball '${PHYSFS_TARBALL}'..."
  262. )
  263. set(PHYSFS_TARGETNAME_UNINSTALL "uninstall" CACHE STRING "Name of 'uninstall' build target")
  264. add_custom_target(
  265. ${PHYSFS_TARGETNAME_UNINSTALL}
  266. "${CMAKE_CURRENT_SOURCE_DIR}/extras/uninstall.sh"
  267. WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
  268. COMMENT "Uninstall the project..."
  269. )
  270. endif()
  271. macro(message_bool_option _NAME _VALUE)
  272. if(${_VALUE})
  273. message(STATUS " ${_NAME}: enabled")
  274. else()
  275. message(STATUS " ${_NAME}: disabled")
  276. endif()
  277. endmacro()
  278. message(STATUS "PhysicsFS will build with the following options:")
  279. message_bool_option("ZIP support" PHYSFS_ARCHIVE_ZIP)
  280. message_bool_option("7zip support" PHYSFS_ARCHIVE_7Z)
  281. message_bool_option("GRP support" PHYSFS_ARCHIVE_GRP)
  282. message_bool_option("WAD support" PHYSFS_ARCHIVE_WAD)
  283. message_bool_option("CSM support" PHYSFS_ARCHIVE_CSM)
  284. message_bool_option("HOG support" PHYSFS_ARCHIVE_HOG)
  285. message_bool_option("MVL support" PHYSFS_ARCHIVE_MVL)
  286. message_bool_option("QPAK support" PHYSFS_ARCHIVE_QPAK)
  287. message_bool_option("SLB support" PHYSFS_ARCHIVE_SLB)
  288. message_bool_option("VDF support" PHYSFS_ARCHIVE_VDF)
  289. message_bool_option("ISO9660 support" PHYSFS_ARCHIVE_ISO9660)
  290. message_bool_option("GOB/LAB/LFD support" PHYSFS_ARCHIVE_LECARCHIVES)
  291. message_bool_option("Build static library" PHYSFS_BUILD_STATIC)
  292. message_bool_option("Build shared library" PHYSFS_BUILD_SHARED)
  293. message_bool_option("Build stdio test program" PHYSFS_BUILD_TEST)
  294. message_bool_option("Build Doxygen documentation" PHYSFS_BUILD_DOCS)
  295. if(PHYSFS_BUILD_TEST)
  296. message_bool_option(" Use readline in test program" HAVE_SYSTEM_READLINE)
  297. endif()
  298. # end of CMakeLists.txt ...