forked from BeamMP/BeamMP-Server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
262 lines (223 loc) · 7.9 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
# 3.4 is required for imported targets.
cmake_minimum_required(VERSION 3.4 FATAL_ERROR)
message(STATUS "You can find build instructions and a list of dependencies in the README at \
https://github.com/BeamMP/BeamMP-Server")
project(BeamMP-Server
DESCRIPTION "Server for BeamMP - The Multiplayer Mod for BeamNG.drive"
HOMEPAGE_URL https://beammp.com
LANGUAGES CXX C)
find_package(Git REQUIRED)
# Update submodules as needed
option(GIT_SUBMODULE "Check submodules during build" ON)
if(GIT_SUBMODULE)
message(STATUS "Submodule update")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
endif()
endif()
set(HTTPLIB_REQUIRE_OPENSSL ON)
set(SENTRY_BUILD_SHARED_LIBS OFF)
add_compile_definitions(CPPHTTPLIB_OPENSSL_SUPPORT=1)
option(WIN32_STATIC_RUNTIME "Build statically-linked runtime on windows (don't touch unless you know what you're doing)" ON)
# ------------------------ APPLE ---------------------------------
if(APPLE)
if(IS_DIRECTORY /opt/homebrew/Cellar/[email protected]/5.3.6)
set(LUA_INCLUDE_DIR /opt/homebrew/Cellar/[email protected]/5.3.6/include/lua5.3)
link_directories(/opt/homebrew/Cellar/[email protected]/5.3.6/lib)
else()
set(LUA_INCLUDE_DIR /usr/local/Cellar/[email protected]/5.3.6/include/lua5.3)
link_directories(/usr/local/Cellar/[email protected]/5.3.6/lib)
endif()
set(LUA_LIBRARIES lua)
if(IS_DIRECTORY /opt/homebrew/opt/[email protected])
include_directories(/opt/homebrew/opt/[email protected]/include)
link_directories(/opt/homebrew/opt/[email protected]/lib)
else()
include_directories(/usr/local/opt/[email protected]/include)
link_directories(/usr/local/opt/[email protected]/lib)
endif()
# ------------------------ WINDOWS ---------------------------------
elseif (WIN32)
if (WIN32_STATIC_RUNTIME)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
# ------------------------ UNIX ------------------------------------
elseif (UNIX)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
option(SANITIZE "Turns on thread and UB sanitizers" OFF)
if (SANITIZE)
message(STATUS "sanitize is ON")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize={address,thread,undefined}")
endif (SANITIZE)
endif ()
set(BUILD_SHARED_LIBS OFF)
# ------------------------ SENTRY ---------------------------------
message(STATUS "Checking for Sentry URL")
# this is set by the build system.
# IMPORTANT: if you're building from source, just leave this empty
if (NOT DEFINED BEAMMP_SECRET_SENTRY_URL)
message(WARNING "No sentry URL configured. Sentry logging is disabled for this build. \
This is not an error, and if you're building the BeamMP-Server yourself, this is expected and can be ignored.")
set(BEAMMP_SECRET_SENTRY_URL "")
set(SENTRY_BACKEND none)
else()
set(SENTRY_BACKEND breakpad)
endif()
add_subdirectory("deps/sentry-native")
# ------------------------ C++ SETUP ---------------------------------
set(CMAKE_CXX_STANDARD 17)
# ------------------------ DEPENDENCIES ------------------------------
message(STATUS "Adding local source dependencies")
# this has to happen before -DDEBUG since it wont compile properly with -DDEBUG
add_subdirectory(deps)
# ------------------------ VARIABLES ---------------------------------
include(FindLua)
include(FindOpenSSL)
include(FindThreads)
include(FindZLIB)
find_package(Boost 1.70 REQUIRED COMPONENTS system)
set(BeamMP_Sources
include/TConsole.h src/TConsole.cpp
include/TServer.h src/TServer.cpp
include/Compat.h src/Compat.cpp
include/Common.h src/Common.cpp
include/Client.h src/Client.cpp
include/VehicleData.h src/VehicleData.cpp
include/TConfig.h src/TConfig.cpp
include/TLuaEngine.h src/TLuaEngine.cpp
include/TLuaPlugin.h src/TLuaPlugin.cpp
include/TResourceManager.h src/TResourceManager.cpp
include/THeartbeatThread.h src/THeartbeatThread.cpp
include/Http.h src/Http.cpp
include/TSentry.h src/TSentry.cpp
include/TPPSMonitor.h src/TPPSMonitor.cpp
include/TNetwork.h src/TNetwork.cpp
include/LuaAPI.h src/LuaAPI.cpp
include/TScopedTimer.h src/TScopedTimer.cpp
include/SignalHandling.h src/SignalHandling.cpp
include/ArgsParser.h src/ArgsParser.cpp
include/TPluginMonitor.h src/TPluginMonitor.cpp
include/Environment.h
include/BoostAliases.h
)
set(BeamMP_Includes
${LUA_INCLUDE_DIR}
${CURL_INCLUDE_DIRS}
"${CMAKE_CURRENT_SOURCE_DIR}/deps/cpp-httplib"
"${CMAKE_CURRENT_SOURCE_DIR}/deps/commandline"
"${CMAKE_CURRENT_SOURCE_DIR}/deps/json/single_include"
"${CMAKE_CURRENT_SOURCE_DIR}/deps/sol2/include"
"${CMAKE_CURRENT_SOURCE_DIR}/deps/rapidjson/include"
"${CMAKE_CURRENT_SOURCE_DIR}/deps/asio/asio/include"
"${CMAKE_CURRENT_SOURCE_DIR}/deps"
)
set(BeamMP_Definitions
SECRET_SENTRY_URL="${BEAMMP_SECRET_SENTRY_URL}"
)
if (WIN32)
list(APPEND BeamMP_Definitions _WIN32_WINNT=0x0601)
list(APPEND BeamMP_Definitions _CRT_SECURE_NO_WARNINGS)
endif()
if (UNIX)
set(BeamMP_CompileOptions
-Wall
-Wextra
-Wpedantic
-Werror=uninitialized
-Werror=float-equal
-Werror=pointer-arith
-Werror=double-promotion
-Werror=write-strings
-Werror=cast-qual
-Werror=init-self
-Werror=cast-align
-Werror=unreachable-code
-Werror=strict-aliasing -fstrict-aliasing
-Werror=redundant-decls
-Werror=missing-declarations
-Werror=missing-field-initializers
-Werror=write-strings
-Werror=ctor-dtor-privacy
-Werror=switch-enum
-Werror=switch-default
-Werror=old-style-cast
-Werror=overloaded-virtual
-Werror=overloaded-virtual
-Werror=missing-include-dirs
-Werror=unused-result
-fstack-protector
-Wzero-as-null-pointer-constant
)
else()
set(BeamMP_CompileOptions
/bigobj
/INCREMENTAL:NO /NODEFAULTLIB:MSVCRT /NODEFAULTLIB:LIBCMT
)
endif()
set(BeamMP_Libraries
Boost::boost
Boost::system
doctest::doctest
OpenSSL::SSL
OpenSSL::Crypto
sol2::sol2
fmt::fmt
Threads::Threads
ZLIB::ZLIB
${LUA_LIBRARIES}
commandline
sentry
)
if (WIN32)
set(BeamMP_PlatformLibs wsock32 ws2_32)
endif ()
# ------------------------ BEAMMP SERVER -----------------------------
add_executable(BeamMP-Server
src/main.cpp
${BeamMP_Sources}
)
target_compile_definitions(BeamMP-Server PRIVATE
${BeamMP_Definitions}
DOCTEST_CONFIG_DISABLE
)
target_compile_options(BeamMP-Server PRIVATE
${BeamMP_CompileOptions}
)
target_include_directories(BeamMP-Server PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/include"
)
target_include_directories(BeamMP-Server SYSTEM PRIVATE
${BeamMP_Includes}
)
target_link_libraries(BeamMP-Server
${BeamMP_Libraries}
${BeamMP_PlatformLibs}
)
# ------------------------ BEAMMP SERVER TESTS -----------------------
option(BUILD_TESTS "Build BeamMP-Server tests" ON)
if(BUILD_TESTS)
add_executable(BeamMP-Server-tests
test/test_main.cpp
${BeamMP_Sources}
)
target_compile_definitions(BeamMP-Server-tests PRIVATE
${BeamMP_Definitions}
)
target_compile_options(BeamMP-Server-tests PRIVATE
${BeamMP_CompileOptions}
)
target_include_directories(BeamMP-Server-tests PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/include"
)
target_include_directories(BeamMP-Server-tests SYSTEM PRIVATE
${BeamMP_Includes}
)
target_link_libraries(BeamMP-Server-tests
${BeamMP_Libraries}
${BeamMP_PlatformLibs}
)
endif()