CMakeLists.txt 12 KB

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