-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
405 lines (328 loc) · 7.24 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
cmake_minimum_required(VERSION 2.6)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
##########################
# Project definition
##########################
project(batajelo)
set(batajelo_VERSION_MAJOR 0)
set(batajelo_VERSION_MINOR 1)
##########################
# Project compile flags
##########################
# This flag is very important for the fixmath library, if one client is
# compiled without it, its world representation may not be identical with
# the other’s one.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFIXMATH_SIN_LUT")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -pedantic -Wall -Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y -pedantic -Wall -Wextra -Weffc++")
configure_file("${PROJECT_SOURCE_DIR}/src/config.hpp.in" "${PROJECT_SOURCE_DIR}/src/config.hpp")
##########################
# Command line options
##########################
set(BUILD_SERVER true)
option(BUILD_SERVER "build the server" ${BUILD_SERVER})
set(BUILD_CLIENT true)
option(BUILD_CLIENT "build the server" ${BUILD_CLIENT})
##########################
# Libraries look up
##########################
find_package(Boost 1.48.0 COMPONENTS filesystem system iostreams locale serialization chrono program_options REQUIRED)
find_package(BOTAN REQUIRED)
find_package(Protobuf REQUIRED)
find_package(LITESQL REQUIRED)
find_package(WEBSOCKETPP REQUIRED)
find_package(OpenSSL REQUIRED)
if(BUILD_CLIENT)
find_package(SFML 2 REQUIRED system window graphics audio)
endif()
##########################
# Includes and Linkage
##########################
include_directories("src/")
include_directories(${Boost_INCLUDE_DIR})
include_directories(${OPENSSL_INCLUDE_DIR})
include_directories(${BOTAN_INCLUDE_DIRS})
include_directories(${PROTOBUF_INCLUDE_DIRS})
include_directories(${WEBSOCKETPP_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
##########################
# Targets
##########################
if(BUILD_CLIENT)
add_executable(batajelo_client src/main/batajelo_client.cpp)
target_link_libraries(batajelo_client
game_client
network
gui
)
add_executable(batajelo_menu_client src/main/batajelo_menu_client.cpp)
target_link_libraries(batajelo_menu_client
menu_client
)
endif()
if(BUILD_SERVER)
add_executable(batajelo_game_server src/main/batajelo_game_server.cpp)
target_link_libraries(batajelo_game_server
game_server
)
add_executable(batajelo_master_server src/main/batajelo_master_server.cpp)
target_link_libraries(batajelo_master_server
network
master_server
)
add_executable(batajelo_slave src/main/batajelo_slave.cpp)
target_link_libraries(batajelo_slave
slave
)
endif(BUILD_SERVER)
#########################
# Project libraries
#########################
#
## Config
#
file(GLOB source_config
src/config/config.[hc]pp
)
add_library(config STATIC ${source_config})
target_link_libraries(config
utils
)
#
## Logging
#
file(GLOB source_logging
src/logging/logging.[hc]pp
)
add_library(logging STATIC ${source_logging})
target_link_libraries(logging
config
${Boost_LIBRARIES}
)
#
## fixmath
#
file(GLOB source_fixmath
src/fixmath/*.c
src/fixmath/*.cpp
)
add_library(fixmath STATIC ${source_fixmath})
#
## Utils
#
file(GLOB source_utils
src/utils/*.[hc]pp
)
add_library(utils STATIC ${source_utils})
target_link_libraries(
utils
${Boost_LIBRARIES}
)
#
## Assets
#
file(GLOB source_assets
src/assets/*.[hc]pp
)
add_library(assets STATIC ${source_assets})
target_link_libraries(assets
${Boost_LIBRARIES}
)
#
## Database
#
LITESQL_GENERATE_CPP("src/database/database.xml"
"batadb"
LITESQL_GENERATED_SOURCES)
add_library(database STATIC src/database/database.cpp
${LITESQL_GENERATED_SOURCES})
target_link_libraries(database ${LITESQL_LIBRARIES} ${BOTAN_LIBRARIES})
#
## Gui
#
if(BUILD_CLIENT)
file(GLOB source_gui
src/gui/*.[hc]pp
src/gui/camera/*.[hc]pp
src/gui/screen/*.[hc]pp
src/gui/hud/*.[hc]pp
src/gui/sprites/*.[hc]pp
)
add_library(gui STATIC ${source_gui})
target_Link_libraries(gui
logging
config
world
utils
assets
${SFML_LIBRARIES}
${Boost_LIBRARIES}
)
endif()
#
## World
#
file(GLOB source_world
src/world/*.[hc]pp
src/world/abilities/*.[hc]pp
src/world/tasks/*.[hc]pp
src/world/works/*.[hc]pp
src/world/status/*.[hc]pp
)
add_library(world STATIC ${source_world})
target_Link_libraries(world
assets
logging
serialization
fixmath
utils
${Boost_LIBRARIES}
)
#
## Serialization
#
file(GLOB proto_files
src/proto/*.proto
)
PROTOBUF_GENERATE_CPP(PROTO_SRC PROTO_HDRS ${proto_files})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_library(serialization STATIC ${PROTO_SRC})
target_link_libraries(serialization ${PROTOBUF_LIBRARIES})
#
## Network
#
file(GLOB source_network
src/network/*.[ch]pp
)
add_library(network STATIC ${source_network})
target_link_libraries(network
${Boost_LIBRARIES}
${OPENSSL_LIBRARIES}
logging
config
${OPENSSL_LIBRARIES}
)
#
## Master Server
#
file(GLOB source_master_server
src/master_server/*.[ch]pp
)
add_library(master_server STATIC ${source_master_server})
target_link_libraries(master_server
serialization
utils
logging
network
config
database
)
#
## Slave
#
file(GLOB source_slave
src/slave/*.[ch]pp
)
add_library(slave STATIC ${source_slave})
target_link_libraries(slave
serialization
utils
logging
network
config
"rt" #for mq_*
)
#
## Menu Client
#
file(GLOB source_menu_client
src/menu_client/*.[ch]pp
)
add_library(menu_client STATIC ${source_menu_client})
target_link_libraries(menu_client
network
utils
logging
config
serialization
gui
)
#
## Game
#
file(GLOB source_game
src/game/game.[ch]pp
src/game/occupant.[ch]pp
src/game/occupants_handler.[ch]pp
src/game/remote_game_client.[ch]pp
src/game/replay.[ch]pp
src/game/time.[ch]pp
src/game/turn.[ch]pp
src/game/turn_handler.[ch]pp
)
add_library(game STATIC ${source_game})
target_link_libraries(game
serialization
logging
config
world
)
#
## Game client
#
file(GLOB source_game_client
src/game/game_client.[ch]pp
src/game/sounds_handler.[ch]pp
src/game/sound.[ch]pp
src/game/selection.[ch]pp
)
add_library(game_client STATIC ${source_game_client})
target_link_libraries(game_client
game
gui
network
)
#
## Game server
#
file(GLOB source_game_server
src/game/game_server.[ch]pp
)
add_library(game_server STATIC ${source_game_server})
target_link_libraries(game_server
game
network
"rt"
)
####################
# Tests
####################
find_package(CATCH)
if(CATCH_FOUND)
file(GLOB source_tests
tests/*.cpp)
add_executable(test_suite EXCLUDE_FROM_ALL
${source_tests})
target_link_libraries(test_suite
config
network
fixmath
world
master_server
game)
target_include_directories(test_suite
PUBLIC ${CATCH_INCLUDE_DIRS})
target_include_directories(test_suite
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/tests)
add_custom_target(check COMMAND "test_suite"
DEPENDS test_suite)
#
## Code coverage
#
if(CMAKE_BUILD_TYPE MATCHES Debug)
include(CodeCoverage)
setup_target_for_coverage(coverage
test_suite
coverage)
endif()
endif(CATCH_FOUND)