CMakeLists.txt 13 KB

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