CMakeLists.txt 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. # PhysicsFS; a portable, flexible file i/o abstraction.
  2. #
  3. # Please see the file LICENSE.txt in the source's root directory.
  4. cmake_minimum_required(VERSION 2.8.4)
  5. project(PhysicsFS)
  6. set(PHYSFS_VERSION 2.1.0)
  7. # Increment this if/when we break backwards compatibility.
  8. set(PHYSFS_SOVERSION 1)
  9. # I hate that they define "WIN32" ... we're about to move to Win64...I hope!
  10. if(WIN32 AND NOT WINDOWS)
  11. set(WINDOWS TRUE)
  12. endif()
  13. # Bleh, let's do it for "APPLE" too.
  14. if(APPLE AND NOT MACOSX)
  15. set(MACOSX TRUE)
  16. endif()
  17. # For now, Haiku and BeOS are the same, as far as the build system cares.
  18. if(HAIKU AND NOT BEOS)
  19. set(BEOS TRUE)
  20. endif()
  21. if(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
  22. set(SOLARIS TRUE)
  23. endif()
  24. include(CheckIncludeFile)
  25. include(CheckLibraryExists)
  26. include(CheckCSourceCompiles)
  27. include_directories(./src)
  28. if(MACOSX)
  29. # Fallback to older OS X on PowerPC to support wider range of systems...
  30. if(CMAKE_OSX_ARCHITECTURES MATCHES ppc)
  31. add_definitions(-DMAC_OS_X_VERSION_MIN_REQUIRED=1020)
  32. set(OTHER_LDFLAGS ${OTHER_LDFLAGS} " -mmacosx-version-min=10.2")
  33. endif()
  34. # Need these everywhere...
  35. add_definitions(-fno-common)
  36. set(OTHER_LDFLAGS ${OTHER_LDFLAGS} "-framework Carbon -framework IOKit")
  37. endif()
  38. # Add some gcc-specific command lines.
  39. if(CMAKE_COMPILER_IS_GNUCC)
  40. # Always build with debug symbols...you can strip it later.
  41. add_definitions(-g -pipe -Werror -fsigned-char)
  42. # Stupid BeOS generates warnings in the system headers.
  43. if(NOT BEOS)
  44. add_definitions(-Wall)
  45. endif()
  46. check_c_source_compiles("
  47. #if ((defined(__GNUC__)) && (__GNUC__ >= 4))
  48. int main(int argc, char **argv) { int is_gcc4 = 1; return 0; }
  49. #else
  50. #error This is not gcc4.
  51. #endif
  52. " PHYSFS_IS_GCC4)
  53. if(PHYSFS_IS_GCC4)
  54. # Not supported on several operating systems at this time.
  55. if(NOT SOLARIS AND NOT WINDOWS)
  56. add_definitions(-fvisibility=hidden)
  57. endif()
  58. endif()
  59. # Don't use -rpath.
  60. set(CMAKE_SKIP_RPATH ON CACHE BOOL "Skip RPATH" FORCE)
  61. endif()
  62. if(CMAKE_C_COMPILER_ID STREQUAL "SunPro")
  63. add_definitions(-erroff=E_EMPTY_TRANSLATION_UNIT)
  64. add_definitions(-xldscope=hidden)
  65. endif()
  66. if(MSVC)
  67. # VS.NET 8.0 got really really anal about strcpy, etc, which even if we
  68. # cleaned up our code, zlib, etc still use...so disable the warning.
  69. add_definitions(-D_CRT_SECURE_NO_WARNINGS=1)
  70. endif()
  71. # Basic chunks of source code ...
  72. set(LZMA_SRCS
  73. src/lzma/C/7zCrc.c
  74. src/lzma/C/Archive/7z/7zBuffer.c
  75. src/lzma/C/Archive/7z/7zDecode.c
  76. src/lzma/C/Archive/7z/7zExtract.c
  77. src/lzma/C/Archive/7z/7zHeader.c
  78. src/lzma/C/Archive/7z/7zIn.c
  79. src/lzma/C/Archive/7z/7zItem.c
  80. src/lzma/C/Archive/7z/7zMethodID.c
  81. src/lzma/C/Compress/Branch/BranchX86.c
  82. src/lzma/C/Compress/Branch/BranchX86_2.c
  83. src/lzma/C/Compress/Lzma/LzmaDecode.c
  84. )
  85. if(BEOS)
  86. # We add this explicitly, since we don't want CMake to think this
  87. # is a C++ project unless we're on BeOS.
  88. set(PHYSFS_BEOS_SRCS src/platform_beos.cpp)
  89. find_library(BE_LIBRARY be)
  90. find_library(ROOT_LIBRARY root)
  91. set(OPTIONAL_LIBRARY_LIBS ${OPTIONAL_LIBRARY_LIBS} ${BE_LIBRARY} ${ROOT_LIBRARY})
  92. endif()
  93. # Almost everything is "compiled" here, but things that don't apply to the
  94. # build are #ifdef'd out. This is to make it easy to embed PhysicsFS into
  95. # another project or bring up a new build system: just compile all the source
  96. # code and #define the things you want.
  97. set(PHYSFS_SRCS
  98. src/physfs.c
  99. src/physfs_byteorder.c
  100. src/physfs_unicode.c
  101. src/platform_posix.c
  102. src/platform_unix.c
  103. src/platform_macosx.c
  104. src/platform_windows.c
  105. src/archiver_dir.c
  106. src/archiver_unpacked.c
  107. src/archiver_grp.c
  108. src/archiver_hog.c
  109. src/archiver_lzma.c
  110. src/archiver_mvl.c
  111. src/archiver_qpak.c
  112. src/archiver_wad.c
  113. src/archiver_zip.c
  114. src/archiver_slb.c
  115. src/archiver_iso9660.c
  116. src/archiver_vdf.c
  117. ${PHYSFS_BEOS_SRCS}
  118. )
  119. # platform layers ...
  120. if(UNIX)
  121. if(BEOS)
  122. set(PHYSFS_HAVE_CDROM_SUPPORT TRUE)
  123. set(PHYSFS_HAVE_THREAD_SUPPORT TRUE)
  124. set(HAVE_PTHREAD_H TRUE)
  125. else()
  126. check_include_file(sys/ucred.h HAVE_UCRED_H)
  127. if(HAVE_UCRED_H)
  128. add_definitions(-DPHYSFS_HAVE_SYS_UCRED_H=1)
  129. set(PHYSFS_HAVE_CDROM_SUPPORT TRUE)
  130. endif()
  131. check_include_file(mntent.h HAVE_MNTENT_H)
  132. if(HAVE_MNTENT_H)
  133. add_definitions(-DPHYSFS_HAVE_MNTENT_H=1)
  134. set(PHYSFS_HAVE_CDROM_SUPPORT TRUE)
  135. endif()
  136. # !!! FIXME: Solaris fails this, because mnttab.h implicitly
  137. # !!! FIXME: depends on other system headers. :(
  138. #check_include_file(sys/mnttab.h HAVE_SYS_MNTTAB_H)
  139. check_c_source_compiles("
  140. #include <stdio.h>
  141. #include <sys/mnttab.h>
  142. int main(int argc, char **argv) { return 0; }
  143. " HAVE_SYS_MNTTAB_H)
  144. if(HAVE_SYS_MNTTAB_H)
  145. add_definitions(-DPHYSFS_HAVE_SYS_MNTTAB_H=1)
  146. set(PHYSFS_HAVE_CDROM_SUPPORT TRUE)
  147. endif()
  148. check_include_file(pthread.h HAVE_PTHREAD_H)
  149. if(HAVE_PTHREAD_H)
  150. set(PHYSFS_HAVE_THREAD_SUPPORT TRUE)
  151. find_library(PTHREAD_LIBRARY pthread)
  152. if(PTHREAD_LIBRARY)
  153. set(OPTIONAL_LIBRARY_LIBS ${OPTIONAL_LIBRARY_LIBS} ${PTHREAD_LIBRARY})
  154. endif()
  155. endif()
  156. endif()
  157. endif()
  158. if(WINDOWS OR OS2)
  159. set(PHYSFS_HAVE_CDROM_SUPPORT TRUE)
  160. set(PHYSFS_HAVE_THREAD_SUPPORT TRUE)
  161. endif()
  162. if(NOT PHYSFS_HAVE_CDROM_SUPPORT)
  163. add_definitions(-DPHYSFS_NO_CDROM_SUPPORT=1)
  164. message(WARNING " ***")
  165. message(WARNING " *** There is no CD-ROM support in this build!")
  166. message(WARNING " *** PhysicsFS will just pretend there are no discs.")
  167. message(WARNING " *** This may be fine, depending on how PhysicsFS is used,")
  168. message(WARNING " *** but is this what you REALLY wanted?")
  169. message(WARNING " *** (Maybe fix CMakeLists.txt, or write a platform driver?)")
  170. message(WARNING " ***")
  171. endif()
  172. if(PHYSFS_HAVE_THREAD_SUPPORT)
  173. add_definitions(-D_REENTRANT -D_THREAD_SAFE)
  174. else()
  175. add_definitions(-DPHYSFS_NO_THREAD_SUPPORT=1)
  176. message(WARNING " ***")
  177. message(WARNING " *** There is no thread support in this build!")
  178. message(WARNING " *** PhysicsFS will NOT be reentrant!")
  179. message(WARNING " *** This may be fine, depending on how PhysicsFS is used,")
  180. message(WARNING " *** but is this what you REALLY wanted?")
  181. message(WARNING " *** (Maybe fix CMakeLists.txt, or write a platform driver?)")
  182. message(WARNING " ***")
  183. endif()
  184. # Archivers ...
  185. option(PHYSFS_ARCHIVE_ZIP "Enable ZIP support" TRUE)
  186. if(PHYSFS_ARCHIVE_ZIP)
  187. add_definitions(-DPHYSFS_SUPPORTS_ZIP=1)
  188. endif()
  189. option(PHYSFS_ARCHIVE_7Z "Enable 7zip support" TRUE)
  190. if(PHYSFS_ARCHIVE_7Z)
  191. add_definitions(-DPHYSFS_SUPPORTS_7Z=1)
  192. # !!! FIXME: rename to 7z.c?
  193. set(PHYSFS_SRCS ${PHYSFS_SRCS} ${LZMA_SRCS})
  194. endif()
  195. option(PHYSFS_ARCHIVE_GRP "Enable Build Engine GRP support" TRUE)
  196. if(PHYSFS_ARCHIVE_GRP)
  197. add_definitions(-DPHYSFS_SUPPORTS_GRP=1)
  198. endif()
  199. option(PHYSFS_ARCHIVE_WAD "Enable Doom WAD support" TRUE)
  200. if(PHYSFS_ARCHIVE_WAD)
  201. add_definitions(-DPHYSFS_SUPPORTS_WAD=1)
  202. endif()
  203. option(PHYSFS_ARCHIVE_HOG "Enable Descent I/II HOG support" TRUE)
  204. if(PHYSFS_ARCHIVE_HOG)
  205. add_definitions(-DPHYSFS_SUPPORTS_HOG=1)
  206. endif()
  207. option(PHYSFS_ARCHIVE_MVL "Enable Descent I/II MVL support" TRUE)
  208. if(PHYSFS_ARCHIVE_MVL)
  209. add_definitions(-DPHYSFS_SUPPORTS_MVL=1)
  210. endif()
  211. option(PHYSFS_ARCHIVE_QPAK "Enable Quake I/II QPAK support" TRUE)
  212. if(PHYSFS_ARCHIVE_QPAK)
  213. add_definitions(-DPHYSFS_SUPPORTS_QPAK=1)
  214. endif()
  215. option(PHYSFS_ARCHIVE_SLB "Enable I-War / Independence War SLB support" TRUE)
  216. if(PHYSFS_ARCHIVE_SLB)
  217. add_definitions(-DPHYSFS_SUPPORTS_SLB=1)
  218. endif()
  219. option(PHYSFS_ARCHIVE_ISO9660 "Enable ISO9660 support" TRUE)
  220. if(PHYSFS_ARCHIVE_ISO9660)
  221. add_definitions(-DPHYSFS_SUPPORTS_ISO9660=1)
  222. endif()
  223. option(PHYSFS_ARCHIVE_VDF "Enable Gothic I/II VDF archive support" TRUE)
  224. if(PHYSFS_ARCHIVE_VDF)
  225. add_definitions(-DPHYSFS_SUPPORTS_VDF=1)
  226. endif()
  227. option(PHYSFS_BUILD_STATIC "Build static library" TRUE)
  228. if(PHYSFS_BUILD_STATIC)
  229. add_library(physfs-static STATIC ${PHYSFS_SRCS})
  230. set_target_properties(physfs-static PROPERTIES OUTPUT_NAME "physfs")
  231. set(PHYSFS_LIB_TARGET physfs-static)
  232. set(PHYSFS_INSTALL_TARGETS ${PHYSFS_INSTALL_TARGETS} ";physfs-static")
  233. endif()
  234. option(PHYSFS_BUILD_SHARED "Build shared library" TRUE)
  235. if(PHYSFS_BUILD_SHARED)
  236. add_library(physfs SHARED ${PHYSFS_SRCS})
  237. set_target_properties(physfs PROPERTIES VERSION ${PHYSFS_VERSION})
  238. set_target_properties(physfs PROPERTIES SOVERSION ${PHYSFS_SOVERSION})
  239. target_link_libraries(physfs ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS})
  240. set(PHYSFS_LIB_TARGET physfs)
  241. set(PHYSFS_INSTALL_TARGETS ${PHYSFS_INSTALL_TARGETS} ";physfs")
  242. endif()
  243. if(NOT PHYSFS_BUILD_SHARED AND NOT PHYSFS_BUILD_STATIC)
  244. message(FATAL "Both shared and static libraries are disabled!")
  245. endif()
  246. # CMake FAQ says I need this...
  247. if(PHYSFS_BUILD_SHARED AND PHYSFS_BUILD_STATIC)
  248. set_target_properties(physfs PROPERTIES CLEAN_DIRECT_OUTPUT 1)
  249. set_target_properties(physfs-static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
  250. endif()
  251. option(PHYSFS_BUILD_TEST "Build stdio test program." TRUE)
  252. mark_as_advanced(PHYSFS_BUILD_TEST)
  253. if(PHYSFS_BUILD_TEST)
  254. find_path(READLINE_H readline/readline.h)
  255. find_path(HISTORY_H readline/history.h)
  256. if(READLINE_H AND HISTORY_H)
  257. find_library(CURSES_LIBRARY NAMES curses ncurses)
  258. set(CMAKE_REQUIRED_LIBRARIES ${CURSES_LIBRARY})
  259. find_library(READLINE_LIBRARY readline)
  260. if(READLINE_LIBRARY)
  261. set(HAVE_SYSTEM_READLINE TRUE)
  262. set(TEST_PHYSFS_LIBS ${TEST_PHYSFS_LIBS} ${READLINE_LIBRARY} ${CURSES_LIBRARY})
  263. include_directories(${READLINE_H} ${HISTORY_H})
  264. add_definitions(-DPHYSFS_HAVE_READLINE=1)
  265. endif()
  266. endif()
  267. add_executable(test_physfs test/test_physfs.c)
  268. target_link_libraries(test_physfs ${PHYSFS_LIB_TARGET} ${TEST_PHYSFS_LIBS} ${OTHER_LDFLAGS})
  269. set(PHYSFS_INSTALL_TARGETS ${PHYSFS_INSTALL_TARGETS} ";test_physfs")
  270. endif()
  271. install(TARGETS ${PHYSFS_INSTALL_TARGETS}
  272. RUNTIME DESTINATION bin
  273. LIBRARY DESTINATION lib${LIB_SUFFIX}
  274. ARCHIVE DESTINATION lib${LIB_SUFFIX})
  275. install(FILES src/physfs.h DESTINATION include)
  276. find_package(Doxygen)
  277. if(DOXYGEN_FOUND)
  278. set(PHYSFS_OUTPUT_DOXYFILE "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile")
  279. configure_file(
  280. "${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile"
  281. "${PHYSFS_OUTPUT_DOXYFILE}"
  282. COPYONLY
  283. )
  284. file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "\n\n# Below auto-generated by cmake...\n\n")
  285. file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "PROJECT_NUMBER = \"${PHYSFS_VERSION}\"\n")
  286. file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "OUTPUT_DIRECTORY = \"${CMAKE_CURRENT_BINARY_DIR}/docs\"\n")
  287. file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "\n# End auto-generated section.\n\n")
  288. add_custom_target(
  289. docs
  290. ${DOXYGEN_EXECUTABLE} "${PHYSFS_OUTPUT_DOXYFILE}"
  291. WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
  292. COMMENT "Building documentation in 'docs' directory..."
  293. )
  294. else()
  295. message(STATUS "Doxygen not found. You won't be able to build documentation.")
  296. endif()
  297. if(UNIX)
  298. set(PHYSFS_TARBALL "${CMAKE_CURRENT_SOURCE_DIR}/../physfs-${PHYSFS_VERSION}.tar.bz2")
  299. add_custom_target(
  300. dist
  301. hg archive -t tbz2 "${PHYSFS_TARBALL}"
  302. WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
  303. COMMENT "Building source tarball '${PHYSFS_TARBALL}'..."
  304. )
  305. add_custom_target(
  306. uninstall
  307. "${CMAKE_CURRENT_SOURCE_DIR}/extras/uninstall.sh"
  308. WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
  309. COMMENT "Uninstall the project..."
  310. )
  311. endif()
  312. if(UNIX AND NOT APPLE)
  313. configure_file(
  314. "extras/physfs.pc.in"
  315. "extras/physfs.pc"
  316. @ONLY
  317. )
  318. install(
  319. FILES "${CMAKE_CURRENT_BINARY_DIR}/extras/physfs.pc"
  320. DESTINATION "lib/pkgconfig"
  321. )
  322. endif()
  323. macro(message_bool_option _NAME _VALUE)
  324. if(${_VALUE})
  325. message(STATUS " ${_NAME}: enabled")
  326. else()
  327. message(STATUS " ${_NAME}: disabled")
  328. endif()
  329. endmacro()
  330. message(STATUS "PhysicsFS will build with the following options:")
  331. message_bool_option("ZIP support" PHYSFS_ARCHIVE_ZIP)
  332. message_bool_option("7zip support" PHYSFS_ARCHIVE_7Z)
  333. message_bool_option("GRP support" PHYSFS_ARCHIVE_GRP)
  334. message_bool_option("WAD support" PHYSFS_ARCHIVE_WAD)
  335. message_bool_option("HOG support" PHYSFS_ARCHIVE_HOG)
  336. message_bool_option("MVL support" PHYSFS_ARCHIVE_MVL)
  337. message_bool_option("QPAK support" PHYSFS_ARCHIVE_QPAK)
  338. message_bool_option("SLB support" PHYSFS_ARCHIVE_SLB)
  339. message_bool_option("CD-ROM drive support" PHYSFS_HAVE_CDROM_SUPPORT)
  340. message_bool_option("Thread safety" PHYSFS_HAVE_THREAD_SUPPORT)
  341. message_bool_option("Build static library" PHYSFS_BUILD_STATIC)
  342. message_bool_option("Build shared library" PHYSFS_BUILD_SHARED)
  343. message_bool_option("Build stdio test program" PHYSFS_BUILD_TEST)
  344. if(PHYSFS_BUILD_TEST)
  345. message_bool_option(" Use readline in test program" HAVE_SYSTEM_READLINE)
  346. endif()
  347. # end of CMakeLists.txt ...