1
0

CMakeLists.txt 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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.4)
  11. project(PhysicsFS)
  12. set(PHYSFS_VERSION 2.1.0)
  13. # Increment this if/when we break backwards compatibility.
  14. set(PHYSFS_SOVERSION 1)
  15. # I hate that they define "WIN32" ... we're about to move to Win64...I hope!
  16. if(WIN32 AND NOT WINDOWS)
  17. set(WINDOWS TRUE)
  18. endif()
  19. include_directories(./src)
  20. if(APPLE)
  21. set(OTHER_LDFLAGS ${OTHER_LDFLAGS} "-framework CoreFoundation -framework IOKit")
  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. # Basic chunks of source code ...
  32. set(LZMA_SRCS
  33. src/lzma/C/7zCrc.c
  34. src/lzma/C/Archive/7z/7zBuffer.c
  35. src/lzma/C/Archive/7z/7zDecode.c
  36. src/lzma/C/Archive/7z/7zExtract.c
  37. src/lzma/C/Archive/7z/7zHeader.c
  38. src/lzma/C/Archive/7z/7zIn.c
  39. src/lzma/C/Archive/7z/7zItem.c
  40. src/lzma/C/Archive/7z/7zMethodID.c
  41. src/lzma/C/Compress/Branch/BranchX86.c
  42. src/lzma/C/Compress/Branch/BranchX86_2.c
  43. src/lzma/C/Compress/Lzma/LzmaDecode.c
  44. )
  45. if(HAIKU)
  46. # We add this explicitly, since we don't want CMake to think this
  47. # is a C++ project unless we're on Haiku.
  48. set(PHYSFS_HAIKU_SRCS src/platform_beos.cpp)
  49. find_library(BE_LIBRARY be)
  50. find_library(ROOT_LIBRARY root)
  51. set(OPTIONAL_LIBRARY_LIBS ${OPTIONAL_LIBRARY_LIBS} ${BE_LIBRARY} ${ROOT_LIBRARY})
  52. endif()
  53. if(UNIX AND NOT WINDOWS AND NOT APPLE) # (MingW and such might be UNIX _and_ WINDOWS!)
  54. find_library(PTHREAD_LIBRARY pthread)
  55. if(PTHREAD_LIBRARY)
  56. set(OPTIONAL_LIBRARY_LIBS ${OPTIONAL_LIBRARY_LIBS} ${PTHREAD_LIBRARY})
  57. endif()
  58. endif()
  59. # Almost everything is "compiled" here, but things that don't apply to the
  60. # build are #ifdef'd out. This is to make it easy to embed PhysicsFS into
  61. # another project or bring up a new build system: just compile all the source
  62. # code and #define the things you want.
  63. set(PHYSFS_SRCS
  64. src/physfs.c
  65. src/physfs_byteorder.c
  66. src/physfs_unicode.c
  67. src/platform_posix.c
  68. src/platform_unix.c
  69. src/platform_macosx.c
  70. src/platform_windows.c
  71. src/archiver_dir.c
  72. src/archiver_unpacked.c
  73. src/archiver_grp.c
  74. src/archiver_hog.c
  75. src/archiver_lzma.c
  76. src/archiver_mvl.c
  77. src/archiver_qpak.c
  78. src/archiver_wad.c
  79. src/archiver_zip.c
  80. src/archiver_slb.c
  81. src/archiver_iso9660.c
  82. src/archiver_vdf.c
  83. ${PHYSFS_HAIKU_SRCS}
  84. )
  85. # Archivers ...
  86. # These are (mostly) on by default now, so these options are only useful for
  87. # disabling them.
  88. option(PHYSFS_ARCHIVE_ZIP "Enable ZIP support" TRUE)
  89. if(NOT PHYSFS_ARCHIVE_ZIP)
  90. add_definitions(-DPHYSFS_SUPPORTS_ZIP=0)
  91. endif()
  92. option(PHYSFS_ARCHIVE_7Z "Enable 7zip support" TRUE)
  93. if(PHYSFS_ARCHIVE_7Z) # !!! FIXME: this is DISABLED by default in the source because it needs LZMA SDK; clean that up and enable this by default.
  94. add_definitions(-DPHYSFS_SUPPORTS_7Z=0)
  95. # !!! FIXME: rename to 7z.c?
  96. set(PHYSFS_SRCS ${PHYSFS_SRCS} ${LZMA_SRCS})
  97. endif()
  98. option(PHYSFS_ARCHIVE_GRP "Enable Build Engine GRP support" TRUE)
  99. if(NOT PHYSFS_ARCHIVE_GRP)
  100. add_definitions(-DPHYSFS_SUPPORTS_GRP=0)
  101. endif()
  102. option(PHYSFS_ARCHIVE_WAD "Enable Doom WAD support" TRUE)
  103. if(NOT PHYSFS_ARCHIVE_WAD)
  104. add_definitions(-DPHYSFS_SUPPORTS_WAD=0)
  105. endif()
  106. option(PHYSFS_ARCHIVE_HOG "Enable Descent I/II HOG support" TRUE)
  107. if(NOT PHYSFS_ARCHIVE_HOG)
  108. add_definitions(-DPHYSFS_SUPPORTS_HOG=0)
  109. endif()
  110. option(PHYSFS_ARCHIVE_MVL "Enable Descent I/II MVL support" TRUE)
  111. if(NOT PHYSFS_ARCHIVE_MVL)
  112. add_definitions(-DPHYSFS_SUPPORTS_MVL=0)
  113. endif()
  114. option(PHYSFS_ARCHIVE_QPAK "Enable Quake I/II QPAK support" TRUE)
  115. if(NOT PHYSFS_ARCHIVE_QPAK)
  116. add_definitions(-DPHYSFS_SUPPORTS_QPAK=0)
  117. endif()
  118. option(PHYSFS_ARCHIVE_SLB "Enable I-War / Independence War SLB support" TRUE)
  119. if(NOT PHYSFS_ARCHIVE_SLB)
  120. add_definitions(-DPHYSFS_SUPPORTS_SLB=0)
  121. endif()
  122. option(PHYSFS_ARCHIVE_ISO9660 "Enable ISO9660 support" TRUE)
  123. if(NOT PHYSFS_ARCHIVE_ISO9660)
  124. add_definitions(-DPHYSFS_SUPPORTS_ISO9660=0)
  125. endif()
  126. option(PHYSFS_ARCHIVE_VDF "Enable Gothic I/II VDF archive support" TRUE)
  127. if(NOT PHYSFS_ARCHIVE_VDF)
  128. add_definitions(-DPHYSFS_SUPPORTS_VDF=0)
  129. endif()
  130. option(PHYSFS_BUILD_STATIC "Build static library" TRUE)
  131. if(PHYSFS_BUILD_STATIC)
  132. add_library(physfs-static STATIC ${PHYSFS_SRCS})
  133. # Don't rename this on Windows, since DLLs will also produce an import
  134. # library named "physfs.lib" which would conflict; Unix tend to like the
  135. # same library name with a different extension for static libs, but
  136. # Windows can just have a separate name.
  137. if(NOT WINDOWS)
  138. set_target_properties(physfs-static PROPERTIES OUTPUT_NAME "physfs")
  139. endif()
  140. set(PHYSFS_LIB_TARGET physfs-static)
  141. set(PHYSFS_INSTALL_TARGETS ${PHYSFS_INSTALL_TARGETS} ";physfs-static")
  142. endif()
  143. option(PHYSFS_BUILD_SHARED "Build shared library" TRUE)
  144. if(PHYSFS_BUILD_SHARED)
  145. add_library(physfs SHARED ${PHYSFS_SRCS})
  146. set_target_properties(physfs PROPERTIES VERSION ${PHYSFS_VERSION})
  147. set_target_properties(physfs PROPERTIES SOVERSION ${PHYSFS_SOVERSION})
  148. target_link_libraries(physfs ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS})
  149. set(PHYSFS_LIB_TARGET physfs)
  150. set(PHYSFS_INSTALL_TARGETS ${PHYSFS_INSTALL_TARGETS} ";physfs")
  151. endif()
  152. if(NOT PHYSFS_BUILD_SHARED AND NOT PHYSFS_BUILD_STATIC)
  153. message(FATAL "Both shared and static libraries are disabled!")
  154. endif()
  155. # CMake FAQ says I need this...
  156. if(PHYSFS_BUILD_SHARED AND PHYSFS_BUILD_STATIC AND NOT WINDOWS)
  157. set_target_properties(physfs PROPERTIES CLEAN_DIRECT_OUTPUT 1)
  158. set_target_properties(physfs-static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
  159. endif()
  160. option(PHYSFS_BUILD_TEST "Build stdio test program." TRUE)
  161. mark_as_advanced(PHYSFS_BUILD_TEST)
  162. if(PHYSFS_BUILD_TEST)
  163. find_path(READLINE_H readline/readline.h)
  164. find_path(HISTORY_H readline/history.h)
  165. if(READLINE_H AND HISTORY_H)
  166. find_library(CURSES_LIBRARY NAMES curses ncurses)
  167. set(CMAKE_REQUIRED_LIBRARIES ${CURSES_LIBRARY})
  168. find_library(READLINE_LIBRARY readline)
  169. if(READLINE_LIBRARY)
  170. set(HAVE_SYSTEM_READLINE TRUE)
  171. set(TEST_PHYSFS_LIBS ${TEST_PHYSFS_LIBS} ${READLINE_LIBRARY} ${CURSES_LIBRARY})
  172. include_directories(${READLINE_H} ${HISTORY_H})
  173. add_definitions(-DPHYSFS_HAVE_READLINE=1)
  174. endif()
  175. endif()
  176. add_executable(test_physfs test/test_physfs.c)
  177. target_link_libraries(test_physfs ${PHYSFS_LIB_TARGET} ${TEST_PHYSFS_LIBS} ${OTHER_LDFLAGS})
  178. set(PHYSFS_INSTALL_TARGETS ${PHYSFS_INSTALL_TARGETS} ";test_physfs")
  179. endif()
  180. install(TARGETS ${PHYSFS_INSTALL_TARGETS}
  181. RUNTIME DESTINATION bin
  182. LIBRARY DESTINATION lib${LIB_SUFFIX}
  183. ARCHIVE DESTINATION lib${LIB_SUFFIX})
  184. install(FILES src/physfs.h DESTINATION include)
  185. find_package(Doxygen)
  186. if(DOXYGEN_FOUND)
  187. set(PHYSFS_OUTPUT_DOXYFILE "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile")
  188. configure_file(
  189. "${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile"
  190. "${PHYSFS_OUTPUT_DOXYFILE}"
  191. COPYONLY
  192. )
  193. file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "\n\n# Below auto-generated by cmake...\n\n")
  194. file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "PROJECT_NUMBER = \"${PHYSFS_VERSION}\"\n")
  195. file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "OUTPUT_DIRECTORY = \"${CMAKE_CURRENT_BINARY_DIR}/docs\"\n")
  196. file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "\n# End auto-generated section.\n\n")
  197. add_custom_target(
  198. docs
  199. ${DOXYGEN_EXECUTABLE} "${PHYSFS_OUTPUT_DOXYFILE}"
  200. WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
  201. COMMENT "Building documentation in 'docs' directory..."
  202. )
  203. else()
  204. message(STATUS "Doxygen not found. You won't be able to build documentation.")
  205. endif()
  206. if(UNIX)
  207. set(PHYSFS_TARBALL "${CMAKE_CURRENT_SOURCE_DIR}/../physfs-${PHYSFS_VERSION}.tar.bz2")
  208. add_custom_target(
  209. dist
  210. hg archive -t tbz2 "${PHYSFS_TARBALL}"
  211. WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
  212. COMMENT "Building source tarball '${PHYSFS_TARBALL}'..."
  213. )
  214. add_custom_target(
  215. uninstall
  216. "${CMAKE_CURRENT_SOURCE_DIR}/extras/uninstall.sh"
  217. WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
  218. COMMENT "Uninstall the project..."
  219. )
  220. endif()
  221. if(UNIX AND NOT APPLE)
  222. configure_file(
  223. "extras/physfs.pc.in"
  224. "extras/physfs.pc"
  225. @ONLY
  226. )
  227. install(
  228. FILES "${CMAKE_CURRENT_BINARY_DIR}/extras/physfs.pc"
  229. DESTINATION "lib/pkgconfig"
  230. )
  231. endif()
  232. macro(message_bool_option _NAME _VALUE)
  233. if(${_VALUE})
  234. message(STATUS " ${_NAME}: enabled")
  235. else()
  236. message(STATUS " ${_NAME}: disabled")
  237. endif()
  238. endmacro()
  239. message(STATUS "PhysicsFS will build with the following options:")
  240. message_bool_option("ZIP support" PHYSFS_ARCHIVE_ZIP)
  241. message_bool_option("7zip support" PHYSFS_ARCHIVE_7Z)
  242. message_bool_option("GRP support" PHYSFS_ARCHIVE_GRP)
  243. message_bool_option("WAD support" PHYSFS_ARCHIVE_WAD)
  244. message_bool_option("HOG support" PHYSFS_ARCHIVE_HOG)
  245. message_bool_option("MVL support" PHYSFS_ARCHIVE_MVL)
  246. message_bool_option("QPAK support" PHYSFS_ARCHIVE_QPAK)
  247. message_bool_option("SLB support" PHYSFS_ARCHIVE_SLB)
  248. message_bool_option("VDF support" PHYSFS_ARCHIVE_VDF)
  249. message_bool_option("ISO9660 support" PHYSFS_ARCHIVE_ISO9660)
  250. message_bool_option("Build static library" PHYSFS_BUILD_STATIC)
  251. message_bool_option("Build shared library" PHYSFS_BUILD_SHARED)
  252. message_bool_option("Build stdio test program" PHYSFS_BUILD_TEST)
  253. if(PHYSFS_BUILD_TEST)
  254. message_bool_option(" Use readline in test program" HAVE_SYSTEM_READLINE)
  255. endif()
  256. # end of CMakeLists.txt ...