-
Notifications
You must be signed in to change notification settings - Fork 166
/
CMakeLists.txt
240 lines (194 loc) · 7.64 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
cmake_minimum_required(VERSION 3.10)
project(odyssey C)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
${CMAKE_CURRENT_SOURCE_DIR}/cmake)
set(CLANGCOMPILERSTANDART gnu11)
set(OD_VERSION_GIT $ENV{VERSION})
if ("${OD_VERSION_GIT}" STREQUAL "")
execute_process(COMMAND git describe --always
OUTPUT_VARIABLE OD_VERSION_GIT
RESULT_VARIABLE OD_VERSION_GIT_RESULT
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET)
if(NOT "${OD_VERSION_GIT_RESULT}" STREQUAL "0")
add_definitions(-DOD_VERSION_GIT="unknown")
else()
add_definitions(-DOD_VERSION_GIT="${OD_VERSION_GIT}")
endif()
else()
add_definitions(-DOD_VERSION_GIT="${OD_VERSION_GIT}")
endif()
set(OD_VERSION_NUMBER $ENV{BUILD_NUMBER})
if ("${OD_VERSION_NUMBER}" STREQUAL "")
execute_process(COMMAND git rev-list --count HEAD
OUTPUT_VARIABLE OD_VERSION_NUMBER
RESULT_VARIABLE OD_VERSION_NUMBER_RESULT
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET)
if(NOT "${OD_VERSION_NUMBER_RESULT}" STREQUAL "0")
add_definitions(-DOD_VERSION_NUMBER="unknown")
else()
add_definitions(-DOD_VERSION_NUMBER="${OD_VERSION_NUMBER}")
endif()
else()
add_definitions(-DOD_VERSION_NUMBER="${OD_VERSION_NUMBER}")
endif()
execute_process(COMMAND ${CMAKE_C_COMPILER} --version
OUTPUT_VARIABLE OD_COMPILER_VERSION
RESULT_VARIABLE OD_COMPILER_VERSION_RESULT
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET)
set(OD_DEVEL_LVL -1)
if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
set(CMAKE_BUILD_TYPE "Debug")
set(OD_DEVEL_LVL 1)
endif()
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
set(CMAKE_C_FLAGS "-std=${CLANGCOMPILERSTANDART} -pedantic -Wall -Wextra -Wstrict-aliasing -g -O2 -pthread -D_GNU_SOURCE")
set(OD_DEVEL_LVL -1)
elseif("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
set(CMAKE_C_FLAGS "-std=${CLANGCOMPILERSTANDART} -pedantic -Wall -Wextra -Wstrict-aliasing -g -O0 -pthread -D_GNU_SOURCE -DLDAP_DBG")
set(OD_DEVEL_LVL 1)
elseif("${CMAKE_BUILD_TYPE}" STREQUAL "ASAN")
set(CMAKE_C_FLAGS "-std=${CLANGCOMPILERSTANDART} -g -fsanitize=address,undefined -fno-sanitize-recover=all -pedantic -Wall -Wextra -Wstrict-aliasing -g -O0 -pthread -D_GNU_SOURCE")
elseif("${CMAKE_BUILD_TYPE}" STREQUAL "TSAN")
set(CMAKE_C_FLAGS "-std=${CLANGCOMPILERSTANDART} -g -fsanitize=thread -fno-sanitize-recover=all -pedantic -Wall -Wextra -Wstrict-aliasing -g -O0 -pthread -D_GNU_SOURCE")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CC_FLAGS}")
string(TOLOWER ${CMAKE_BUILD_TYPE} OD_VERSION_BUILD)
add_definitions(-DOD_VERSION_BUILD="${OD_VERSION_BUILD}")
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package(Threads REQUIRED)
add_custom_target(build_libs)
set(od_libraries "rt")
# debian build
option(BUILD_DEBIAN "Enable Debian Build" OFF)
if (BUILD_DEBIAN)
include(BuildDebian)
endif()
# postgresql
find_package(PostgreSQL REQUIRED)
set(od_libraries ${od_libraries} ${POSTGRESQL_LIBRARY} ${POSTGRESQL_LIBPGPORT} ${PQ_LIBRARY})
include_directories(${POSTGRESQL_INCLUDE_DIR})
set(OPENSSL_INCLUDE_DIR $ENV{OPENSSL_INCLUDE_DIR})
set(OPENSSL_LIBRARIES $ENV{OPENSSL_LIBRARIES})
set(OPENSSL_VERSION $ENV{OPENSSL_VERSION})
# use BoringSSL or OpenSSL
option(USE_BORINGSSL "Use BoringSSL" OFF)
if (USE_BORINGSSL)
find_package(BoringSSL REQUIRED)
if (BORINGSSL_FOUND)
set(od_ssl ${BORINGSSL_LIBRARIES})
include_directories(${BORINGSSL_INCLUDE_DIR})
endif ()
elseif ("${OPENSSL_LIBRARIES}" STREQUAL "")
find_package(OpenSSL REQUIRED)
set(od_ssl ${OPENSSL_LIBRARIES})
include_directories(${OPENSSL_INCLUDE_DIR})
add_definitions(-DUSE_SSL)
else ()
set(od_ssl ${OPENSSL_LIBRARIES})
include_directories(${OPENSSL_INCLUDE_DIR})
add_definitions(-DUSE_SSL)
endif ()
# use PAM
find_package(PAM)
if (PAM_FOUND)
set(od_pam ${PAM_LIBRARY})
include_directories(${PAM_INCLUDE_DIR})
endif()
set(od_libraries ${od_libraries} ${od_pam})
# use LDAP
find_package(LDAP)
if (LDAP_FOUND)
set(od_ldap ${LDAP_LIBRARY})
include_directories(${LDAP_INCLUDE_DIR})
endif()
set(od_libraries ${od_libraries} ${od_ldap})
# use Prom
find_package(Prom)
if (PROMHTTP_FOUND)
set(od_promhttp ${PROMHTTP_LIBRARY})
include_directories(${PROMHTTP_INCLUDE_DIR})
endif()
set(od_libraries ${od_libraries} ${od_promhttp})
if (PROM_FOUND)
set(od_prom ${PROM_LIBRARY})
include_directories(${PROM_INCLUDE_DIR})
endif()
set(od_libraries ${od_libraries} ${od_prom})
#scram
if (USE_SCRAM)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_SCRAM")
endif()
#compression
option(BUILD_COMPRESSION "Build with compression support" OFF)
if(BUILD_COMPRESSION)
set(compression_libraries "")
add_definitions(-DMM_BUILD_COMPRESSION)
# use zstd
find_package(Zstd)
if(ZSTD_FOUND)
include_directories(${ZSTD_INCLUDE_DIR})
set(compression_libraries ${compression_libraries} ${ZSTD_LIBRARY})
add_definitions(-DMM_HAVE_ZSTD)
endif()
# use zlib
find_package(ZLIB)
if(ZLIB_FOUND)
include_directories(${ZLIB_INCLUDE_DIRS})
set(compression_libraries ${compression_libraries} ${ZLIB_LIBRARIES})
add_definitions(-DMM_HAVE_ZLIB)
endif()
endif()
# machinarium
include(BuildMachinarium)
build_machinarium()
set(od_libraries ${od_libraries} ${MACHINARIUM_LIBRARIES} ${od_ssl} "dl")
include_directories(${MACHINARIUM_INCLUDE_DIRS})
# kiwi
include(BuildKiwi)
build_kiwi()
set(od_libraries ${od_libraries} ${KIWI_LIBRARIES})
include_directories(${KIWI_INCLUDE_DIRS})
message(STATUS "")
message(STATUS "Odyssey (version: ${OD_VERSION_NUMBER}-${OD_VERSION_GIT}-${OD_VERSION_BUILD})")
message(STATUS "")
message(STATUS "using compiler: ${CMAKE_C_COMPILER} version
${OD_COMPILER_VERSION}")
message(STATUS "c lang standard: ${CLANGCOMPILERSTANDARD}")
message(STATUS " ")
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
message(STATUS "BUILD_DEBIAN: ${BUILD_DEBIAN}")
message(STATUS "POSTGRESQL_INCLUDE_DIR: ${POSTGRESQL_INCLUDE_DIR}")
message(STATUS "POSTGRESQL_LIBRARY: ${POSTGRESQL_LIBRARY}")
message(STATUS "POSTGRESQL_LIBPGPORT: ${POSTGRESQL_LIBPGPORT}")
message(STATUS "PG_VERSION_NUM: ${PG_VERSION_NUM}")
message(STATUS "PQ_LIBRARY: ${PQ_LIBRARY}")
message(STATUS "USE_BORINGSSL: ${USE_BORINGSSL}")
message(STATUS "BORINGSSL_ROOT_DIR: ${BORINGSSL_ROOT_DIR}")
message(STATUS "BORINGSSL_INCLUDE_DIR: ${BORINGSSL_INCLUDE_DIR}")
message(STATUS "OPENSSL_VERSION: ${OPENSSL_VERSION}")
message(STATUS "OPENSSL_ROOT_DIR: ${OPENSSL_ROOT_DIR}")
message(STATUS "OPENSSL_INCLUDE_DIR: ${OPENSSL_INCLUDE_DIR}")
message(STATUS "OPENSSL_LIBRARIES: ${OPENSSL_LIBRARIES}")
if (PAM_FOUND)
message(STATUS "PAM_LIBRARY: ${PAM_LIBRARY}")
message(STATUS "PAM_INCLUDE_DIR: ${PAM_INCLUDE_DIR}")
endif()
message(STATUS "USE_SCRAM: ${USE_SCRAM}")
message(STATUS "BUILD_COMPRESSION: ${BUILD_COMPRESSION}")
if (BUILD_COMPRESSION)
message(STATUS "ZSTD_INCLUDE_DIR: ${ZSTD_INCLUDE_DIR}")
message(STATUS "ZSTD_LIBRARY: ${ZSTD_LIBRARY}")
message(STATUS "ZLIB_INCLUDE_DIRS: ${ZLIB_INCLUDE_DIRS}")
message(STATUS "ZLIB_LIBRARIES: ${ZLIB_LIBRARIES}")
endif()
message(STATUS "LDAP_SUPPORT: ${LDAP_FOUND}")
if (LDAP_FOUND)
message(STATUS "LDAP_LIBRARY: ${LDAP_LIBRARY}")
message(STATUS "LDAP_INCLUDE_DIR: ${LDAP_INCLUDE_DIR}")
endif()
add_subdirectory(sources)
add_subdirectory(test)
add_subdirectory(stress)