-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCMakeLists.txt
299 lines (275 loc) · 8.81 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#
# Copyright 2024 "Simon Sandström"
# Copyright 2024 "John Högberg"
#
# This file is part of tibiarc.
#
# tibiarc is free software: you can redistribute it and/or modify it under the
# terms of the GNU Affero General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# tibiarc is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License
# along with tibiarc. If not, see <https://www.gnu.org/licenses/>.
#
## Note that this is the oldest version tested against, even older versions
## might work.
cmake_minimum_required(VERSION 3.13)
project(tibiarc
VERSION 0.1
LANGUAGES C
)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo)
endif()
option(TIBIARC_CROSSCOMPILING "Whether this is a cross-compiled build" OFF)
if(TIBIARC_CROSSCOMPILING)
set(CMAKE_CROSSCOMPILING TRUE)
set(TIBIARC_NO_LTO TRUE)
endif()
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_EXTENSIONS OFF)
# ########################################################################### #
## `tibiarc` library
# ########################################################################### #
# Read L1 cache line size
execute_process(
COMMAND getconf LEVEL1_DCACHE_LINESIZE
OUTPUT_VARIABLE LEVEL1_DCACHE_LINESIZE
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE RET
)
if(RET AND NOT RET EQUAL 0)
set(LEVEL1_DCACHE_LINESIZE "128")
endif()
add_library(tibiarc
"lib/canvas.c"
"lib/canvas.h"
"lib/characterset.h"
"lib/container.c"
"lib/container.h"
"lib/creature.c"
"lib/creature.h"
"lib/datareader.c"
"lib/datareader.h"
"lib/demuxer.c"
"lib/deps/7z/7zTypes.h"
"lib/deps/7z/Alloc.c"
"lib/deps/7z/Alloc.h"
"lib/deps/7z/Compiler.h"
"lib/deps/7z/LzmaDec.c"
"lib/deps/7z/LzmaDec.h"
"lib/deps/7z/Precomp.h"
"lib/deps/uthash.h"
"lib/effect.h"
"lib/fonts.c"
"lib/fonts.h"
"lib/formats/cam.c"
"lib/formats/rec.c"
"lib/formats/tibiacast.c"
"lib/formats/tibiareplay.c"
"lib/formats/tmv2.c"
"lib/formats/tmv1.c"
"lib/formats/ttm.c"
"lib/formats/yatc.c"
"lib/gamestate.c"
"lib/gamestate.h"
"lib/icons.c"
"lib/icons.h"
"lib/map.h"
"lib/message.c"
"lib/message.h"
"lib/missile.h"
"lib/object.h"
"lib/packet.c"
"lib/parser.c"
"lib/parser.h"
"lib/pictures.c"
"lib/pictures.h"
"lib/pixel.h"
"lib/player.h"
"lib/position.h"
"lib/recordings.c"
"lib/recordings.h"
"lib/renderer.c"
"lib/renderer.h"
"lib/report.c"
"lib/report.h"
"lib/sprites.c"
"lib/sprites.h"
"lib/textrenderer.c"
"lib/textrenderer.h"
"lib/tile.c"
"lib/tile.h"
"lib/types.c"
"lib/types.h"
"lib/utils.h"
"lib/versions_decl.h"
"lib/versions.c"
"lib/versions.h"
)
target_include_directories(tibiarc PUBLIC "lib")
target_link_libraries(tibiarc PRIVATE m)
target_compile_definitions(tibiarc PUBLIC "LEVEL1_DCACHE_LINESIZE=${LEVEL1_DCACHE_LINESIZE}")
# Options to help debug certain versioning issues, enable them with e.g.
# `cmake -DTIBIARC_DUMP_PIC=ON ...`
option(TIBIARC_DUMP_PIC "Dumps .pic files as bitmaps when loaded" OFF)
if(TIBIARC_DUMP_PIC)
target_compile_definitions(tibiarc PRIVATE DUMP_PIC)
endif()
option(TIBIARC_DUMP_MESSAGE_TYPES "Writes messages and their types to stdout when received" OFF)
if(TIBIARC_DUMP_MESSAGE_TYPES)
target_compile_definitions(tibiarc PRIVATE DUMP_MESSAGE_TYPES)
endif()
option(TIBIARC_DUMP_ITEMS "Dumps item sprites (with properties) as bitmaps when loaded" OFF)
if(TIBIARC_DUMP_ITEMS)
target_compile_definitions(tibiarc PRIVATE DUMP_ITEMS)
endif()
option(TIBIARC_NO_ZLIB "Explicitly disable zlib support" OFF)
if(NOT TIBIARC_NO_ZLIB)
find_package(ZLIB QUIET)
if (NOT ZLIB_FOUND)
message(WARNING "zlib was not found, tibiarc will be built without zlib support")
endif()
endif()
if(ZLIB_FOUND)
target_include_directories(tibiarc PRIVATE ${ZLIB_INCLUDE_DIRS})
target_link_libraries(tibiarc PRIVATE ${ZLIB_LIBRARIES})
else()
target_compile_definitions(tibiarc PRIVATE DISABLE_ZLIB)
endif()
option(TIBIARC_NO_OPENSSL "Explicitly disable zlib support" OFF)
if(NOT TIBIARC_NO_OPENSSL)
find_package(OpenSSL QUIET)
if (NOT OPENSSL_FOUND)
message(WARNING "libcrypto was not found, tibiarc will be built without crypto support")
endif()
endif()
if(OPENSSL_FOUND)
target_include_directories(tibiarc PRIVATE ${OPENSSL_INCLUDE_DIR})
target_link_libraries(tibiarc PRIVATE OpenSSL::Crypto)
else()
target_compile_definitions(tibiarc PRIVATE DISABLE_OPENSSL_CRYPTO)
endif()
# ########################################################################### #
## Recording converter
# ########################################################################### #
add_executable(converter
"converter/converter.c"
"converter/encoders/inert.c"
"converter/encoders/libav.c"
"converter/encoding.c"
"converter/encoding.h"
"converter/exporter.c"
"converter/exporter.h"
"utils/memoryfile.c"
"utils/memoryfile.h"
)
target_include_directories(converter PRIVATE "converter" "utils")
target_link_libraries(converter PRIVATE tibiarc)
# SDL2
option(TIBIARC_NO_SDL2 "Explicitly disable SDL2" OFF)
if(NOT TIBIARC_NO_SDL2)
find_package(SDL2 QUIET)
if (NOT SDL2_FOUND)
message(WARNING "SDL2 was not found, converter will be built without SDL2 encoder")
endif()
endif()
if(SDL2_FOUND)
target_include_directories(converter PRIVATE ${SDL2_INCLUDE_DIRS})
target_link_libraries(converter PRIVATE SDL2::SDL2)
else()
target_compile_definitions(converter PRIVATE DISABLE_SDL2)
endif()
# ffmpeg
option(TIBIARC_NO_LIBAV "Explicitly disable ffmpeg" OFF)
if(NOT TIBIARC_NO_LIBAV)
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBAV IMPORTED_TARGET
libavcodec
libavformat
libswscale
libavutil
)
if(NOT LIBAV_FOUND)
message(WARNING "ffmpeg libraries were not found, converter will be built without ffmpeg encoder")
endif()
endif()
if(LIBAV_FOUND)
target_include_directories(converter PRIVATE ${LIBAV_INCLUDE_DIRS})
target_link_libraries(converter PRIVATE PkgConfig::LIBAV)
else()
target_compile_definitions(converter PRIVATE DISABLE_LIBAV)
endif()
# OpenMP support
option(TIBIARC_NO_OPENMP "Explicitly disable OpenMP support" OFF)
if(NOT TIBIARC_NO_OPENMP)
find_package(OpenMP QUIET)
endif()
if(OpenMP_C_FOUND)
target_include_directories(converter PRIVATE ${OpenMP_C_INCLUDE_DIRS})
target_compile_options(converter PRIVATE ${OpenMP_C_FLAGS})
target_link_libraries(converter PRIVATE ${OpenMP_C_LIBRARIES})
endif()
# ########################################################################### #
## player
# ########################################################################### #
add_executable(player
"player/player.c"
"player/playback.c"
"player/playback.h"
"player/rendering.c"
"player/rendering.h"
"utils/memoryfile.c"
"utils/memoryfile.h"
)
target_include_directories(player PRIVATE "converter" "utils")
target_link_libraries(player PRIVATE tibiarc)
if(NOT EMSCRIPTEN)
if(NOT SDL2_FOUND)
message(FATAL_ERROR "player without EMSCRIPTEN requires SDL2")
endif()
target_include_directories(player PRIVATE ${SDL2_INCLUDE_DIRS})
target_link_libraries(player PRIVATE ${SDL2_LIBRARIES})
else()
set_target_properties(converter PROPERTIES EXCLUDE_FROM_ALL 1)
set_target_properties(player PROPERTIES SUFFIX ".html")
target_compile_options(player PRIVATE -sUSE_SDL=2)
target_link_options(player PRIVATE
-sUSE_SDL=2
-sALLOW_MEMORY_GROWTH=1
-sEXPORTED_FUNCTIONS=_main,_load_files,_malloc
-sEXPORTED_RUNTIME_METHODS=ccall)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_link_options(player PRIVATE
-sEXCEPTION_DEBUG=1
-sASSERTIONS=1
-sSAFE_HEAP=1
-sDEMANGLE_SUPPORT=1)
endif()
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/player/index.html"
"${CMAKE_BINARY_DIR}/index.html" COPYONLY)
endif()
# ########################################################################### #
## Misc flags that must be set at the very end
# ########################################################################### #
# Enable IPO if supported
option(TIBIARC_NO_LTO "Explicitly disable link-time optimization" OFF)
if(NOT TIBIARC_NO_LTO)
if(NOT EMSCRIPTEN)
include(CheckIPOSupported)
check_ipo_supported(RESULT ipo_supported)
if(ipo_supported)
set_target_properties(tibiarc converter
PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
set_target_properties(player PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
endif()
endif()
# Include extra CMakeLists.txt if available
include(CMakeLists.user.txt OPTIONAL)