-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathCMakeLists.txt
324 lines (273 loc) · 8.73 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
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()
set (CMAKE_CXX_STANDARD 20)
set(CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
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)
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(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(SFML 2.5 CONFIG COMPONENTS system window graphics REQUIRED)
find_package(BZip2)
find_package(ZLIB)
find_package(PNG)
set(EXTRA_LIBS PNG::PNG ZLIB::ZLIB BZip2::BZip2)
else()
add_definitions(-fno-math-errno)
if (NOT CMAKE_BUILD_TYPE MATCHES Debug)
# clang gets undefined references to builtin exp, log, etc. with -ffinite-math-only/-fno-honor-infinities, so we do this the hard way
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -funsafe-math-optimizations -fno-honor-nans -fassociative-math -freciprocal-math -fno-signed-zeros -fno-trapping-math -ffp-contract=fast")
add_definitions(-D__FAST_MATH__)
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffast-math")
endif()
#string(REPLACE "-O3" "-Ofast" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
endif()
add_definitions(-Wall -Wextra -pedantic -Wno-sign-compare -Wno-unused-parameter)
set(EXTRA_LIBS stdc++fs pthread dl)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/)
# Somehow need this because otherwise the SFML config gets fucked
find_package(ZLIB)
find_package(SFML COMPONENTS system window graphics REQUIRED)
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_definitions(-Wno-nested-anon-types)
endif()
# TODO: proper find_packages
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/extern/miniaudio/miniaudio.h)
message(STATUS "Using bundled miniaudio")
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/extern/)
endif()
# TODO: proper find_packages
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/extern/genieutils/include/genie/Types.h)
message(STATUS "Using bundled genieutils")
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/extern/genieutils/include/)
set(GUTILS_STATIC True)
add_subdirectory(extern/genieutils)
endif()
include_directories(
src/
extern/
${PROJECT_BINARY_DIR}
)
add_subdirectory(tools/resgen)
add_resource(FONT_ALEGREYA fonts/Alegreya/Alegreya-Bold.latin)
add_resource(FONT_BERRYROTUNDA fonts/BerryRotunda/BerryRotunda.ttf)
set(AI_SRC
src/ai/grammar.gen.tab.cpp
src/ai/lex.yy.cc
src/ai/AiRule.cpp
src/ai/AiScript.cpp
src/ai/ScriptLoader.cpp
src/ai/actions/Actions.cpp
src/ai/conditions/Conditions.cpp
)
set(CORE_SRC
src/core/Logger.cpp
src/core/Utility.cpp
)
set(GLOBAL_SRC
src/global/Config.cpp
src/global/EventManager.cpp
src/global/EventListener.cpp
)
set(RESOURCE_SRC
src/resource/DataManager.cpp
src/resource/Graphic.cpp
src/resource/LanguageManager.cpp
src/resource/Resource.cpp
src/resource/AssetManager.cpp
src/resource/TerrainSprite.cpp
)
set(MECHANICS_SRC
src/mechanics/Entity.cpp
src/mechanics/Civilization.cpp
src/mechanics/Farm.cpp
src/mechanics/GameState.cpp
src/mechanics/Map.cpp
src/mechanics/Player.cpp
src/mechanics/StateManager.cpp
src/mechanics/UnitActionHandler.cpp
src/mechanics/UnitFactory.cpp
src/mechanics/UnitManager.cpp
src/mechanics/Unit.cpp
src/mechanics/Missile.cpp
src/mechanics/MapTile.cpp
src/mechanics/Building.cpp
src/mechanics/ScenarioController.cpp
)
set(ACTIONS_SRC
src/actions/IAction.cpp
src/actions/ActionAttack.cpp
src/actions/ActionBuild.cpp
src/actions/ActionGather.cpp
src/actions/ActionMove.cpp
src/actions/ActionFly.cpp
)
set(RENDER_SRC
src/render/Camera.cpp
src/render/GraphicRender.cpp
src/render/IRenderer.cpp
src/render/IRenderTarget.cpp
src/render/MapRenderer.cpp
src/render/SfmlRenderTarget.cpp
)
set(SERVER_SRC
src/server/GameServer.cpp
)
set(SETTINGS_SRC
src/settings/input.cpp
)
set(COMMUNICATION_SRC
src/client/GameClient.cpp
src/communication/TunnelToClient.cpp
src/communication/TunnelToServer.cpp
src/communication/UnitStatus.cpp
src/communication/commands/CommandMove.cpp
src/communication/commands/CommandSpawn.cpp
src/communication/tunnels/LocalTunnelToClient.cpp
src/communication/tunnels/LocalunnelToServer.cpp
)
set(UNSORTED_SRC
src/audio/AudioPlayer.cpp
src/audio/sts_mixer.cpp
src/audio/Implementations.cpp
)
set (UI_SRC
src/ui/ActionPanel.cpp
src/ui/FileDialog.cpp
src/ui/UnitInfoPanel.cpp
src/ui/HomeScreen.cpp
src/ui/HistoryScreen.cpp
src/ui/UiScreen.cpp
src/ui/TextButton.cpp
src/ui/Minimap.cpp
src/ui/Dialog.cpp
src/ui/NumberLabel.cpp
src/ui/MouseCursor.cpp
src/ui/IconButton.cpp
)
set (EDITOR_SRC
src/editor/Editor.cpp
)
set(DEBUG_SRC
src/debug/AllunitsGameSample.cpp
src/debug/BasicGameSample.cpp
src/debug/SampleGameFactory.cpp
)
set(ENGINE_SRC
src/Engine.cpp
${CORE_SRC}
${AI_SRC}
${RESOURCE_SRC}
${GLOBAL_SRC}
${MECHANICS_SRC}
${ACTIONS_SRC}
${RENDER_SRC}
${UNSORTED_SRC}
${UI_SRC}
${FONT_ALEGREYA}
${FONT_BERRYROTUNDA}
${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)
add_executable(test test/main.cpp $<TARGET_OBJECTS:freeaoe_common>)
target_link_libraries(test ${ALL_LIBRARIES})
add_executable(ai-test test/ai-test.cpp $<TARGET_OBJECTS:freeaoe_common>)
target_link_libraries(ai-test ${ALL_LIBRARIES})
if (ENABLE_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()