CMakeLists.txt 9.4 KB

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