CMakeLists.txt 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  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 -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. ${PHYSFS_BEOS_SRCS}
  117. )
  118. # platform layers ...
  119. if(UNIX)
  120. if(BEOS)
  121. set(PHYSFS_HAVE_CDROM_SUPPORT TRUE)
  122. set(PHYSFS_HAVE_THREAD_SUPPORT TRUE)
  123. set(HAVE_PTHREAD_H TRUE)
  124. else()
  125. check_include_file(sys/ucred.h HAVE_UCRED_H)
  126. if(HAVE_UCRED_H)
  127. add_definitions(-DPHYSFS_HAVE_SYS_UCRED_H=1)
  128. set(PHYSFS_HAVE_CDROM_SUPPORT TRUE)
  129. endif()
  130. check_include_file(mntent.h HAVE_MNTENT_H)
  131. if(HAVE_MNTENT_H)
  132. add_definitions(-DPHYSFS_HAVE_MNTENT_H=1)
  133. set(PHYSFS_HAVE_CDROM_SUPPORT TRUE)
  134. endif()
  135. # !!! FIXME: Solaris fails this, because mnttab.h implicitly
  136. # !!! FIXME: depends on other system headers. :(
  137. #check_include_file(sys/mnttab.h HAVE_SYS_MNTTAB_H)
  138. check_c_source_compiles("
  139. #include <stdio.h>
  140. #include <sys/mnttab.h>
  141. int main(int argc, char **argv) { return 0; }
  142. " HAVE_SYS_MNTTAB_H)
  143. if(HAVE_SYS_MNTTAB_H)
  144. add_definitions(-DPHYSFS_HAVE_SYS_MNTTAB_H=1)
  145. set(PHYSFS_HAVE_CDROM_SUPPORT TRUE)
  146. endif()
  147. check_include_file(pthread.h HAVE_PTHREAD_H)
  148. if(HAVE_PTHREAD_H)
  149. set(PHYSFS_HAVE_THREAD_SUPPORT TRUE)
  150. find_library(PTHREAD_LIBRARY pthread)
  151. if(PTHREAD_LIBRARY)
  152. set(OPTIONAL_LIBRARY_LIBS ${OPTIONAL_LIBRARY_LIBS} ${PTHREAD_LIBRARY})
  153. endif()
  154. endif()
  155. endif()
  156. endif()
  157. if(WINDOWS)
  158. set(PHYSFS_HAVE_CDROM_SUPPORT TRUE)
  159. set(PHYSFS_HAVE_THREAD_SUPPORT TRUE)
  160. endif()
  161. if(NOT PHYSFS_HAVE_CDROM_SUPPORT)
  162. add_definitions(-DPHYSFS_NO_CDROM_SUPPORT=1)
  163. message(WARNING " ***")
  164. message(WARNING " *** There is no CD-ROM support in this build!")
  165. message(WARNING " *** PhysicsFS will just pretend there are no discs.")
  166. message(WARNING " *** This may be fine, depending on how PhysicsFS is used,")
  167. message(WARNING " *** but is this what you REALLY wanted?")
  168. message(WARNING " *** (Maybe fix CMakeLists.txt, or write a platform driver?)")
  169. message(WARNING " ***")
  170. endif()
  171. if(PHYSFS_HAVE_THREAD_SUPPORT)
  172. add_definitions(-D_REENTRANT -D_THREAD_SAFE)
  173. else()
  174. add_definitions(-DPHYSFS_NO_THREAD_SUPPORT=1)
  175. message(WARNING " ***")
  176. message(WARNING " *** There is no thread support in this build!")
  177. message(WARNING " *** PhysicsFS will NOT be reentrant!")
  178. message(WARNING " *** This may be fine, depending on how PhysicsFS is used,")
  179. message(WARNING " *** but is this what you REALLY wanted?")
  180. message(WARNING " *** (Maybe fix CMakeLists.txt, or write a platform driver?)")
  181. message(WARNING " ***")
  182. endif()
  183. # Archivers ...
  184. option(PHYSFS_ARCHIVE_ZIP "Enable ZIP support" TRUE)
  185. if(PHYSFS_ARCHIVE_ZIP)
  186. add_definitions(-DPHYSFS_SUPPORTS_ZIP=1)
  187. endif()
  188. option(PHYSFS_ARCHIVE_7Z "Enable 7zip support" TRUE)
  189. if(PHYSFS_ARCHIVE_7Z)
  190. add_definitions(-DPHYSFS_SUPPORTS_7Z=1)
  191. # !!! FIXME: rename to 7z.c?
  192. set(PHYSFS_SRCS ${PHYSFS_SRCS} ${LZMA_SRCS})
  193. endif()
  194. option(PHYSFS_ARCHIVE_GRP "Enable Build Engine GRP support" TRUE)
  195. if(PHYSFS_ARCHIVE_GRP)
  196. add_definitions(-DPHYSFS_SUPPORTS_GRP=1)
  197. endif()
  198. option(PHYSFS_ARCHIVE_WAD "Enable Doom WAD support" TRUE)
  199. if(PHYSFS_ARCHIVE_WAD)
  200. add_definitions(-DPHYSFS_SUPPORTS_WAD=1)
  201. endif()
  202. option(PHYSFS_ARCHIVE_HOG "Enable Descent I/II HOG support" TRUE)
  203. if(PHYSFS_ARCHIVE_HOG)
  204. add_definitions(-DPHYSFS_SUPPORTS_HOG=1)
  205. endif()
  206. option(PHYSFS_ARCHIVE_MVL "Enable Descent I/II MVL support" TRUE)
  207. if(PHYSFS_ARCHIVE_MVL)
  208. add_definitions(-DPHYSFS_SUPPORTS_MVL=1)
  209. endif()
  210. option(PHYSFS_ARCHIVE_QPAK "Enable Quake I/II QPAK support" TRUE)
  211. if(PHYSFS_ARCHIVE_QPAK)
  212. add_definitions(-DPHYSFS_SUPPORTS_QPAK=1)
  213. endif()
  214. option(PHYSFS_ARCHIVE_SLB "Enable I-War / Independence War SLB support" TRUE)
  215. if(PHYSFS_ARCHIVE_SLB)
  216. add_definitions(-DPHYSFS_SUPPORTS_SLB=1)
  217. endif()
  218. option(PHYSFS_ARCHIVE_ISO9660 "Enable ISO9660 support" TRUE)
  219. if(PHYSFS_ARCHIVE_ISO9660)
  220. add_definitions(-DPHYSFS_SUPPORTS_ISO9660=1)
  221. endif()
  222. option(PHYSFS_BUILD_STATIC "Build static library" TRUE)
  223. if(PHYSFS_BUILD_STATIC)
  224. add_library(physfs-static STATIC ${PHYSFS_SRCS})
  225. set_target_properties(physfs-static PROPERTIES OUTPUT_NAME "physfs")
  226. set(PHYSFS_LIB_TARGET physfs-static)
  227. set(PHYSFS_INSTALL_TARGETS ${PHYSFS_INSTALL_TARGETS} ";physfs-static")
  228. endif()
  229. option(PHYSFS_BUILD_SHARED "Build shared library" TRUE)
  230. if(PHYSFS_BUILD_SHARED)
  231. add_library(physfs SHARED ${PHYSFS_SRCS})
  232. set_target_properties(physfs PROPERTIES VERSION ${PHYSFS_VERSION})
  233. set_target_properties(physfs PROPERTIES SOVERSION ${PHYSFS_SOVERSION})
  234. target_link_libraries(physfs ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS})
  235. set(PHYSFS_LIB_TARGET physfs)
  236. set(PHYSFS_INSTALL_TARGETS ${PHYSFS_INSTALL_TARGETS} ";physfs")
  237. endif()
  238. if(NOT PHYSFS_BUILD_SHARED AND NOT PHYSFS_BUILD_STATIC)
  239. message(FATAL "Both shared and static libraries are disabled!")
  240. endif()
  241. # CMake FAQ says I need this...
  242. if(PHYSFS_BUILD_SHARED AND PHYSFS_BUILD_STATIC)
  243. set_target_properties(physfs PROPERTIES CLEAN_DIRECT_OUTPUT 1)
  244. set_target_properties(physfs-static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
  245. endif()
  246. option(PHYSFS_BUILD_TEST "Build stdio test program." TRUE)
  247. mark_as_advanced(PHYSFS_BUILD_TEST)
  248. if(PHYSFS_BUILD_TEST)
  249. find_path(READLINE_H readline/readline.h)
  250. find_path(HISTORY_H readline/history.h)
  251. if(READLINE_H AND HISTORY_H)
  252. find_library(CURSES_LIBRARY NAMES curses ncurses)
  253. set(CMAKE_REQUIRED_LIBRARIES ${CURSES_LIBRARY})
  254. find_library(READLINE_LIBRARY readline)
  255. if(READLINE_LIBRARY)
  256. set(HAVE_SYSTEM_READLINE TRUE)
  257. set(TEST_PHYSFS_LIBS ${TEST_PHYSFS_LIBS} ${READLINE_LIBRARY} ${CURSES_LIBRARY})
  258. include_directories(SYSTEM ${READLINE_H} ${HISTORY_H})
  259. add_definitions(-DPHYSFS_HAVE_READLINE=1)
  260. endif()
  261. endif()
  262. add_executable(test_physfs test/test_physfs.c)
  263. target_link_libraries(test_physfs ${PHYSFS_LIB_TARGET} ${TEST_PHYSFS_LIBS} ${OTHER_LDFLAGS})
  264. set(PHYSFS_INSTALL_TARGETS ${PHYSFS_INSTALL_TARGETS} ";test_physfs")
  265. endif()
  266. install(TARGETS ${PHYSFS_INSTALL_TARGETS}
  267. RUNTIME DESTINATION bin
  268. LIBRARY DESTINATION lib${LIB_SUFFIX}
  269. ARCHIVE DESTINATION lib${LIB_SUFFIX})
  270. install(FILES src/physfs.h DESTINATION include)
  271. find_package(Doxygen)
  272. if(DOXYGEN_FOUND)
  273. set(PHYSFS_OUTPUT_DOXYFILE "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile")
  274. configure_file(
  275. "${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile"
  276. "${PHYSFS_OUTPUT_DOXYFILE}"
  277. COPYONLY
  278. )
  279. file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "\n\n# Below auto-generated by cmake...\n\n")
  280. file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "PROJECT_NUMBER = \"${PHYSFS_VERSION}\"\n")
  281. file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "OUTPUT_DIRECTORY = \"${CMAKE_CURRENT_BINARY_DIR}/docs\"\n")
  282. file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "\n# End auto-generated section.\n\n")
  283. add_custom_target(
  284. docs
  285. ${DOXYGEN_EXECUTABLE} "${PHYSFS_OUTPUT_DOXYFILE}"
  286. WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
  287. COMMENT "Building documentation in 'docs' directory..."
  288. )
  289. else()
  290. message(STATUS "Doxygen not found. You won't be able to build documentation.")
  291. endif()
  292. if(UNIX)
  293. set(PHYSFS_TARBALL "${CMAKE_CURRENT_SOURCE_DIR}/../physfs-${PHYSFS_VERSION}.tar.bz2")
  294. add_custom_target(
  295. dist
  296. hg archive -t tbz2 "${PHYSFS_TARBALL}"
  297. WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
  298. COMMENT "Building source tarball '${PHYSFS_TARBALL}'..."
  299. )
  300. add_custom_target(
  301. uninstall
  302. "${CMAKE_CURRENT_SOURCE_DIR}/extras/uninstall.sh"
  303. WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
  304. COMMENT "Uninstall the project..."
  305. )
  306. endif()
  307. if(UNIX AND NOT APPLE)
  308. configure_file(
  309. "extras/physfs.pc.in"
  310. "extras/physfs.pc"
  311. @ONLY
  312. )
  313. install(
  314. FILES "${CMAKE_CURRENT_BINARY_DIR}/extras/physfs.pc"
  315. DESTINATION "lib/pkgconfig"
  316. )
  317. endif()
  318. macro(message_bool_option _NAME _VALUE)
  319. if(${_VALUE})
  320. message(STATUS " ${_NAME}: enabled")
  321. else()
  322. message(STATUS " ${_NAME}: disabled")
  323. endif()
  324. endmacro()
  325. message(STATUS "PhysicsFS will build with the following options:")
  326. message_bool_option("ZIP support" PHYSFS_ARCHIVE_ZIP)
  327. message_bool_option("7zip support" PHYSFS_ARCHIVE_7Z)
  328. message_bool_option("GRP support" PHYSFS_ARCHIVE_GRP)
  329. message_bool_option("WAD support" PHYSFS_ARCHIVE_WAD)
  330. message_bool_option("HOG support" PHYSFS_ARCHIVE_HOG)
  331. message_bool_option("MVL support" PHYSFS_ARCHIVE_MVL)
  332. message_bool_option("QPAK support" PHYSFS_ARCHIVE_QPAK)
  333. message_bool_option("SLB support" PHYSFS_ARCHIVE_SLB)
  334. message_bool_option("CD-ROM drive support" PHYSFS_HAVE_CDROM_SUPPORT)
  335. message_bool_option("Thread safety" PHYSFS_HAVE_THREAD_SUPPORT)
  336. message_bool_option("Build static library" PHYSFS_BUILD_STATIC)
  337. message_bool_option("Build shared library" PHYSFS_BUILD_SHARED)
  338. message_bool_option("Build stdio test program" PHYSFS_BUILD_TEST)
  339. if(PHYSFS_BUILD_TEST)
  340. message_bool_option(" Use readline in test program" HAVE_SYSTEM_READLINE)
  341. endif()
  342. # end of CMakeLists.txt ...