forked from dingodb/dingo-store
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
370 lines (325 loc) · 11.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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
# Copyright (c) 2023 dingodb.com, Inc. All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Use the command in the next line to release
# cmake -DCMAKE_BUILD_TYPE=Release -DTHIRD_PARTY_BUILD_TYPE=Release ..
cmake_minimum_required(VERSION 3.23.1 FATAL_ERROR)
project(dingo-store C CXX)
option(EXAMPLE_LINK_SO "Whether examples are linked dynamically" OFF)
option(LINK_TCMALLOC "Link tcmalloc if possible" OFF)
option(BUILD_UNIT_TESTS "Build unit test" ON)
option(DINGO_BUILD_STATIC "Link libraries statically to generate the DingoDB binary" OFF)
option(ENABLE_FAILPOINT "Enable failpoint" OFF)
option(WITH_DISKANN "Build with diskann index" OFF)
option(WITH_MKL "Build with intel mkl" OFF)
option(BOOST_SEARCH_PATH "")
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-std=c++17" COMPILER_SUPPORTS_CXX17)
if(COMPILER_SUPPORTS_CXX17)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
else()
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++17 support. Please use a different C++ compiler.")
endif()
if(THIRD_PARTY_BUILD_TYPE MATCHES "Debug")
set(CMAKE_STATIC_LIBRARY_SUFFIX "d.a")
endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24:
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif()
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(THIRD_PARTY_PATH ${CMAKE_CURRENT_BINARY_DIR}/third-party)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_PREFIX_PATH ${OUTPUT_PATH})
execute_process(COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/contrib/.clang-tidy ${CMAKE_CURRENT_BINARY_DIR}/)
find_package(Threads REQUIRED)
include(openssl)
include(zlib)
include(gflags)
include(glog)
include(gtest)
include(snappy)
include(lz4)
include(zstd)
include(leveldb)
include(protobuf)
include(rocksdb)
include(brpc)
include(braft)
include(yaml-cpp)
include(openblas)
include(faiss)
include(fmt)
include(libunwind)
include(libbacktrace)
include(gperftools)
include(hnswlib)
message("protoc: ${PROTOBUF_PROTOC_EXECUTABLE}, proto inc: ${PROTOBUF_INCLUDE_DIRS}, lib: ${PROTOBUF_LIBRARIES}, ${PROTOBUF_PROTOC_LIBRARY}, protos: ${PROTO_FILES}")
SET(MESSAGE_DIR ${CMAKE_CURRENT_BINARY_DIR}/proto)
if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/proto" AND IS_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/proto")
SET(PROTO_META_BASE_DIR ${MESSAGE_DIR})
else()
file(MAKE_DIRECTORY ${MESSAGE_DIR})
SET(PROTO_META_BASE_DIR ${MESSAGE_DIR})
endif()
LIST(APPEND PROTO_FLAGS -I${CMAKE_SOURCE_DIR}/proto)
file(GLOB_RECURSE MSG_PROTOS ${CMAKE_SOURCE_DIR}/proto/*.proto)
set(PROTO_SRCS "")
set(PROTO_HDRS "")
foreach(msg ${MSG_PROTOS})
get_filename_component(FIL_WE ${msg} NAME_WE)
list(APPEND PROTO_SRCS "${CMAKE_CURRENT_BINARY_DIR}/proto/${FIL_WE}.pb.cc")
list(APPEND PROTO_HDRS "${CMAKE_CURRENT_BINARY_DIR}/proto/${FIL_WE}.pb.h")
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/proto/${FIL_WE}.pb.cc"
"${CMAKE_CURRENT_BINARY_DIR}/proto/${FIL_WE}.pb.h"
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE}
ARGS --cpp_out ${PROTO_META_BASE_DIR}
-I ${CMAKE_SOURCE_DIR}/proto
${msg}
DEPENDS protobuf ${msg}
COMMENT "Running C++ protocol buffer compiler on ${msg}"
VERBATIM
)
endforeach()
set_source_files_properties(${PROTO_SRCS} ${PROTO_HDRS} PROPERTIES GENERATED TRUE)
add_library(PROTO_OBJS OBJECT ${PROTO_SRCS})
message("Debug Message protoc: ${PROTOBUF_PROTOC_EXECUTABLE}, proto srcs : ${PROTO_SRCS}")
add_custom_target(build_proto ALL
DEPENDS ${PROTO_SRCS} ${PROTO_HDRS}
COMMENT "generate message target"
VERBATIM
)
# include PROTO_HEADER
include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${BRAFT_INCLUDE_DIR})
include_directories(${BRPC_INCLUDE_DIR})
include_directories(${GLOG_INCLUDE_DIR})
include_directories(${GTEST_INCLUDE_DIR})
include_directories(${GFLAGS_INCLUDE_DIR})
include_directories(${ROCKSDB_INCLUDE_DIR})
include_directories(${YAMLCPP_INCLUDE_DIR})
include_directories(${FMT_INCLUDE_DIR})
include_directories(${OPENSSL_INCLUDE_DIR})
include_directories(${LIBUNWIND_INCLUDE_DIR})
include_directories(${LIBBACKTRACE_INCLUDE_DIR})
include_directories(${GPERFTOOLS_INCLUDE_DIR})
include_directories(${FAISS_INCLUDE_DIR})
include_directories(${PROJECT_SOURCE_DIR}/src)
set(DYNAMIC_LIB
${GFLAGS_LIBRARIES}
${PROTOBUF_LIBRARY}
${LEVELDB_LIBRARIES}
${BRAFT_LIBRARIES}
${BRPC_LIBRARIES}
${ROCKSDB_LIBRARIES}
${SNAPPY_LIBRARIES}
${LZ4_LIBRARIES}
${ZSTD_LIBRARIES}
${YAMLCPP_LIBRARIES}
${FAISS_LIBRARIES}
${FMT_LIBRARIES}
${ZLIB_LIBRARIES}
${OPENSSL_LIBRARIES}
${CRYPTO_LIBRARIES}
${GLOG_LIBRARIES}
${GTEST_MAIN_LIBRARIES}
${GTEST_LIBRARIES}
${LIBUNWIND_LIBRARIES}
${LIBUNWIND_GENERIC_LIBRARIES}
${LIBUNWIND_ARCH_LIBRARIES}
${LIBBACKTRACE_LIBRARIES}
# rt
dl
Threads::Threads
)
set(DEPEND_LIBS
openssl
zlib
gflags
protobuf
leveldb
braft
brpc
rocksdb
snappy
lz4
zstd
glog
yamlcpp
faiss
fmt
gtest
libunwind
libbacktrace
)
if(LINK_TCMALLOC)
message(STATUS "Build DingoDB with tcmalloc")
set(DYNAMIC_LIB ${DYNAMIC_LIB} ${GPERFTOOLS_LIBRARIES})
set(DEPEND_LIBS ${DEPEND_LIBS} gperftools)
endif()
if(WITH_MKL)
find_package(MKL REQUIRED)
if(MKL_FOUND)
message(STATUS "The MKL is found, use intel mkl to replace openblas.")
else()
message(FATAL_ERROR "The MKL is not found, please install MKL and enable MKL.")
endif()
else()
find_package(MKL QUIET)
if(MKL_FOUND)
message(FATAL_ERROR "The MKL is found, cannot build faiss with openblas, please disable MKL.")
endif()
include_directories(${OPENBLAS_INCLUDE_DIR})
set(DEPEND_LIBS ${DEPEND_LIBS} openblas)
set(DYNAMIC_LIB ${DYNAMIC_LIB} ${OPENBLAS_LIBRARIES})
endif()
if(WITH_DISKANN)
if(NOT WITH_MKL)
message(FATAL_ERROR "The WITH_MKL is not ON, please install enable WITH_MKL to build diskann.")
endif()
if(NOT MKL_FOUND)
message(FATAL_ERROR "The MKL is not found, please install intel mkl to build diskann.")
endif()
if(NOT BOOST_SEARCH_PATH)
find_package(Boost REQUIRED COMPONENTS program_options)
else()
message(STATUS "BOOST_SEARCH_PATH=${BOOST_SEARCH_PATH}, use user-defined boost version")
endif()
include(diskann)
include_directories(${DISKANN_INCLUDE_DIR})
set(DEPEND_LIBS ${DEPEND_LIBS} diskann)
set(DYNAMIC_LIB ${DYNAMIC_LIB} ${DISKANN_LIBRARIES})
endif()
# source file
file(GLOB COMMON_SRCS ${PROJECT_SOURCE_DIR}/src/common/*.cc)
file(GLOB CONFIG_SRCS ${PROJECT_SOURCE_DIR}/src/config/*.cc)
file(GLOB LOG_SRCS ${PROJECT_SOURCE_DIR}/src/log/*.cc)
file(GLOB VECTOR_SRCS ${PROJECT_SOURCE_DIR}/src/vector/*.cc)
file(GLOB RAFT_SRCS ${PROJECT_SOURCE_DIR}/src/raft/*.cc)
file(GLOB ENGINE_SRCS ${PROJECT_SOURCE_DIR}/src/engine/*.cc)
file(GLOB CRONTAB_SRCS ${PROJECT_SOURCE_DIR}/src/crontab/*.cc)
file(GLOB HANDLER_SRCS ${PROJECT_SOURCE_DIR}/src/handler/*.cc)
file(GLOB EVENT_SRCS ${PROJECT_SOURCE_DIR}/src/event/*.cc)
file(GLOB META_SRCS ${PROJECT_SOURCE_DIR}/src/meta/*.cc)
file(GLOB COORDINATOR_SRCS ${PROJECT_SOURCE_DIR}/src/coordinator/*.cc)
file(GLOB STORE_SRCS ${PROJECT_SOURCE_DIR}/src/store/*.cc)
file(GLOB SERVER_SRCS ${PROJECT_SOURCE_DIR}/src/server/*.cc)
file(GLOB SCAN_SRCS ${PROJECT_SOURCE_DIR}/src/scan/*.cc)
file(GLOB METRICS_SRCS ${PROJECT_SOURCE_DIR}/src/metrics/*.cc)
file(GLOB VERSION_SRCS ${PROJECT_SOURCE_DIR}/src/common/version.cc)
file(GLOB SERIAL1_SRCS ${PROJECT_SOURCE_DIR}/src/serial/*.cc)
file(GLOB SERIAL2_SRCS ${PROJECT_SOURCE_DIR}/src/serial/schema/*.cc)
file(GLOB EXPR_SRCS ${PROJECT_SOURCE_DIR}/src/expr/*.cc)
file(GLOB EXPR_CALC_SRCS ${PROJECT_SOURCE_DIR}/src/expr/calc/*.cc)
file(GLOB COPROCESSOR_SRCS ${PROJECT_SOURCE_DIR}/src/coprocessor/*.cc)
list(REMOVE_ITEM SERVER_SRCS "${PROJECT_SOURCE_DIR}/src/server/main.cc")
# object file
add_library(DINGODB_OBJS
OBJECT
${COMMON_SRCS}
${CONFIG_SRCS}
${LOG_SRCS}
${VECTOR_SRCS}
${RAFT_SRCS}
${ENGINE_SRCS}
${CRONTAB_SRCS}
${HANDLER_SRCS}
${EVENT_SRCS}
${META_SRCS}
${COORDINATOR_SRCS}
${STORE_SRCS}
${SERVER_SRCS}
${SCAN_SRCS}
${METRICS_SRCS}
${SERIAL1_SRCS}
${SERIAL2_SRCS}
${COPROCESSOR_SRCS}
${EXPR_SRCS}
${EXPR_CALC_SRCS}
)
# bin output dir
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
execute_process(
COMMAND git describe --always --dirty
OUTPUT_VARIABLE GIT_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND git describe --abbrev=0 --tags --always
OUTPUT_VARIABLE GIT_TAG_NAME
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (NOT GIT_VERSION)
set(GIT_VERSION "unknown")
endif()
if (NOT GIT_TAG_NAME)
set(GIT_TAG_NAME "unknown")
endif()
add_definitions(-DGLOG_CUSTOM_PREFIX_SUPPORT=ON)
add_definitions(-DGIT_VERSION="${GIT_VERSION}")
add_definitions(-DGIT_TAG_NAME="${GIT_TAG_NAME}")
add_definitions(-DDINGO_BUILD_TYPE="${CMAKE_BUILD_TYPE}")
add_definitions(-DDINGO_CONTRIB_BUILD_TYPE="${THIRD_PARTY_BUILD_TYPE}")
if (ENABLE_FAILPOINT)
message(STATUS "Enable failpoint")
add_definitions(-DENABLE_FAILPOINT="ON")
unset(ENABLE_FAILPOINT CACHE)
endif()
add_executable(dingodb_server src/server/main.cc $<TARGET_OBJECTS:DINGODB_OBJS> $<TARGET_OBJECTS:PROTO_OBJS>)
add_executable(dingodb_client_store
src/client/store_client.cc
src/client/client_interation.cc
src/client/store_client_function.cc
src/common/helper.cc
${VERSION_SRCS} $<TARGET_OBJECTS:PROTO_OBJS>)
add_executable(dingodb_client_coordinator
src/client/coordinator_client.cc
src/client/coordinator_client_function_coor.cc
src/client/coordinator_client_function_meta.cc
src/client/coordinator_client_function_incr.cc
src/common/helper.cc
src/coordinator/coordinator_interaction.cc
${VERSION_SRCS} $<TARGET_OBJECTS:PROTO_OBJS>)
add_dependencies(DINGODB_OBJS ${DEPEND_LIBS})
add_dependencies(dingodb_server ${DEPEND_LIBS})
add_dependencies(dingodb_client_store ${DEPEND_LIBS})
add_dependencies(dingodb_client_coordinator ${DEPEND_LIBS})
if(DINGO_BUILD_STATIC)
message(STATUS "Build DingoDB with static libraries linking")
if (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
# This is only for build some modules for testing, not for the whole project.
# This project is currently not compatible with MacOS.
else()
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
endif()
endif()
target_link_libraries(dingodb_server
"-Xlinker \"-(\""
${DYNAMIC_LIB}
"-Xlinker \"-)\"")
target_link_libraries(dingodb_client_store
"-Xlinker \"-(\""
${DYNAMIC_LIB}
"-Xlinker \"-)\"")
target_link_libraries(dingodb_client_coordinator
"-Xlinker \"-(\""
${DYNAMIC_LIB}
"-Xlinker \"-)\"")
add_subdirectory(src)
if(BUILD_UNIT_TESTS)
add_subdirectory(test)
endif()