forked from Sphereserver/Source-X
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
180 lines (142 loc) · 6 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
# Main config #
CMAKE_MINIMUM_REQUIRED (VERSION 3.13)
SET (CMAKE_SUPPRESS_REGENERATION true) # Supress the ZERO_CHECK generation
SET (CMAKE_NO_GIT_REVISION false CACHE BOOL "Do not try to retrieve the current git revision. Useful for building source not git-cloned from Github.")
SET (WIN32_SPAWN_CONSOLE false CACHE BOOL "Spawn an additional console, useful for debugging.")
SET (USE_ASAN false CACHE BOOL "Enable AddressSanitizer.")
SET (USE_MSAN false CACHE BOOL "Enable MemorySanitizer.")
SET (USE_LSAN false CACHE BOOL "Enable LeakSanitizer.")
SET (USE_UBSAN false CACHE BOOL "Enable Undefined Behavior Sanitizer.")
FUNCTION (booleanize_str_find VAR)
IF (${VAR} EQUAL -1)
UNSET (${VAR} PARENT_SCOPE)
ELSE ()
SET (${VAR} 1 PARENT_SCOPE)
ENDIF ()
ENDFUNCTION ()
IF ((NOT TOOLCHAIN) AND (NOT ${CMAKE_TOOLCHAIN_FILE} STREQUAL ""))
INCLUDE (${CMAKE_TOOLCHAIN_FILE})
toolchain_force_compiler ()
ENDIF ()
MESSAGE (STATUS "Scanning system build tools...")
PROJECT (SphereServer) # does a scan for C++ and C compilers
# Determine system arch
INCLUDE ("cmake/CMakeDetectArch.cmake")
determine_target_architecture(ARCH_DETECTED)
STRING (FIND "${ARCH_DETECTED}" "x86_64" ARCH_HAS_x86_64)
STRING (FIND "${ARCH_DETECTED}" "x86" ARCH_HAS_x86)
booleanize_str_find(ARCH_HAS_x86_64)
booleanize_str_find(ARCH_HAS_x86)
# If we have not specified a toolchain, let's detect which one we should use, using the detected arch.
IF (NOT TOOLCHAIN)
INCLUDE ("cmake/CMakeDefaultToolchain.cmake")
ENDIF ()
# Stuff that needs to be executed after PROJECT but before ADD_EXECUTABLE
toolchain_after_project()
STRING (FIND "${CMAKE_GENERATOR}" "Makefiles" GEN_IS_MAKEFILE)
STRING (FIND "${CMAKE_GENERATOR}" "Ninja" GEN_IS_NINJA)
booleanize_str_find(GEN_IS_MAKEFILE)
booleanize_str_find(GEN_IS_NINJA)
IF ( (GEN_IS_MAKEFILE OR GEN_IS_NINJA) AND (NOT MSVC) )
SET (SINGLE_TARGET 1)
ENDIF ()
# TODO: check if Ninja can handle different targets.
IF (SINGLE_TARGET)
# If you want to manually specify the build type, call cmake with parameter: -DCMAKE_BUILD_TYPE=something
MESSAGE (STATUS "Single-target build system (${CMAKE_GENERATOR}) detected: generating multiple projects!")
IF (NOT ${CMAKE_BUILD_TYPE} STREQUAL "")
IF ((NOT ${CMAKE_BUILD_TYPE} STREQUAL "Release") AND (NOT ${CMAKE_BUILD_TYPE} STREQUAL "Debug") AND (NOT ${CMAKE_BUILD_TYPE} STREQUAL "Nightly"))
MESSAGE (WARNING "Invalid parameter -DCMAKE_BUILD_TYPE, defaulting to Nightly.")
# -> needed only for MAKEFILE-STYLE generators, which can't switch between different configs
SET (CMAKE_BUILD_TYPE "Nightly" CACHE STRING "" FORCE)
ELSE ()
MESSAGE (STATUS "Generating only specified project: ${CMAKE_BUILD_TYPE}.")
ENDIF ()
ELSE ()
MESSAGE (STATUS "No target specified: building all the projects (Release, Debug, Nightly).")
# The only situation supported here is using MSVC, and /MP (multi-core) is set in its compiler flags.
ENDIF ()
IF (GEN_IS_MAKEFILE)
# Setting parallel make; ninja does that by default.
INCLUDE (ProcessorCount)
ProcessorCount (MAKE_THREADS)
IF (NOT MAKE_THREADS EQUAL 0)
MATH (EXPR MAKE_THREADS "${MAKE_THREADS} + (${MAKE_THREADS}/2)") # Suggested number of threads: cores * 1.5
SET (CMAKE_MAKE_PROGRAM "${CMAKE_MAKE_PROGRAM} -j${MAKE_THREADS}")
ELSE ()
MESSAGE (STATUS "Can't determine CPU cores number. Parallel compilation turned off.")
ENDIF ()
ENDIF ()
ELSE (SINGLE_TARGET)
MESSAGE (STATUS "Multi-target build system detected: generating single project with multiple targets!")
SET (CMAKE_CONFIGURATION_TYPES "Debug;Release;Nightly" CACHE STRING "" FORCE)
ENDIF (SINGLE_TARGET)
# Include the list of all our source files
INCLUDE ("CMakeSources.cmake")
SET (ALL_SRCS
${LIB_SRCS}
${game_SRCS}
${items_SRCS}
${chars_SRCS}
${clients_SRCS}
${components_SRCS}
${uofiles_SRCS}
${common_SRCS}
${resource_SRCS}
${resourcesections_SRCS}
${network_SRCS}
${crypto_SRCS}
${sphere_SRCS}
${crashdump_SRCS}
${spherelibrary_SRCS}
${tables_SRCS}
${app_resources_SRCS}
)
# Configure output binaries
IF (SINGLE_TARGET)
IF (("${CMAKE_BUILD_TYPE}" STREQUAL "") OR (${CMAKE_BUILD_TYPE} MATCHES "(R|r?)elease"))
SET (TARGETS ${TARGETS} spheresvr_release)
ADD_EXECUTABLE (spheresvr_release
${ALL_SRCS}
# ${docs_TEXT}
)
SET_TARGET_PROPERTIES (spheresvr_release PROPERTIES OUTPUT_NAME SphereSvrX${ARCH_BITS}_release)
ENDIF ()
IF (("${CMAKE_BUILD_TYPE}" STREQUAL "") OR (${CMAKE_BUILD_TYPE} MATCHES "(N|n?)ightly"))
SET (TARGETS ${TARGETS} spheresvr_nightly)
ADD_EXECUTABLE (spheresvr_nightly
${ALL_SRCS}
# ${docs_TEXT}
)
SET_TARGET_PROPERTIES (spheresvr_nightly PROPERTIES OUTPUT_NAME SphereSvrX${ARCH_BITS}_nightly)
ENDIF ()
IF (("${CMAKE_BUILD_TYPE}" STREQUAL "") OR (${CMAKE_BUILD_TYPE} MATCHES "(D|d?)ebug"))
SET (TARGETS ${TARGETS} spheresvr_debug)
ADD_EXECUTABLE (spheresvr_debug
${ALL_SRCS}
# ${docs_TEXT}
)
SET_TARGET_PROPERTIES (spheresvr_debug PROPERTIES OUTPUT_NAME SphereSvrX${ARCH_BITS}_debug)
ENDIF ()
ELSE (SINGLE_TARGET)
SET (TARGETS ${TARGETS} spheresvr)
ADD_EXECUTABLE (spheresvr
${ALL_SRCS}
${docs_TEXT}
)
SET_TARGET_PROPERTIES (spheresvr PROPERTIES OUTPUT_NAME_RELEASE SphereSvrX${ARCH_BITS}_release)
SET_TARGET_PROPERTIES (spheresvr PROPERTIES OUTPUT_NAME_NIGHTLY SphereSvrX${ARCH_BITS}_nightly)
SET_TARGET_PROPERTIES (spheresvr PROPERTIES OUTPUT_NAME_DEBUG SphereSvrX${ARCH_BITS}_debug)
ENDIF (SINGLE_TARGET)
# Need to clear shared library flags. If not, cmake sets -rdynamic and this
# add to the executable the full symbol table (included unused symbols).
# This is a problem because the binary is ~700 KB bigger.
SET (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS)
SET (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS)
toolchain_exe_stuff() # stuff to be executed after ADD_EXECUTABLE
# Get the Git revision number
INCLUDE ("cmake/CMakeGitStatus.cmake")
# Generate config.h file for libev (if we are using it)
INCLUDE ("cmake/CMakeConditionalConfigureLibev.cmake")
# Configure MariaDB C Connector source headers
INCLUDE ("lib/mariadb/configure.cmake")