CMakeLists.txt 9.5 KB

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