-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
359 lines (297 loc) · 13.7 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
cmake_minimum_required(VERSION 3.8)
project(log_service C CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
option(WITH_CLOUD_AZ_INFO "With Cloud Availability Zone Info" OFF)
message(NOTICE "With Cloud Availability Zone Info: ${WITH_CLOUD_AZ_INFO}")
if (WITH_CLOUD_AZ_INFO)
add_definitions(-DWITH_CLOUD_AZ_INFO)
endif()
SET(LOG_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
SET(LOG_PROTO_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tx-log-protos)
message(NOTICE "log_service source dir: ${LOG_SOURCE_DIR}")
option(TEST_LOG_SERVICE "Test log service" ON)
message(NOTICE "TEST_LOG_SERVICE : ${TEST_LOG_SERVICE}")
option(BRPC_WITH_GLOG "With glog" ON)
message(NOTICE "BRPC_WITH_GLOG : ${BRPC_WITH_GLOG}")
option(LINK_TCMALLOC "Link tcmalloc if possible" OFF)
message(NOTICE "LINK_TCMALLOC : ${LINK_TCMALLOC}")
option(USE_ROCKSDB_LOG_STATE "Whether use rocksdb log state or in-memory log state" ON)
message(NOTICE "USE_ROCKSDB_LOG_STATE : ${USE_ROCKSDB_LOG_STATE}")
option(WITH_ROCKSDB_CLOUD "RocksDB Cloud storage backend, S3 or GCS")
set_property(CACHE WITH_ROCKSDB_CLOUD PROPERTY STRINGS "S3" "GCS")
message(NOTICE "With RocksDB Cloud: ${WITH_ROCKSDB_CLOUD}")
option(WITH_ASAN "Enable memory sanitize" OFF)
message(NOTICE "WITH ASAN: ${WITH_ASAN}")
option(DISABLE_CODE_LINE_IN_LOG "Enable DISABLE_CODE_LINE_IN_LOG" OFF)
message(NOTICE "DISABLE_CODE_LINE_IN_LOG : ${DISABLE_CODE_LINE_IN_LOG}")
if (DISABLE_CODE_LINE_IN_LOG)
add_definitions(-DDISABLE_CODE_LINE_IN_LOG)
endif()
#include(FindThreads)
#include(FindProtobuf)
find_path(BRPC_INCLUDE_PATH NAMES brpc/stream.h)
find_library(BRPC_LIB NAMES brpc)
if ((NOT BRPC_INCLUDE_PATH) OR (NOT BRPC_LIB))
message(FATAL_ERROR "Fail to find brpc")
endif ()
include_directories(${BRPC_INCLUDE_PATH})
find_path(BRAFT_INCLUDE_PATH NAMES braft/raft.h)
find_library(BRAFT_LIB NAMES braft)
if ((NOT BRAFT_INCLUDE_PATH) OR (NOT BRAFT_LIB))
message(FATAL_ERROR "Fail to find braft")
endif ()
include_directories(${BRAFT_INCLUDE_PATH})
find_path(GFLAGS_INCLUDE_PATH gflags/gflags.h)
find_library(GFLAGS_LIBRARY NAMES gflags libgflags)
if ((NOT GFLAGS_INCLUDE_PATH) OR (NOT GFLAGS_LIBRARY))
message(FATAL_ERROR "Fail to find gflags")
endif ()
include_directories(${GFLAGS_INCLUDE_PATH})
if (BRPC_WITH_GLOG)
find_path(GLOG_INCLUDE_PATH NAMES glog/logging.h)
find_library(GLOG_LIB NAMES glog)
if ((NOT GLOG_INCLUDE_PATH) OR (NOT GLOG_LIB))
message(FATAL_ERROR "Fail to find glog")
endif ()
include_directories(${GLOG_INCLUDE_PATH})
set(LOG_LIB ${LOG_LIB} ${GLOG_LIB})
endif ()
execute_process(
COMMAND bash -c "grep \"namespace [_A-Za-z0-9]\\+ {\" ${GFLAGS_INCLUDE_PATH}/gflags/gflags_declare.h | head -1 | awk '{print $2}' | tr -d '\n'"
OUTPUT_VARIABLE GFLAGS_NS
)
if (${GFLAGS_NS} STREQUAL "GFLAGS_NAMESPACE")
execute_process(
COMMAND bash -c "grep \"#define GFLAGS_NAMESPACE [_A-Za-z0-9]\\+\" ${GFLAGS_INCLUDE_PATH}/gflags/gflags_declare.h | head -1 | awk '{print $3}' | tr -d '\n'"
OUTPUT_VARIABLE GFLAGS_NS
)
endif ()
if (LINK_TCMALLOC)
find_path(GPERFTOOLS_INCLUDE_DIR NAMES gperftools/heap-profiler.h)
find_library(GPERFTOOLS_LIBRARIES NAMES tcmalloc_and_profiler)
if (GPERFTOOLS_INCLUDE_DIR AND GPERFTOOLS_LIBRARIES)
set(CMAKE_CXX_FLAGS "-DBRPC_ENABLE_CPU_PROFILER")
include_directories(${GPERFTOOLS_INCLUDE_DIR})
else ()
set(GPERFTOOLS_LIBRARIES "")
endif ()
endif ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CPP_FLAGS} -DGFLAGS_NS=${GFLAGS_NS} -O2 -D__const__=__unused__ -pipe -W -Wall -Wno-unused-parameter -fPIC -fno-omit-frame-pointer")
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# require at least gcc 4.8
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
message(FATAL_ERROR "GCC is too old, please install a newer version supporting C++11")
endif ()
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# require at least clang 3.3
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.3)
message(FATAL_ERROR "Clang is too old, please install a newer version supporting C++11")
endif ()
else ()
message(WARNING "You are using an unsupported compiler! Compilation has only been tested with Clang and GCC.")
endif ()
if (WITH_ASAN)
# Enable AddressSanitizer
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
endif()
find_path(LEVELDB_INCLUDE_PATH NAMES leveldb/db.h)
find_library(LEVELDB_LIB NAMES leveldb)
if ((NOT LEVELDB_INCLUDE_PATH) OR (NOT LEVELDB_LIB))
message(FATAL_ERROR "Fail to find leveldb")
endif ()
include_directories(${LEVELDB_INCLUDE_PATH})
set(LOG_SHIPPING_THREADS_NUM 8)
if (OVERRIDE_GFLAGS_NAMESPACE)
add_compile_definitions(OVERRIDE_GFLAGS_NAMESPACE)
endif ()
if (USE_ROCKSDB_LOG_STATE)
if (WITH_ROCKSDB_CLOUD MATCHES "S3|GCS")
if (WITH_ROCKSDB_CLOUD STREQUAL "S3")
find_path(AWS_CORE_INCLUDE_PATH aws/core/Aws.h)
if((NOT AWS_CORE_INCLUDE_PATH))
message(FATAL_ERROR "Fail to find aws/core include path")
endif()
message(STATUS "aws/core include path: ${AWS_CORE_INCLUDE_PATH}")
find_library(AWS_CORE_LIB aws-cpp-sdk-core)
if((NOT AWS_CORE_LIB ))
message(FATAL_ERROR "Fail to find aws-cpp-sdk-core lib")
endif()
message(STATUS "aws-cpp-sdk-core library: ${AWS_CORE_LIB}")
find_path(AWS_KINESIS_INCLUDE_PATH aws/kinesis/KinesisClient.h)
if((NOT AWS_KINESIS_INCLUDE_PATH))
message(FATAL_ERROR "Fail to find aws/kinesis include path")
endif()
message(STATUS "aws/kinesis include path: ${AWS_KINESIS_INCLUDE_PATH}")
find_library(AWS_KINESIS_LIB aws-cpp-sdk-kinesis)
if((NOT AWS_KINESIS_LIB))
message(FATAL_ERROR "Fail to find aws-cpp-sdk-kinesis lib")
endif()
message(STATUS "aws-cpp-sdk-kinesis library: ${AWS_KINESIS_LIB}")
find_path(AWS_KINESIS_INCLUDE_PATH aws/kinesis/KinesisClient.h)
if((NOT AWS_KINESIS_INCLUDE_PATH))
message(FATAL_ERROR "Fail to find aws/kinesis include path")
endif()
message(STATUS "aws/kinesis include path: ${AWS_KINESIS_INCLUDE_PATH}")
find_library(AWS_KINESIS_LIB aws-cpp-sdk-kinesis)
if((NOT AWS_KINESIS_LIB))
message(FATAL_ERROR "Fail to find aws-cpp-sdk-kinesis lib")
endif()
message(STATUS "aws-cpp-sdk-kinesis library: ${AWS_KINESIS_LIB}")
find_path(AWS_S3_INCLUDE_PATH aws/s3/S3Client.h)
if((NOT AWS_S3_INCLUDE_PATH))
message(FATAL_ERROR "Fail to find aws/s3 include path")
endif()
message(STATUS "aws/s3 include path: ${AWS_S3_INCLUDE_PATH}")
find_library(AWS_S3_LIB aws-cpp-sdk-s3)
if((NOT AWS_S3_LIB ))
message(FATAL_ERROR "Fail to find aws-cpp-sdk-s3 lib")
endif()
message(STATUS "aws-cpp-sdk-s3 library: ${AWS_S3_LIB}")
set(ROCKSDB_INCLUDE_PATH ${ROCKSDB_INCLUDE_PATH} ${AWS_CORE_INCLUDE_PATH})
set(ROCKSDB_INCLUDE_PATH ${ROCKSDB_INCLUDE_PATH} ${AWS_KINESIS_INCLUDE_PATH})
set(ROCKSDB_INCLUDE_PATH ${ROCKSDB_INCLUDE_PATH} ${AWS_S3_INCLUDE_PATH})
set(ROCKSDB_LIB ${ROCKSDB_LIB} ${AWS_CORE_LIB})
set(ROCKSDB_LIB ${ROCKSDB_LIB} ${AWS_KINESIS_LIB})
set(ROCKSDB_LIB ${ROCKSDB_LIB} ${AWS_S3_LIB})
find_library(ROCKSDB_CLOUD_LIB NAMES rocksdb-cloud-aws)
add_compile_definitions(USE_AWS)
add_compile_definitions(WITH_ROCKSDB_CLOUD=1)
elseif (WITH_ROCKSDB_CLOUD STREQUAL "GCS")
find_path(GCP_CS_INCLUDE_PATH google/cloud/storage/client.h)
if((NOT GCP_CS_INCLUDE_PATH))
message(FATAL_ERROR "Fail to find google/cloud/storage include path")
endif()
message(STATUS "google/cloud/storage include path: ${GCP_CS_INCLUDE_PATH}")
find_library(GCP_COMMON_LIB google_cloud_cpp_common)
if((NOT GCP_COMMON_LIB))
message(FATAL_ERROR "Fail to find google_cloud_cpp_common lib")
endif()
message(STATUS "google_cloud_cpp_common library: ${GCP_COMMON_LIB}")
find_library(GCP_CS_LIB google_cloud_cpp_storage)
if((NOT GCP_CS_LIB))
message(FATAL_ERROR "Fail to find google_cloud_cpp_storage lib")
endif()
message(STATUS "google_cloud_cpp_storage library: ${GCP_CS_LIB}")
set(ROCKSDB_LIB ${ROCKSDB_LIB} ${GCP_COMMON_LIB})
set(ROCKSDB_LIB ${ROCKSDB_LIB} ${GCP_CS_LIB})
find_library(ROCKSDB_CLOUD_LIB NAMES rocksdb-cloud-gcp)
add_compile_definitions(USE_GCP)
add_compile_definitions(WITH_ROCKSDB_CLOUD=2)
endif ()
find_path(ROCKSDB_CLOUD_INCLUDE_PATH NAMES rocksdb/db.h PATH_SUFFIXES "rocksdb_cloud_header")
if (NOT ROCKSDB_CLOUD_INCLUDE_PATH)
message(FATAL_ERROR "Fail to find RocksDB Cloud include path")
endif ()
message(STATUS "ROCKSDB_CLOUD_INCLUDE_PATH: ${ROCKSDB_CLOUD_INCLUDE_PATH}")
set(ROCKSDB_INCLUDE_PATH ${ROCKSDB_INCLUDE_PATH} ${ROCKSDB_CLOUD_INCLUDE_PATH})
if (NOT ROCKSDB_CLOUD_LIB)
message(FATAL_ERROR "Fail to find RocksDB Cloud lib path")
endif ()
message(STATUS "ROCKSDB_CLOUD_LIB: ${ROCKSDB_CLOUD_LIB}")
set(ROCKSDB_LIB ${ROCKSDB_LIB} ${ROCKSDB_CLOUD_LIB})
else ()
find_path(ROCKSDB_INCLUDE_PATH NAMES rocksdb/db.h)
if (NOT ROCKSDB_INCLUDE_PATH)
message(FATAL_ERROR "Fail to find RocksDB include path")
endif ()
message(STATUS "ROCKSDB_INCLUDE_PATH: ${ROCKSDB_INCLUDE_PATH}")
find_library(ROCKSDB_LIB NAMES rocksdb)
if (NOT ROCKSDB_LIB)
message(FATAL_ERROR "Fail to find RocksDB lib path")
endif ()
message(STATUS "ROCKSDB_LIB: ${ROCKSDB_LIB}")
endif ()
set(LOG_INCLUDE_DIR
${LOG_INCLUDE_DIR}
${ROCKSDB_INCLUDE_PATH}
)
set(LOG_LIB
${LOG_LIB}
${ROCKSDB_LIB}
)
# add preprocessor definition USE_ROCKSDB_LOG_STATE
add_compile_definitions(USE_ROCKSDB_LOG_STATE)
# one shipping thread is enough for rocksdb version log state
set(LOG_SHIPPING_THREADS_NUM 1)
endif ()
find_package(Protobuf REQUIRED)
set(PROTO_SRC ${LOG_PROTO_SOURCE_DIR})
set(PROTO_NAME log)
execute_process(
COMMAND protoc ./${PROTO_NAME}.proto --cpp_out=./
WORKING_DIRECTORY ${PROTO_SRC}
)
set(LOG_INCLUDE_DIR
${LOG_INCLUDE_DIR}
${LOG_SOURCE_DIR}/include
${LOG_PROTO_SOURCE_DIR}
)
set(LOG_LIB
${LOG_LIB}
${CMAKE_THREAD_LIBS_INIT}
${GFLAGS_LIBRARY}
${PROTOBUF_LIBRARY}
${GPERFTOOLS_LIBRARIES}
${LEVELDB_LIB}
${BRAFT_LIB}
${BRPC_LIB}
dl
z
)
add_library(logservice STATIC
${LOG_PROTO_SOURCE_DIR}/log.pb.cc
${LOG_PROTO_SOURCE_DIR}/log_agent.cpp
${LOG_SOURCE_DIR}/src/log_server.cpp
${LOG_SOURCE_DIR}/src/log_state_rocksdb_impl.cpp
${LOG_SOURCE_DIR}/src/log_state_rocksdb_cloud_impl.cpp
${LOG_SOURCE_DIR}/src/fault_inject.cpp
${LOG_SOURCE_DIR}/src/INIReader.cpp
${LOG_SOURCE_DIR}/src/ini.c
${LOG_SOURCE_DIR}/src/open_log_service.cpp
${LOG_SOURCE_DIR}/src/open_log_task.cpp)
target_compile_definitions(logservice PUBLIC LOG_SHIPPING_THREADS_NUM=${LOG_SHIPPING_THREADS_NUM})
target_include_directories(logservice PUBLIC ${LOG_INCLUDE_DIR})
target_link_libraries(logservice PUBLIC ${LOG_LIB})
if (TEST_LOG_SERVICE)
add_executable(launch_sv ${LOG_SOURCE_DIR}/src/launch_sv.cpp)
target_link_libraries(launch_sv PUBLIC logservice)
#add_executable(launch_cl ${LOG_SOURCE_DIR}/src/launch_cl.cpp)
#target_link_libraries(launch_cl PUBLIC logservice)
#
# add_executable(test_log_state_rocksdb ${LOG_SOURCE_DIR}/src/test_log_state_rocksdb.cpp)
# target_link_libraries(test_log_state_rocksdb PUBLIC logservice)
add_executable(launch_replay_service ${LOG_SOURCE_DIR}/test/launch_replay_service.cpp)
target_link_libraries(launch_replay_service PUBLIC logservice)
#add_executable(recover_time_test ${LOG_SOURCE_DIR}/test/recover_time_test.cpp)
#target_link_libraries(recover_time_test PUBLIC logservice)
#add_executable(write_log_test ${LOG_SOURCE_DIR}/test/write_log_test.cpp)
#target_link_libraries(write_log_test PUBLIC logservice)
add_executable(async_write_log_test ${LOG_SOURCE_DIR}/test/async_write_log_test.cpp)
target_link_libraries(async_write_log_test PUBLIC logservice)
if (USE_ROCKSDB_LOG_STATE)
add_executable(rocksdb_test ${LOG_SOURCE_DIR}/test/rocksdb_test.cpp)
target_link_libraries(rocksdb_test PUBLIC logservice)
if (WITH_ROCKSDB_CLOUD)
find_package(Catch2 CONFIG REQUIRED)
add_executable(log_server_rocksdb_cloud_tests ${LOG_SOURCE_DIR}/test/log_server_rocksdb_cloud_tests.cpp)
target_link_libraries(log_server_rocksdb_cloud_tests PUBLIC logservice Catch2::Catch2)
add_executable(rocksdb_cloud_delete_range_test ${LOG_SOURCE_DIR}/test/rocksdb_cloud_delete_range_test.cpp)
target_link_libraries(rocksdb_cloud_delete_range_test PUBLIC logservice Catch2::Catch2)
add_executable(write_log_test ${LOG_SOURCE_DIR}/test/write_log_test.cpp)
target_link_libraries(write_log_test PUBLIC logservice)
endif ()
endif ()
# set(TEST_PROTO_SRC ${CMAKE_CURRENT_SOURCE_DIR}/test/proto)
# set(TEST_PROTO_NAME test)
# execute_process(
# COMMAND protoc ./${TEST_PROTO_NAME}.proto --cpp_out=./ --proto_path=./
# WORKING_DIRECTORY ${TEST_PROTO_SRC}
# )
# add_library(test STATIC
# ${TEST_PROTO_SRC}/test.pb.cc
# )
# add_executable(parse_test ${LOG_SOURCE_DIR}/test/parse_performance_test.cpp)
# target_include_directories(parse_test PUBLIC ${TEST_PROTO_SRC})
# target_link_libraries(parse_test PUBLIC test ${PROTOBUF_LIBRARY} ${BRPC_LIB})
endif ()