-
Notifications
You must be signed in to change notification settings - Fork 5
/
CMakeLists.txt
executable file
·262 lines (206 loc) · 8.41 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
# Copyright (C) 2007 <SWGEmu>. All rights reserved.
# Distribution of this file for usage outside of Core3 is prohibited.
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
project(core3 CXX C)
# Set cpp requirements
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
include(CheckCXXSourceCompiles)
include(CheckCXXCompilerFlag)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.4)
message(FATAL_ERROR "GCC version myst be at least 5.4!")
endif()
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4)
message(FATAL_ERROR "Clang version must be at least 3.4!")
endif()
else()
message(WARNING "You are using an unsupported compiler! Compilation has only been tested with Clang and GCC.")
endif()
# Set up options
option(BUILD_IDL "Generate idl c++ sources with cmake" ON)
option(IDL_NOPRELOCKS "Disables all prelock annotations" OFF)
option(ENABLE_CCACHE "Enables ccache search and usage" ON)
option(RUN_GIT "Runs git log to dump last commit messages into rev.txt" OFF)
option(COMPILE_TESTS "Enables mock generation in idlc and test compiling" ON)
option(LOGIN_SERVER_EXTRA_PORTS "Enables login server with extra ports config" OFF)
option(ENABLE_ASAN "Enables address sanitizer compiling" OFF)
option(ENABLE_TSAN "Enables thread sanitizer compiling" OFF)
option(ENABLE_UBSAN "Enables undefined behavior sanitizer compiling" OFF)
option(ENABLE_NATIVE "Enables -march=native compiler option" ON)
option(ENABLE_OMIT_FRAMEPOINTER "Enables -fno-omit-frame-pointer compiler option" ON)
option(ENABLE_ERROR_ON_WARNINGS "Enables -Werror compiler option" ON)
option(ENABLE_REST_SERVER "Enables RESTServer if cpprestsdk is found" OFF)
option(ENABLE_ODB "Enables odb3 compiling" OFF)
option(ENABLE_ODB_REFERENCES "Sets ODB_REFERENCES define" ON) #needs to match engine3
option(ENABLE_BUILD_CLIENT "Enables core3client build" ON)
# Set cmake paths
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
find_package(Git QUIET)
# Add lua includes and libraries
find_package(Lua "5.3" REQUIRED)
include_directories(${LUA_INCLUDE_DIR})
# Find mysql includes and libraries
find_package(MySql REQUIRED)
#include_directories(${MYSQL_INCLUDE_DIR}) already included in find
# Find berkeley includes and libraries
find_package(Berkeley REQUIRED)
include_directories(${DB_INCLUDE_DIR})
find_package(Java 1.5 COMPONENTS Runtime REQUIRED )
# Find engine3 includes and libraries
find_package(Engine3 REQUIRED)
include_directories(${ENGINE3_INCLUDE_DIR})
find_package(OpenSSL REQUIRED)
include_directories(${OPENSSL_INCLUDE_DIR})
find_package(ZLIB REQUIRED)
include_directories(${ZLIB_INCLUDE_DIRS})
# Find and set -pthreads
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost QUIET OPTIONAL_COMPONENTS thread)
function(check_working_cxx_atomics varname)
set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
set(CMAKE_REQUIRED_FLAGS "-std=c++11")
CHECK_CXX_SOURCE_COMPILES("
#include <atomic>
struct test_type { float x[3]; };
std::atomic<test_type> atom;
test_type old;
test_type newval;
int main() {
newval.x[2] = 3;
return atom.compare_exchange_strong(old, newval);
}
" ${varname})
set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
endfunction(check_working_cxx_atomics)
check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB)
if (NOT HAVE_CXX_ATOMICS_WITHOUT_LIB)
find_package(GccAtomic REQUIRED)
endif()
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
endif()
if(ENABLE_CCACHE)
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
message(STATUS "Using ccache")
endif(CCACHE_FOUND)
endif(ENABLE_CCACHE)
if(IDL_NOPRELOCKS)
set(IDL_DIRECTIVES ${IDL_DIRECTIVES} -noprelocks)
endif(IDL_NOPRELOCKS)
# Include googlemock and googletest
if(COMPILE_TESTS)
add_subdirectory(utils/googletest-release-1.8.0/googlemock)
include_directories(${CMAKE_SOURCE_DIR}/utils/googletest-release-1.8.0/googletest/include)
include_directories(${CMAKE_SOURCE_DIR}/utils/googletest-release-1.8.0/googlemock/include)
add_definitions(-DCOMPILE_CORE3_TESTS)
else(COMPILE_TESTS)
set(IDL_DIRECTIVES ${IDL_DIRECTIVES} -nomocks)
endif(COMPILE_TESTS)
if (LOGIN_SERVER_EXTRA_PORTS)
add_definitions(-DUSE_RANDOM_EXTRA_PORTS)
endif(LOGIN_SERVER_EXTRA_PORTS)
include_directories(${CMAKE_SOURCE_DIR}/src)
include_directories(${CMAKE_SOURCE_DIR}/src/autogen)
include_directories(${CMAKE_SOURCE_DIR}/utils)
if (ENABLE_ODB_REFERENCES)
add_definitions(-DODB_REFERENCES)
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# Define global build gcc compatible flags to check and add if available
set(GCCEXTRAFLAGS -Wall
-Wextra
-Wno-unused
-Wno-sign-compare
-Wno-multichar
-Wno-unused-parameter
-Wno-overloaded-virtual
-Wno-missing-declarations
-Wno-return-std-move
-Wno-implicit-fallthrough
-fcolor-diagnostics)
foreach(flag_comp ${GCCEXTRAFLAGS})
CHECK_CXX_COMPILER_FLAG(${flag_comp} CxxFlag${flag_comp})
if (CxxFlag${flag_comp})
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag_comp}")
endif()
endforeach(flag_comp)
if (ENABLE_ERROR_ON_WARNINGS)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
endif(ENABLE_ERROR_ON_WARNINGS)
if (ENABLE_ASAN)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} -fsanitize=address")
message(STATUS "Adress sanitizer enabled")
endif(ENABLE_ASAN)
if (ENABLE_TSAN)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} -fsanitize=thread")
message(STATUS "Thread sanitizer enabled")
endif(ENABLE_TSAN)
if (ENABLE_UBSAN)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} -fsanitize=undefined")
message(STATUS "Undefined behavior sanitizer sanitizer enabled")
endif(ENABLE_UBSAN)
if (ENABLE_NATIVE)
CHECK_CXX_COMPILER_FLAG(-march=native CxxFlagMnative)
if (CxxFlagMnative)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
endif (CxxFlagMnative)
endif(ENABLE_NATIVE)
if (ENABLE_OMIT_FRAMEPOINTER)
CHECK_CXX_COMPILER_FLAG(-fno-omit-frame-pointer CxxFlagFramePointer)
if (CxxFlagFramePointer)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer")
endif (CxxFlagFramePointer)
endif()
endif()
add_definitions(-DDEFAULT_DYNAMIC_CAST)
add_subdirectory(src)
add_subdirectory(src/conf)
add_subdirectory(src/terrain)
add_subdirectory(src/templates)
add_subdirectory(src/pathfinding)
add_subdirectory(src/server/db)
add_subdirectory(src/server/status)
add_subdirectory(src/server/web)
add_subdirectory(src/server/ping)
add_subdirectory(src/server/login)
add_subdirectory(src/server/chat)
if (ENABLE_BUILD_CLIENT)
add_subdirectory(src/client)
endif()
set_source_files_properties(tags PROPERTIES GENERATED true)
add_custom_target(tags
COMMAND ctags -R --fields=+iaS --extra=+q src/
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
set_source_files_properties(compile_commands.json PROPERTIES GENERATED true)
add_custom_target(compdb
COMMAND compdb -p ${CMAKE_BINARY_DIR} list > compile_commands.json
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
add_custom_target(update-engine3
COMMAND ${GIT_EXECUTABLE} submodule update --recursive --remote
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
message(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
#message(STATUS "Compiler flags:" ${CMAKE_CXX_COMPILE_FLAGS})
if (${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo")
message(STATUS "Compiler cxx release with debug flags: " ${CMAKE_CXX_FLAGS_RELWITHDEBINFO})
elseif (${CMAKE_BUILD_TYPE} STREQUAL "Release")
message(STATUS "Compiler cxx release flags: " ${CMAKE_CXX_FLAGS_RELEASE})
elseif (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
message(STATUS "Compiler cxx debug flags: " ${CMAKE_CXX_FLAGS_DEBUG})
endif ()
#message(STATUS "Compiler cxx min size flags:" ${CMAKE_CXX_FLAGS_MINSIZEREL})
message(STATUS "Compiler extra cxx flags:" ${CMAKE_CXX_FLAGS})
message(STATUS "Available targets: tags compdb update-engine3 core3 odb3 idl rebuild-idl")