CMakeLists.txt 12 KB

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