-
Notifications
You must be signed in to change notification settings - Fork 20
/
CMakeLists.txt
434 lines (375 loc) · 11.8 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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
if(${CMAKE_VERSION} VERSION_LESS "3.9.0")
cmake_minimum_required(VERSION 2.6)
message("Please upgrade to cmake 3.9 to get more fancy stuff")
else()
cmake_minimum_required(VERSION 3.9)
endif()
option(BUILD_TESTS "Build tests")
set (CMAKE_CXX_STANDARD 20)
set(CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if(NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "")
message(STATUS "Build type not set, setting to RelWithDebInfo")
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif()
project(freeaoe)
if(DEFAULT_DATA_PATH)
add_definitions(-DDEFAULT_DATA_PATH=\"${DEFAULT_DATA_PATH}\")
endif()
#############################
## Compiler specific stuff ##
#############################
option(ENABLE_IPO "Enable link-time optimization, improves speed and memory usage (https://en.wikipedia.org/wiki/Interprocedural_optimization)")
if (ENABLE_IPO)
include(CheckIPOSupported)
check_ipo_supported(RESULT IPO_AVAILABLE OUTPUT IPO_ERROR)
if (IPO_AVAILABLE)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION True)
if (CMAKE_COMPILER_IS_GNUCXX)
message(STATUS "Enabling all link time optimizations")
add_definitions(-fuse-linker-plugin)
add_definitions(-Wformat-truncation=2 -Wformat-signedness -Wformat-overflow=2)
else()
message(STATUS "Disabling linker plugin for link time optimization")
endif()
else()
message(STATUS "IPO/LTO not supported: <${IPO_ERROR}>")
endif()
else()
message(STATUS "Not enabling IPO/LTO")
endif()
if (VC_STATIC)
message(STATUS "Static build with MSVC")
set(CMAKE_CXX_FLAGS_RELEASE "/MT /O2 /Ob2 /DNDEBUG")
set(CMAKE_C_FLAGS_RELEASE "/MT /O2 /Ob2 /DNDEBUG")
endif()
#find_package(SDL2 REQUIRED)
if (CMAKE_BUILD_TYPE MATCHES Debug)
add_definitions(-DDEBUG)
find_program(
CLANG_TIDY_EXE
NAMES "clang-tidy"
DOC "Path to clang-tidy executable"
)
if(NOT CLANG_TIDY_EXE)
message(STATUS "clang-tidy not found.")
else()
message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}")
set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}")
endif()
endif()
find_program(BUILDCACHE_PROGRAM buildcache)
if(BUILDCACHE_PROGRAM)
message(STATUS "Using buildcache: ${BUILDCACHE_PROGRAM}")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${BUILDCACHE_PROGRAM}")
endif()
option(ENABLE_SANITIZERS "Enable runtime sanitizing (for development)")
if (ENABLE_SANITIZERS)
message("Enabling asan and ubsan")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
endif()
##################
## Dependencies ##
##################
if(WIN32)
include_directories(src/extern/genieutils/extern/win-iconv/)
add_definitions(-DNTDDI_VERSION=NTDDI_WINBLUE)
endif()
if(MSVC)
add_definitions(/D_USE_MATH_DEFINES)
add_definitions(/wd4244 /wd4018 /wd4267 /wd4996 /wd4305 /wd4800 /wd4065)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /fp:fast")
find_package(BZip2)
find_package(ZLIB)
find_package(PNG)
set(EXTRA_LIBS PNG::PNG ZLIB::ZLIB BZip2::BZip2)
else()
# We're not doing rocket surgery so let's get some fast yolo math.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffast-math")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -Wno-sign-compare -Wno-unused-parameter")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O2")
set(CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT} -O2")
set(EXTRA_LIBS pthread dl)
# Somehow need this because otherwise the SFML config gets fucked
find_package(ZLIB)
endif()
find_package(SFML COMPONENTS system window graphics REQUIRED)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_definitions(-Wno-nested-anon-types)
endif()
# TODO: proper find_packages
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/extern/miniaudio/miniaudio.h)
message(STATUS "Using bundled miniaudio")
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/extern/)
endif()
# TODO: proper find_packages
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/extern/genieutils/include/genie/Types.h)
message(STATUS "Using bundled genieutils")
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/extern/genieutils/include/)
set(GUTILS_STATIC True)
add_subdirectory(src/extern/genieutils)
endif()
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/extern/tinysoundfont)
message(STATUS "Using bundled tinysoundfont")
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/extern/tinysoundfont)
endif()
include_directories(
src/
src/extern/
${PROJECT_BINARY_DIR}
)
# Because we want to support msvc we can't use the standard funny linker or incbin tricks
add_subdirectory(src/tools/resgen)
# Fonts
add_resource(FONT_ALEGREYA misc/fonts/Alegreya/Alegreya-Bold.latin)
add_resource(FONT_BERRYROTUNDA misc/fonts/BerryRotunda/BerryRotunda.ttf)
add_resource(FONT_CHARIS misc/fonts/charis/CharisSILEur-R.ttf)
# Images
add_resource(IMAGE_PARCHMENT misc/images/parchment.jpg)
# Soundfont (for midi playback)
add_resource(SOUNDFONT_WT_181K_G misc/soundfont/wt_181k_g/wt_181k_G.sf2)
set(AI_SRC
src/ai/grammar.gen.tab.cpp
src/ai/grammar.gen.tab.hpp
src/ai/lex.yy.cc
src/ai/AiRule.cpp
src/ai/AiRule.h
src/ai/AiScript.cpp
src/ai/AiScript.h
src/ai/ScriptLoader.cpp
src/ai/ScriptLoader.h
src/ai/actions/Actions.cpp
src/ai/actions/Actions.h
src/ai/conditions/Conditions.cpp
src/ai/conditions/Conditions.h
src/ai/Ids.cpp
src/ai/Ids.h
src/ai/AiPlayer.cpp
src/ai/AiPlayer.h
src/ai/EnumLogDefs.h
src/ai/location.hh
src/ai/ScriptTokenizer.h
src/ai/gen/enums.h
)
set(CORE_SRC
src/core/Logger.cpp
src/core/Logger.h
src/core/Utility.cpp
src/core/Utility.h
src/core/SignalEmitter.cpp
src/core/SignalEmitter.h
)
set(GLOBAL_SRC
src/global/Config.cpp
src/global/Config.h
src/global/EventManager.cpp
src/global/EventManager.h
src/global/EventListener.cpp
src/global/EventListener.h
)
set(RESOURCE_SRC
src/resource/DataManager.cpp
src/resource/DataManager.h
src/resource/Sprite.cpp
src/resource/Sprite.h
src/resource/LanguageManager.cpp
src/resource/LanguageManager.h
src/resource/Resource.cpp
src/resource/Resource.h
src/resource/AssetManager.cpp
src/resource/AssetManager.h
src/resource/AssetManager_HD.h
src/resource/TerrainSprite.cpp
src/resource/TerrainSprite.h
src/resource/GameSpecific.cpp
src/resource/GameSpecific.h
)
set(MECHANICS_SRC
src/mechanics/Entity.cpp
src/mechanics/Entity.h
src/mechanics/Civilization.cpp
src/mechanics/Civilization.h
src/mechanics/Farm.cpp
src/mechanics/Farm.h
src/mechanics/GameState.cpp
src/mechanics/GameState.h
src/mechanics/Map.cpp
src/mechanics/Map.h
src/mechanics/Player.cpp
src/mechanics/Player.h
src/mechanics/StateManager.cpp
src/mechanics/StateManager.h
src/mechanics/UnitActionHandler.cpp
src/mechanics/UnitActionHandler.h
src/mechanics/UnitFactory.cpp
src/mechanics/UnitFactory.h
src/mechanics/UnitManager.cpp
src/mechanics/UnitManager.h
src/mechanics/Unit.cpp
src/mechanics/Unit.h
src/mechanics/Missile.cpp
src/mechanics/Missile.h
src/mechanics/MapTile.cpp
src/mechanics/MapTile.h
src/mechanics/Building.cpp
src/mechanics/Building.h
src/mechanics/ScenarioController.cpp
src/mechanics/ScenarioController.h
)
set(ACTIONS_SRC
src/actions/IAction.cpp
src/actions/IAction.h
src/actions/ActionAttack.cpp
src/actions/ActionAttack.h
src/actions/ActionBuild.cpp
src/actions/ActionBuild.h
src/actions/ActionGather.cpp
src/actions/ActionGather.h
src/actions/ActionMove.cpp
src/actions/ActionMove.h
src/actions/ActionFly.cpp
src/actions/ActionFly.h
src/actions/ActionGarrison.cpp
src/actions/ActionGarrison.h
)
set(RENDER_SRC
src/render/Camera.cpp
src/render/Camera.h
src/render/GraphicRender.cpp
src/render/GraphicRender.h
src/render/IRenderer.cpp
src/render/IRenderer.h
src/render/IRenderTarget.cpp
src/render/IRenderTarget.h
src/render/MapRenderer.cpp
src/render/MapRenderer.h
src/render/SfmlRenderTarget.cpp
src/render/SfmlRenderTarget.h
src/render/UnitsRenderer.cpp
src/render/UnitsRenderer.h
)
set(SERVER_SRC
src/server/GameServer.cpp
)
set(SETTINGS_SRC
src/settings/input.cpp
)
set(COMMUNICATION_SRC
src/client/GameClient.cpp
src/client/GameClient.h
src/communication/TunnelToClient.cpp
src/communication/TunnelToClient.h
src/communication/TunnelToServer.cpp
src/communication/TunnelToServer.h
src/communication/UnitStatus.cpp
src/communication/UnitStatus.h
src/communication/commands/CommandMove.cpp
src/communication/commands/CommandMove.h
src/communication/commands/CommandSpawn.cpp
src/communication/commands/CommandSpawn.h
src/communication/tunnels/LocalTunnelToClient.cpp
src/communication/tunnels/LocalTunnelToClient.h
src/communication/tunnels/LocalunnelToServer.cpp
src/communication/tunnels/LocalunnelToServer.h
)
set(UNSORTED_SRC
src/audio/AudioPlayer.cpp
src/audio/AudioPlayer.h
src/audio/sts_mixer.cpp
src/audio/sts_mixer.h
src/audio/Implementations.cpp
)
set (UI_SRC
src/ui/ActionPanel.cpp
src/ui/ActionPanel.h
src/ui/FileDialog.cpp
src/ui/FileDialog.h
src/ui/UnitInfoPanel.cpp
src/ui/UnitInfoPanel.h
src/ui/HomeScreen.cpp
src/ui/HomeScreen.h
src/ui/HistoryScreen.cpp
src/ui/HistoryScreen.h
src/ui/UiScreen.cpp
src/ui/UiScreen.h
src/ui/TextButton.cpp
src/ui/TextButton.h
src/ui/Minimap.cpp
src/ui/Minimap.h
src/ui/Dialog.cpp
src/ui/Dialog.h
src/ui/NumberLabel.cpp
src/ui/NumberLabel.h
src/ui/MouseCursor.cpp
src/ui/MouseCursor.h
src/ui/IconButton.cpp
src/ui/IconButton.h
${IMAGE_PARCHMENT}
)
set (EDITOR_SRC
src/editor/Editor.cpp
src/editor/Editor.h
)
set(DEBUG_SRC
src/debug/AllunitsGameSample.cpp
src/debug/AllunitsGameSample.h
src/debug/BasicGameSample.cpp
src/debug/BasicGameSample.h
src/debug/SampleGameFactory.cpp
src/debug/SampleGameFactory.h
)
set(ENGINE_SRC
src/Engine.cpp
src/Engine.h
${CORE_SRC}
${AI_SRC}
${RESOURCE_SRC}
${GLOBAL_SRC}
${MECHANICS_SRC}
${ACTIONS_SRC}
${RENDER_SRC}
${UNSORTED_SRC}
${UI_SRC}
${FONT_ALEGREYA}
${FONT_BERRYROTUNDA}
${FONT_CHARIS}
${SOUNDFONT_WT_181K_G}
${SETTINGS_SRC}
${DEBUG_SRC}
${EDITOR_SRC}
)
set(ALL_LIBRARIES
sfml-system
sfml-window
sfml-graphics
genieutils
${EXTRA_LIBS}
# SDL2::SDL2
# SDL2::SDL2main
)
add_library(freeaoe_common OBJECT ${ENGINE_SRC})
target_link_libraries(freeaoe_common ${ALL_LIBRARIES})
#add_executable(freeaoe src/main.cpp ${ENGINE_SRC})
add_executable(freeaoe src/main.cpp $<TARGET_OBJECTS:freeaoe_common>)
target_link_libraries(freeaoe ${ALL_LIBRARIES})
install(TARGETS freeaoe DESTINATION bin)
if (BUILD_TESTS)
add_executable(test src/test/main.cpp $<TARGET_OBJECTS:freeaoe_common>)
target_link_libraries(test ${ALL_LIBRARIES})
add_executable(ai-test src/test/ai-test.cpp $<TARGET_OBJECTS:freeaoe_common>)
target_link_libraries(ai-test ${ALL_LIBRARIES})
endif()
if (ENABLE_SANITIZERS)
# these are way too big and complex for the sanitizers
set_source_files_properties(src/ai/grammar.gen.tab.cpp PROPERTIES COMPILE_FLAGS -fno-sanitize=all)
set_source_files_properties(src/ai/lex.yy.cc PROPERTIES COMPILE_FLAGS -fno-sanitize=all)
endif()
#if (CMAKE_BUILD_TYPE MATCHES Debug)
# if(CLANG_TIDY_EXE)
# set_target_properties(
# freeaoe PROPERTIES
# CXX_CLANG_TIDY "${DO_CLANG_TIDY}"
# )
# endif()
#endif()