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