-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCMakeLists.txt
280 lines (241 loc) · 7.54 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
#LAST CMAKE DE NIKO
cmake_minimum_required(VERSION 3.10)
project(tp_final LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
# compilation flags
set(CXXSTD c++17)
add_definitions(-DDATA_PATH="${PROJECT_SOURCE_DIR}/data")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -pedantic -pedantic-errors -O0 -ggdb -DDEBUG -fno-inline -std=${CXXSTD} -D _POSIX_C_SOURCE=200809L")
# find_package(SDL2 REQUIRED)
# find_package(SDL2_ttf REQUIRED)
# find_package(SDL2_image REQUIRED)
# find_package(SDL2_mixer REQUIRED)
# find_package(YamlCpp REQUIRED)
option(math "Use math.h" ON)
option(threads "Use threads" ON)
option(static "Static compilation" OFF)
option(TESTS "Build tests" OFF)
if (math)
set(LDFLAGS "${LDFLAGS} -lm")
endif()
if (threads)
set(LDFLAGS "${LDFLAGS} -pthread")
endif()
if (static)
set(LDFLAGS "${LDFLAGS} -static")
endif()
# DEBUGGING
if (LOG)
add_definitions(-DLOG)
endif()
if(LOG_VERBOSE)
add_definitions(-DLOG_VERBOSE)
endif()
if (CHEATS)
add_definitions(-DCHEATS)
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LDFLAGS}")
set(CMAKE_PREFIX_PATH "${SDL2_INCLUDE_DIRS} ${SDL2_ttf_INCLUDE_DIRS} ${SDL2_image_INCLUDE_DIRS} ${SDL2_mixer_INCLUDE_DIRS}")
file(GLOB_RECURSE SOURCES_CLIENT "client/*.cpp" "client/**/*.cpp")
file(GLOB_RECURSE SOURCES_SERVER "server/*.cpp" "sever/**/*.cpp")
file(GLOB_RECURSE SOURCES_COMMON "common/*.cpp" "common/**/*.cpp")
file(GLOB_RECURSE SOURCES_GAME_ENGINE "game_engine/*.cpp" "game_engine/**/*.cpp")
file(GLOB_RECURSE HEADERS_CLIENT "client/*.h" "client/**/*.h")
file(GLOB_RECURSE HEADERS_SERVER "server/*.h" "server/**/*.h")
file(GLOB_RECURSE HEADERS_COMMON "common/*.h" "common/**/*.h")
file(GLOB_RECURSE HEADERS_GAME_ENGINE "game_engine/*.h" "game_engine/**/*.h")
if (PRODUCTION)
add_executable(client
${SOURCES_COMMON}
${SOURCES_CLIENT}
${HEADERS_CLIENT}
${HEADERS_COMMON}
${SOURCES_GAME_ENGINE}
${HEADERS_GAME_ENGINE}
)
add_executable(server
${SOURCES_COMMON}
${SOURCES_SERVER}
${HEADERS_SERVER}
${HEADERS_COMMON}
${SOURCES_GAME_ENGINE}
${HEADERS_GAME_ENGINE}
)
target_link_libraries(client
SDL2main
SDL2
SDL2_image
SDL2_ttf
SDL2_mixer
yaml-cpp
)
target_link_libraries(server
SDL2main
SDL2
SDL2_image
SDL2_ttf
SDL2_mixer
yaml-cpp
)
endif()
# COMMUNICATION - TESTS
if (EVENTS)
file(GLOB_RECURSE SOURCES_CLIENT_PROTOCOL "client/protocol/*.cpp")
file(GLOB_RECURSE SOURCES_SERVER_PROTOCOL "server/protocol/*.cpp")
file(GLOB_RECURSE SOURCES_SERVER_GAME_LOGIC "server/game_logic/*.cpp")
add_executable(client_test_one tests/events/client_to_server/client_main.cpp
${SOURCES_COMMON}
${SOURCES_CLIENT_PROTOCOL}
${SOURCES_SERVER_PROTOCOL}
${SOURCES_SERVER_GAME_LOGIC}
${HEADERS_CLIENT}
${HEADERS_SERVER}
${HEADERS_COMMON}
${SOURCES_GAME_ENGINE}
${HEADERS_GAME_ENGINE}
)
target_link_libraries(client_test_one
SDL2main
SDL2
SDL2_image
SDL2_ttf
SDL2_mixer
yaml-cpp
)
add_executable(server_test_one tests/events/client_to_server/server_main.cpp
${SOURCES_COMMON}
${SOURCES_CLIENT_PROTOCOL}
${SOURCES_SERVER_PROTOCOL}
${SOURCES_SERVER_GAME_LOGIC}
${HEADERS_CLIENT}
${HEADERS_SERVER}
${HEADERS_COMMON}
${SOURCES_GAME_ENGINE}
${HEADERS_GAME_ENGINE}
)
target_link_libraries(server_test_one
SDL2main
SDL2
SDL2_image
SDL2_ttf
SDL2_mixer
yaml-cpp
)
add_executable(client_test_two tests/events/server_to_client/client_main.cpp
${SOURCES_COMMON}
${SOURCES_CLIENT_PROTOCOL}
${SOURCES_SERVER_PROTOCOL}
${SOURCES_SERVER_GAME_LOGIC}
${HEADERS_CLIENT}
${HEADERS_SERVER}
${HEADERS_COMMON}
${SOURCES_GAME_ENGINE}
${HEADERS_GAME_ENGINE}
)
target_link_libraries(client_test_two
SDL2main
SDL2
SDL2_image
SDL2_ttf
SDL2_mixer
yaml-cpp
)
add_executable(server_test_two tests/events/server_to_client/server_main.cpp
${SOURCES_COMMON}
${SOURCES_CLIENT_PROTOCOL}
${SOURCES_SERVER_PROTOCOL}
${SOURCES_SERVER_GAME_LOGIC}
${HEADERS_CLIENT}
${HEADERS_SERVER}
${HEADERS_COMMON}
${SOURCES_GAME_ENGINE}
${HEADERS_GAME_ENGINE}
)
target_link_libraries(server_test_two
SDL2main
SDL2
SDL2_image
SDL2_ttf
SDL2_mixer
yaml-cpp
)
endif()
# GRAPHICS TEST
if (GRAPHICS)
file(GLOB_RECURSE GRAPHIC_TESTS "tests/graphics/*.cpp" "tests/graphics/**/*.cpp")
foreach(file ${GRAPHIC_TESTS})
# Extract the file name without extension to use as the target name
get_filename_component(target_name ${file} NAME_WE)
add_executable(${target_name} ${file} ${SOURCES_GAME_ENGINE} ${HEADERS_GAME_ENGINE})
target_link_libraries(${target_name}
SDL2main
SDL2
SDL2_image
SDL2_ttf
SDL2_mixer
yaml-cpp)
endforeach()
endif()
# GRAPHICS TEST
if (GP_TESTS)
add_executable(GPTEST "tests/graphics/gui_phy_test.cpp"
${HEADERS_GAME_ENGINE}
${SOURCES_GAME_ENGINE}
${SOURCES_COMMON}
${HEADERS_COMMON}
${SERVER_WITHOUT_MAIN})
target_link_libraries(GPTEST SDL2main SDL2 SDL2_image SDL2_ttf SDL2_mixer)
endif()
if(PHYSICS)
find_package(Catch2 REQUIRED)
file(GLOB_RECURSE SOURCES_CLIENT_PROTOCOL "client/protocol/*.cpp")
file(GLOB_RECURSE SOURCES_SERVER_PROTOCOL "server/protocol/*.cpp")
file(GLOB_RECURSE SOURCES_SERVER_GAME_LOGIC "server/game_logic/*.cpp")
add_executable(tests tests/unit_tests/physics_test.cpp
${SOURCES_COMMON}
${SOURCES_GAME_ENGINE}
${HEADERS_COMMON}
${HEADERS_GAME_ENGINE}
${SOURCES_CLIENT_PROTOCOL}
${SOURCES_SERVER_PROTOCOL}
${SOURCES_SERVER_GAME_LOGIC}
${HEADERS_SERVER}
${HEADERS_CLIENT}
)
target_link_libraries(tests PRIVATE
Catch2WithMain
SDL2main
SDL2
SDL2_image
SDL2_ttf
${SOURCES_COMMON}
${SOURCES_GAME_ENGINE}
${HEADERS_COMMON}
${HEADERS_GAME_ENGINE}
${SOURCES_CLIENT_PROTOCOL}
${SOURCES_SERVER_PROTOCOL}
${SOURCES_SERVER_GAME_LOGIC}
${HEADERS_SERVER}
${HEADERS_CLIENT}
)
target_link_libraries(tests PRIVATE
Catch2WithMain
SDL2main
SDL2
SDL2_image
SDL2_ttf
SDL2_mixer
yaml-cpp
)
endif()
if (DEFINED TSAN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread")
add_executable(server-tsan ${SOURCES_SERVER} ${SOURCES_COMMON}
game_engine/physics_engine/collision_manager.h
game_engine/physics_engine/colision_object.h)
endif()
if (verbose)
set(CMAKE_VERBOSE_MAKEFILE ON)
endif()