Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | pmbaty | 1 | # PhysicsFS; a portable, flexible file i/o abstraction. |
2 | # |
||
3 | # Please see the file LICENSE.txt in the source's root directory. |
||
4 | |||
5 | # The CMake project file is meant to get this compiling on all sorts of |
||
6 | # platforms quickly, and serve as the way Unix platforms and Linux distros |
||
7 | # package up official builds, but you don't _need_ to use this; we have |
||
8 | # built PhysicsFS to (hopefully) be able to drop into your project and |
||
9 | # compile, using preprocessor checks for platform-specific bits instead of |
||
10 | # testing in here. |
||
11 | |||
12 | cmake_minimum_required(VERSION 2.8.4) |
||
13 | |||
14 | project(PhysicsFS) |
||
15 | set(PHYSFS_VERSION 3.0.2) |
||
16 | |||
17 | # Increment this if/when we break backwards compatibility. |
||
18 | set(PHYSFS_SOVERSION 1) |
||
19 | |||
20 | # I hate that they define "WIN32" ... we're about to move to Win64...I hope! |
||
21 | if(WIN32 AND NOT WINDOWS) |
||
22 | set(WINDOWS TRUE) |
||
23 | endif() |
||
24 | |||
25 | include_directories(./src) |
||
26 | |||
27 | if(APPLE) |
||
28 | set(OTHER_LDFLAGS ${OTHER_LDFLAGS} "-framework IOKit -framework Foundation") |
||
29 | set(PHYSFS_M_SRCS src/physfs_platform_apple.m) |
||
30 | endif() |
||
31 | |||
32 | if(CMAKE_COMPILER_IS_GNUCC) |
||
33 | # Don't use -rpath. |
||
34 | set(CMAKE_SKIP_RPATH ON CACHE BOOL "Skip RPATH" FORCE) |
||
35 | endif() |
||
36 | |||
37 | if(CMAKE_C_COMPILER_ID STREQUAL "SunPro") |
||
38 | add_definitions(-erroff=E_EMPTY_TRANSLATION_UNIT) |
||
39 | add_definitions(-xldscope=hidden) |
||
40 | endif() |
||
41 | |||
42 | if(HAIKU) |
||
43 | # We add this explicitly, since we don't want CMake to think this |
||
44 | # is a C++ project unless we're on Haiku. |
||
45 | set(PHYSFS_CPP_SRCS src/physfs_platform_haiku.cpp) |
||
46 | find_library(BE_LIBRARY be) |
||
47 | find_library(ROOT_LIBRARY root) |
||
48 | set(OPTIONAL_LIBRARY_LIBS ${OPTIONAL_LIBRARY_LIBS} ${BE_LIBRARY} ${ROOT_LIBRARY}) |
||
49 | endif() |
||
50 | |||
51 | if(CMAKE_SYSTEM_NAME STREQUAL "WindowsPhone" OR CMAKE_SYSTEM_NAME STREQUAL "WindowsStore") |
||
52 | set(WINRT TRUE) |
||
53 | endif() |
||
54 | |||
55 | if(WINRT) |
||
56 | set(PHYSFS_CPP_SRCS src/physfs_platform_winrt.cpp) |
||
57 | endif() |
||
58 | |||
59 | if(UNIX AND NOT WINDOWS AND NOT APPLE) # (MingW and such might be UNIX _and_ WINDOWS!) |
||
60 | find_library(PTHREAD_LIBRARY pthread) |
||
61 | if(PTHREAD_LIBRARY) |
||
62 | set(OPTIONAL_LIBRARY_LIBS ${OPTIONAL_LIBRARY_LIBS} ${PTHREAD_LIBRARY}) |
||
63 | endif() |
||
64 | endif() |
||
65 | |||
66 | # Almost everything is "compiled" here, but things that don't apply to the |
||
67 | # build are #ifdef'd out. This is to make it easy to embed PhysicsFS into |
||
68 | # another project or bring up a new build system: just compile all the source |
||
69 | # code and #define the things you want. |
||
70 | set(PHYSFS_SRCS |
||
71 | src/physfs.c |
||
72 | src/physfs_byteorder.c |
||
73 | src/physfs_unicode.c |
||
74 | src/physfs_platform_posix.c |
||
75 | src/physfs_platform_unix.c |
||
76 | src/physfs_platform_windows.c |
||
77 | src/physfs_platform_os2.c |
||
78 | src/physfs_platform_qnx.c |
||
79 | src/physfs_archiver_dir.c |
||
80 | src/physfs_archiver_unpacked.c |
||
81 | src/physfs_archiver_grp.c |
||
82 | src/physfs_archiver_hog.c |
||
83 | src/physfs_archiver_7z.c |
||
84 | src/physfs_archiver_mvl.c |
||
85 | src/physfs_archiver_qpak.c |
||
86 | src/physfs_archiver_wad.c |
||
87 | src/physfs_archiver_zip.c |
||
88 | src/physfs_archiver_slb.c |
||
89 | src/physfs_archiver_iso9660.c |
||
90 | src/physfs_archiver_vdf.c |
||
91 | ${PHYSFS_CPP_SRCS} |
||
92 | ${PHYSFS_M_SRCS} |
||
93 | ) |
||
94 | |||
95 | |||
96 | # Archivers ... |
||
97 | # These are (mostly) on by default now, so these options are only useful for |
||
98 | # disabling them. |
||
99 | |||
100 | option(PHYSFS_ARCHIVE_ZIP "Enable ZIP support" TRUE) |
||
101 | if(NOT PHYSFS_ARCHIVE_ZIP) |
||
102 | add_definitions(-DPHYSFS_SUPPORTS_ZIP=0) |
||
103 | endif() |
||
104 | |||
105 | option(PHYSFS_ARCHIVE_7Z "Enable 7zip support" TRUE) |
||
106 | if(NOT PHYSFS_ARCHIVE_7Z) |
||
107 | add_definitions(-DPHYSFS_SUPPORTS_7Z=0) |
||
108 | endif() |
||
109 | |||
110 | option(PHYSFS_ARCHIVE_GRP "Enable Build Engine GRP support" TRUE) |
||
111 | if(NOT PHYSFS_ARCHIVE_GRP) |
||
112 | add_definitions(-DPHYSFS_SUPPORTS_GRP=0) |
||
113 | endif() |
||
114 | |||
115 | option(PHYSFS_ARCHIVE_WAD "Enable Doom WAD support" TRUE) |
||
116 | if(NOT PHYSFS_ARCHIVE_WAD) |
||
117 | add_definitions(-DPHYSFS_SUPPORTS_WAD=0) |
||
118 | endif() |
||
119 | |||
120 | option(PHYSFS_ARCHIVE_HOG "Enable Descent I/II HOG support" TRUE) |
||
121 | if(NOT PHYSFS_ARCHIVE_HOG) |
||
122 | add_definitions(-DPHYSFS_SUPPORTS_HOG=0) |
||
123 | endif() |
||
124 | |||
125 | option(PHYSFS_ARCHIVE_MVL "Enable Descent I/II MVL support" TRUE) |
||
126 | if(NOT PHYSFS_ARCHIVE_MVL) |
||
127 | add_definitions(-DPHYSFS_SUPPORTS_MVL=0) |
||
128 | endif() |
||
129 | |||
130 | option(PHYSFS_ARCHIVE_QPAK "Enable Quake I/II QPAK support" TRUE) |
||
131 | if(NOT PHYSFS_ARCHIVE_QPAK) |
||
132 | add_definitions(-DPHYSFS_SUPPORTS_QPAK=0) |
||
133 | endif() |
||
134 | |||
135 | option(PHYSFS_ARCHIVE_SLB "Enable I-War / Independence War SLB support" TRUE) |
||
136 | if(NOT PHYSFS_ARCHIVE_SLB) |
||
137 | add_definitions(-DPHYSFS_SUPPORTS_SLB=0) |
||
138 | endif() |
||
139 | |||
140 | option(PHYSFS_ARCHIVE_ISO9660 "Enable ISO9660 support" TRUE) |
||
141 | if(NOT PHYSFS_ARCHIVE_ISO9660) |
||
142 | add_definitions(-DPHYSFS_SUPPORTS_ISO9660=0) |
||
143 | endif() |
||
144 | |||
145 | option(PHYSFS_ARCHIVE_VDF "Enable Gothic I/II VDF archive support" TRUE) |
||
146 | if(NOT PHYSFS_ARCHIVE_VDF) |
||
147 | add_definitions(-DPHYSFS_SUPPORTS_VDF=0) |
||
148 | endif() |
||
149 | |||
150 | |||
151 | option(PHYSFS_BUILD_STATIC "Build static library" TRUE) |
||
152 | if(PHYSFS_BUILD_STATIC) |
||
153 | add_library(physfs-static STATIC ${PHYSFS_SRCS}) |
||
154 | # Don't rename this on Windows, since DLLs will also produce an import |
||
155 | # library named "physfs.lib" which would conflict; Unix tend to like the |
||
156 | # same library name with a different extension for static libs, but |
||
157 | # Windows can just have a separate name. |
||
158 | if(NOT MSVC) |
||
159 | set_target_properties(physfs-static PROPERTIES OUTPUT_NAME "physfs") |
||
160 | endif() |
||
161 | if(WINRT) |
||
162 | # Ignore LNK4264 warnings; we don't author any WinRT components, just consume them, so we're okay in a static library. |
||
163 | set_target_properties(physfs-static PROPERTIES VS_WINRT_COMPONENT True) |
||
164 | set_target_properties(physfs-static PROPERTIES STATIC_LIBRARY_FLAGS "/ignore:4264") |
||
165 | endif() |
||
166 | |||
167 | set(PHYSFS_LIB_TARGET physfs-static) |
||
168 | set(PHYSFS_INSTALL_TARGETS ${PHYSFS_INSTALL_TARGETS} ";physfs-static") |
||
169 | endif() |
||
170 | |||
171 | option(PHYSFS_BUILD_SHARED "Build shared library" TRUE) |
||
172 | if(PHYSFS_BUILD_SHARED) |
||
173 | add_library(physfs SHARED ${PHYSFS_SRCS}) |
||
174 | set_target_properties(physfs PROPERTIES MACOSX_RPATH 1) |
||
175 | set_target_properties(physfs PROPERTIES VERSION ${PHYSFS_VERSION}) |
||
176 | set_target_properties(physfs PROPERTIES SOVERSION ${PHYSFS_SOVERSION}) |
||
177 | if(WINRT) |
||
178 | set_target_properties(physfs PROPERTIES VS_WINRT_COMPONENT True) |
||
179 | endif() |
||
180 | target_link_libraries(physfs ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS}) |
||
181 | set(PHYSFS_LIB_TARGET physfs) |
||
182 | set(PHYSFS_INSTALL_TARGETS ${PHYSFS_INSTALL_TARGETS} ";physfs") |
||
183 | endif() |
||
184 | |||
185 | if(NOT PHYSFS_BUILD_SHARED AND NOT PHYSFS_BUILD_STATIC) |
||
186 | message(FATAL "Both shared and static libraries are disabled!") |
||
187 | endif() |
||
188 | |||
189 | # CMake FAQ says I need this... |
||
190 | if(PHYSFS_BUILD_SHARED AND PHYSFS_BUILD_STATIC AND NOT WINDOWS) |
||
191 | set_target_properties(physfs PROPERTIES CLEAN_DIRECT_OUTPUT 1) |
||
192 | set_target_properties(physfs-static PROPERTIES CLEAN_DIRECT_OUTPUT 1) |
||
193 | endif() |
||
194 | |||
195 | option(PHYSFS_BUILD_TEST "Build stdio test program." TRUE) |
||
196 | mark_as_advanced(PHYSFS_BUILD_TEST) |
||
197 | if(PHYSFS_BUILD_TEST) |
||
198 | find_path(READLINE_H readline/readline.h) |
||
199 | find_path(HISTORY_H readline/history.h) |
||
200 | if(READLINE_H AND HISTORY_H) |
||
201 | find_library(CURSES_LIBRARY NAMES curses ncurses) |
||
202 | set(CMAKE_REQUIRED_LIBRARIES ${CURSES_LIBRARY}) |
||
203 | find_library(READLINE_LIBRARY readline) |
||
204 | if(READLINE_LIBRARY) |
||
205 | set(HAVE_SYSTEM_READLINE TRUE) |
||
206 | set(TEST_PHYSFS_LIBS ${TEST_PHYSFS_LIBS} ${READLINE_LIBRARY} ${CURSES_LIBRARY}) |
||
207 | include_directories(SYSTEM ${READLINE_H} ${HISTORY_H}) |
||
208 | add_definitions(-DPHYSFS_HAVE_READLINE=1) |
||
209 | endif() |
||
210 | endif() |
||
211 | add_executable(test_physfs test/test_physfs.c) |
||
212 | target_link_libraries(test_physfs ${PHYSFS_LIB_TARGET} ${TEST_PHYSFS_LIBS} ${OTHER_LDFLAGS}) |
||
213 | set(PHYSFS_INSTALL_TARGETS ${PHYSFS_INSTALL_TARGETS} ";test_physfs") |
||
214 | endif() |
||
215 | |||
216 | install(TARGETS ${PHYSFS_INSTALL_TARGETS} |
||
217 | RUNTIME DESTINATION bin |
||
218 | LIBRARY DESTINATION lib${LIB_SUFFIX} |
||
219 | ARCHIVE DESTINATION lib${LIB_SUFFIX}) |
||
220 | install(FILES src/physfs.h DESTINATION include) |
||
221 | |||
222 | find_package(Doxygen) |
||
223 | if(DOXYGEN_FOUND) |
||
224 | set(PHYSFS_OUTPUT_DOXYFILE "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile") |
||
225 | configure_file( |
||
226 | "${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile" |
||
227 | "${PHYSFS_OUTPUT_DOXYFILE}" |
||
228 | COPYONLY |
||
229 | ) |
||
230 | file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "\n\n# Below auto-generated by cmake...\n\n") |
||
231 | file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "PROJECT_NUMBER = \"${PHYSFS_VERSION}\"\n") |
||
232 | file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "OUTPUT_DIRECTORY = \"${CMAKE_CURRENT_BINARY_DIR}/docs\"\n") |
||
233 | file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "\n# End auto-generated section.\n\n") |
||
234 | |||
235 | set(PHYSFS_TARGETNAME_DOCS "docs" CACHE STRING "Name of 'docs' build target") |
||
236 | add_custom_target( |
||
237 | ${PHYSFS_TARGETNAME_DOCS} |
||
238 | ${DOXYGEN_EXECUTABLE} "${PHYSFS_OUTPUT_DOXYFILE}" |
||
239 | WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" |
||
240 | COMMENT "Building documentation in 'docs' directory..." |
||
241 | ) |
||
242 | else() |
||
243 | message(STATUS "Doxygen not found. You won't be able to build documentation.") |
||
244 | endif() |
||
245 | |||
246 | if(UNIX) |
||
247 | set(PHYSFS_TARBALL "${CMAKE_CURRENT_SOURCE_DIR}/../physfs-${PHYSFS_VERSION}.tar.bz2") |
||
248 | |||
249 | set(PHYSFS_TARGETNAME_DIST "dist" CACHE STRING "Name of 'dist' build target") |
||
250 | add_custom_target( |
||
251 | ${PHYSFS_TARGETNAME_DIST} |
||
252 | hg archive -t tbz2 "${PHYSFS_TARBALL}" |
||
253 | WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" |
||
254 | COMMENT "Building source tarball '${PHYSFS_TARBALL}'..." |
||
255 | ) |
||
256 | |||
257 | set(PHYSFS_TARGETNAME_UNINSTALL "uninstall" CACHE STRING "Name of 'uninstall' build target") |
||
258 | add_custom_target( |
||
259 | ${PHYSFS_TARGETNAME_UNINSTALL} |
||
260 | "${CMAKE_CURRENT_SOURCE_DIR}/extras/uninstall.sh" |
||
261 | WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" |
||
262 | COMMENT "Uninstall the project..." |
||
263 | ) |
||
264 | endif() |
||
265 | |||
266 | if(NOT MSVC) |
||
267 | configure_file( |
||
268 | "extras/physfs.pc.in" |
||
269 | "extras/physfs.pc" |
||
270 | @ONLY |
||
271 | ) |
||
272 | install( |
||
273 | FILES "${CMAKE_CURRENT_BINARY_DIR}/extras/physfs.pc" |
||
274 | DESTINATION "lib${LIB_SUFFIX}/pkgconfig" |
||
275 | ) |
||
276 | endif() |
||
277 | |||
278 | macro(message_bool_option _NAME _VALUE) |
||
279 | if(${_VALUE}) |
||
280 | message(STATUS " ${_NAME}: enabled") |
||
281 | else() |
||
282 | message(STATUS " ${_NAME}: disabled") |
||
283 | endif() |
||
284 | endmacro() |
||
285 | |||
286 | message(STATUS "PhysicsFS will build with the following options:") |
||
287 | message_bool_option("ZIP support" PHYSFS_ARCHIVE_ZIP) |
||
288 | message_bool_option("7zip support" PHYSFS_ARCHIVE_7Z) |
||
289 | message_bool_option("GRP support" PHYSFS_ARCHIVE_GRP) |
||
290 | message_bool_option("WAD support" PHYSFS_ARCHIVE_WAD) |
||
291 | message_bool_option("HOG support" PHYSFS_ARCHIVE_HOG) |
||
292 | message_bool_option("MVL support" PHYSFS_ARCHIVE_MVL) |
||
293 | message_bool_option("QPAK support" PHYSFS_ARCHIVE_QPAK) |
||
294 | message_bool_option("SLB support" PHYSFS_ARCHIVE_SLB) |
||
295 | message_bool_option("VDF support" PHYSFS_ARCHIVE_VDF) |
||
296 | message_bool_option("ISO9660 support" PHYSFS_ARCHIVE_ISO9660) |
||
297 | message_bool_option("Build static library" PHYSFS_BUILD_STATIC) |
||
298 | message_bool_option("Build shared library" PHYSFS_BUILD_SHARED) |
||
299 | message_bool_option("Build stdio test program" PHYSFS_BUILD_TEST) |
||
300 | if(PHYSFS_BUILD_TEST) |
||
301 | message_bool_option(" Use readline in test program" HAVE_SYSTEM_READLINE) |
||
302 | endif() |
||
303 | |||
304 | # end of CMakeLists.txt ... |
||
305 |