-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
316 lines (274 loc) · 12.4 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
# Copyright 2018 The HyperPebblesDB Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. See the AUTHORS file for names of contributors.
cmake_minimum_required(VERSION 3.9)
project(PebblesDB VERSION 1.21.0 LANGUAGES C CXX)
# This project requires C++20
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Setup the options that CMake can take in
option(PEBBLESDB_INSTALL "Install PebblesDB's header and library" OFF)
option(PEBBLESDB_BUILD_TESTS "Build PeblesDB's unit tests" ON)
# 1: LSM_Secondary_Index 2: LSM_SI_PM
# 3: P-Masstree-perseid 4: P-Masstree-composite 5: P-Masstree-log
# 6: FAST_FAIR-perseid 7: FAST_FAIR-composite 8: FAST_FAIR-log
set(SEC_IDX_TYPE 3 CACHE STRING "Secondary Index Type")
message(STATUS "SET SEC_IDX_TYPE ${SEC_IDX_TYPE}")
set(VALIDATE true CACHE STRING "kUsingValidation")
message(STATUS "SET VALIDATE ${VALIDATE}")
set(PRUNE_SEQ true CACHE STRING "kPruneComponentsBySeq")
message(STATUS "SET PRUNE_SEQ ${PRUNE_SEQ}")
set(PAL_PDB false CACHE STRING "kParallelGetPDB")
message(STATUS "SET PAL_PDB ${PAL_PDB}")
set(IDX_ONLY true CACHE STRING "kIndexOnlyQuery")
message(STATUS "SET IDX_ONLY ${IDX_ONLY}")
set(LSMSI_SYNC false CACHE STRING "kLSMSync")
message(STATUS "SET LSMSI_SYNC ${LSMSI_SYNC}")
configure_file(
"${PROJECT_SOURCE_DIR}/src/db/sec_idx/sec_idx_config.h.in"
"${PROJECT_SOURCE_DIR}/src/db/sec_idx/sec_idx_config.h"
)
# Setup the basic C++ Compiler flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wno-variadic-macros -Wno-sign-compare -Wno-unused-function -faligned-new")
message(STATUS "CMAKE_SOURCE_DIR: " ${CMAKE_SOURCE_DIR})
set(PROJECT_SOURCE_DIR "${PROJECT_SOURCE_DIR}/src")
message(STATUS "PROJECT_SOURCE_DIR: " ${PROJECT_SOURCE_DIR})
# need to let "port_posix.h" to include "config.h"
add_definitions(-DHAVE_CONFIG_H)
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG(-fno-builtin-memcmp COMPILER_SUPPORTS_MEMCMP)
CHECK_CXX_COMPILER_FLAG(-fno-builtin-memmove COMPILER_SUPPORTS_MEMMOVE)
CHECK_CXX_COMPILER_FLAG(-Qunused-arguments COMPILER_SUPPORTS_UNUSED_ARGS)
if (COMPILER_SUPPORTS_MEMCMP)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-builtin-memcmp")
endif (COMPILER_SUPPORTS_MEMCMP)
if (COMPILER_SUPPORTS_MEMMOVE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-builtin-memmove")
endif (COMPILER_SUPPORTS_MEMMOVE)
if (COMPILER_SUPPORTS_UNUSED_ARGS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments")
endif (COMPILER_SUPPORTS_UNUSED_ARGS)
# variable name (e.g. HAVE_ENDIAN_H) matches "port/port_posix.h"
include(CheckIncludeFile)
check_include_file("endian.h" HAVE_ENDIAN_H)
check_include_file("machine/endian.h" HAVE_MACHINE_ENDIAN_H)
check_include_file("sys/endian.h" HAVE_SYS_ENDIAN_H)
check_include_file("sys/isa_defs.h" HAVE_SYS_ISA_DEFS_H)
check_include_file("sys/types.h" HAVE_SYS_TYPES_H)
check_include_file("dlfcn.h" HAVE_DLFCN_H)
check_include_file("inttypes.h" HAVE_INTTYPES_H)
check_include_file("memory.h" HAVE_MEMORY_H)
check_include_file("stdint.h" HAVE_STDINT_H)
check_include_file("stdlib.h" HAVE_STDLIB_H)
check_include_file("strings.h" HAVE_STRINGS_H)
check_include_file("string.h" HAVE_STRING_H)
check_include_file("sys/param.h" HAVE_SYS_PARAM_H)
check_include_file("sys/stat.h" HAVE_SYS_STAT_H)
check_include_file("unistd.h" HAVE_UNISTD_H)
include(CheckFunctionExists)
macro(check_function_exists_in_batch name_list)
foreach (arg ${ARGV})
LIST(APPEND ListNames ${arg})
endforeach ()
foreach (name ${ListNames})
string(TOUPPER ${name} allcap)
string(CONCAT var_name HAVE_ ${allcap})
check_function_exists(${name} ${var_name})
endforeach ()
endmacro()
check_function_exists_in_batch(
error_at_line mmap alarm clock_gettime mach_absolute_time ftruncate fsync
fread fread_unlocked fwrite fwrite_unlocked fflush
fflush_unlocked memmove mkdir munmap rmdir socket getpagesize)
include(CheckSymbolExists)
check_symbol_exists(fdatasync "unistd.h" HAVE_DECL_FDATASYNC)
include(CheckLibraryExists)
check_library_exists(crc32c crc32c_value "" HAVE_CRC32C)
check_library_exists(snappy snappy_compress "" HAVE_SNAPPY)
check_library_exists(tcmalloc malloc "" HAVE_TCMALLOC)
set(PEBBLESDB_PUBLIC_INCLUDE_DIR "include/pebblesdb")
configure_file(
"${PROJECT_SOURCE_DIR}/config.h.in.forcmake"
"${PROJECT_SOURCE_DIR}/config.h"
)
include_directories(
"${PROJECT_SOURCE_DIR}/include"
"${PROJECT_SOURCE_DIR}"
)
add_library(pebblesdb "")
target_sources(pebblesdb
PRIVATE
"${PROJECT_SOURCE_DIR}/db/builder.cc"
"${PROJECT_SOURCE_DIR}/db/c.cc"
"${PROJECT_SOURCE_DIR}/db/dbformat.cc"
"${PROJECT_SOURCE_DIR}/db/db_impl.cc"
"${PROJECT_SOURCE_DIR}/db/db_iter.cc"
"${PROJECT_SOURCE_DIR}/db/filename.cc"
"${PROJECT_SOURCE_DIR}/db/log_reader.cc"
"${PROJECT_SOURCE_DIR}/db/log_writer.cc"
"${PROJECT_SOURCE_DIR}/db/memtable.cc"
"${PROJECT_SOURCE_DIR}/db/murmurhash3.cc"
"${PROJECT_SOURCE_DIR}/db/repair.cc"
"${PROJECT_SOURCE_DIR}/db/replay_iterator.cc"
"${PROJECT_SOURCE_DIR}/db/table_cache.cc"
"${PROJECT_SOURCE_DIR}/db/version_edit.cc"
"${PROJECT_SOURCE_DIR}/db/version_set.cc"
"${PROJECT_SOURCE_DIR}/db/write_batch.cc"
"${PROJECT_SOURCE_DIR}/table/block_builder.cc"
"${PROJECT_SOURCE_DIR}/table/block.cc"
"${PROJECT_SOURCE_DIR}/table/filter_block.cc"
"${PROJECT_SOURCE_DIR}/table/format.cc"
"${PROJECT_SOURCE_DIR}/table/iterator.cc"
"${PROJECT_SOURCE_DIR}/table/merger.cc"
"${PROJECT_SOURCE_DIR}/table/table_builder.cc"
"${PROJECT_SOURCE_DIR}/table/table.cc"
"${PROJECT_SOURCE_DIR}/table/two_level_iterator.cc"
"${PROJECT_SOURCE_DIR}/util/arena.cc"
"${PROJECT_SOURCE_DIR}/util/atomic.cc"
"${PROJECT_SOURCE_DIR}/util/bloom.cc"
"${PROJECT_SOURCE_DIR}/util/cache.cc"
"${PROJECT_SOURCE_DIR}/util/coding.cc"
"${PROJECT_SOURCE_DIR}/util/comparator.cc"
"${PROJECT_SOURCE_DIR}/util/crc32c.cc"
"${PROJECT_SOURCE_DIR}/util/env.cc"
"${PROJECT_SOURCE_DIR}/util/env_posix.cc"
"${PROJECT_SOURCE_DIR}/util/filter_policy.cc"
"${PROJECT_SOURCE_DIR}/util/hash.cc"
"${PROJECT_SOURCE_DIR}/util/histogram.cc"
"${PROJECT_SOURCE_DIR}/util/logging.cc"
"${PROJECT_SOURCE_DIR}/util/options.cc"
"${PROJECT_SOURCE_DIR}/util/status.cc"
"${PROJECT_SOURCE_DIR}/port/port_posix.cc"
"${PROJECT_SOURCE_DIR}/db/sec_idx/CCEH/CCEH_MSB.cpp"
"${PROJECT_SOURCE_DIR}/db/sec_idx/clht/clht_lb_res.cc"
)
if (SEC_IDX_TYPE EQUAL 3) # MASSTREE
target_sources(pebblesdb
PRIVATE
"${PROJECT_SOURCE_DIR}/db/sec_idx/P-Masstree/masstree.cpp"
"${PROJECT_SOURCE_DIR}/db/sec_idx/P-Masstree/Epoche.cpp"
)
elseif (SEC_IDX_TYPE EQUAL 4)
target_sources(pebblesdb
PRIVATE
"${PROJECT_SOURCE_DIR}/db/sec_idx/P-Masstree-composite/masstree.cpp"
"${PROJECT_SOURCE_DIR}/db/sec_idx/P-Masstree-composite/Epoche.cpp"
)
elseif (SEC_IDX_TYPE EQUAL 5)
target_sources(pebblesdb
PRIVATE
"${PROJECT_SOURCE_DIR}/db/sec_idx/P-Masstree-log/masstree.cpp"
"${PROJECT_SOURCE_DIR}/db/sec_idx/P-Masstree-log/Epoche.cpp"
)
elseif (SEC_IDX_TYPE EQUAL 6)
target_sources(pebblesdb
PRIVATE
"${PROJECT_SOURCE_DIR}/db/sec_idx/FAST_FAIR/ff_btree.cc"
)
elseif (SEC_IDX_TYPE EQUAL 7)
target_sources(pebblesdb
PRIVATE
"${PROJECT_SOURCE_DIR}/db/sec_idx/FAST_FAIR-composite/ff_btree.cc"
)
elseif (SEC_IDX_TYPE EQUAL 8)
target_sources(pebblesdb
PRIVATE
"${PROJECT_SOURCE_DIR}/db/sec_idx/FAST_FAIR-log/ff_btree.cc"
)
endif()
target_compile_definitions(pebblesdb
PRIVATE
# Used by port/port.h.
LEVELDB_PLATFORM_POSIX=1
)
if (HAVE_SNAPPY)
target_link_libraries(pebblesdb snappy)
endif (HAVE_SNAPPY)
# Locate the pthread library
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(pebblesdb Threads::Threads)
target_link_libraries(pebblesdb pmem tbb)
find_package(gflags REQUIRED)
message(STATUS "C++ flags: " ${CMAKE_CXX_FLAGS})
if (PEBBLESDB_BUILD_TESTS)
enable_testing()
function(pebblesdb_test test_file)
get_filename_component(test_target_name "${test_file}" NAME_WE)
add_executable("${test_target_name}" "")
target_sources("${test_target_name}"
PRIVATE
"${PROJECT_SOURCE_DIR}/util/testharness.cc"
"${PROJECT_SOURCE_DIR}/util/testharness.h"
"${PROJECT_SOURCE_DIR}/util/testutil.cc"
"${PROJECT_SOURCE_DIR}/util/testutil.h"
"${test_file}"
)
target_link_libraries("${test_target_name}" pebblesdb)
target_compile_definitions("${test_target_name}"
PRIVATE
LEVELDB_PLATFORM_POSIX=1
)
add_test(NAME "${test_target_name}" COMMAND "${test_target_name}")
endfunction(pebblesdb_test)
pebblesdb_test("${PROJECT_SOURCE_DIR}/db/autocompact_test.cc")
pebblesdb_test("${PROJECT_SOURCE_DIR}/util/arena_test.cc")
pebblesdb_test("${PROJECT_SOURCE_DIR}/util/bloom_test.cc")
pebblesdb_test("${PROJECT_SOURCE_DIR}/db/c_test.c")
pebblesdb_test("${PROJECT_SOURCE_DIR}/util/cache_test.cc")
pebblesdb_test("${PROJECT_SOURCE_DIR}/util/coding_test.cc")
pebblesdb_test("${PROJECT_SOURCE_DIR}/db/corruption_test.cc")
pebblesdb_test("${PROJECT_SOURCE_DIR}/util/crc32c_test.cc")
pebblesdb_test("${PROJECT_SOURCE_DIR}/db/db_test.cc")
pebblesdb_test("${PROJECT_SOURCE_DIR}/db/dbformat_test.cc")
pebblesdb_test("${PROJECT_SOURCE_DIR}/util/env_test.cc")
pebblesdb_test("${PROJECT_SOURCE_DIR}/db/filename_test.cc")
pebblesdb_test("${PROJECT_SOURCE_DIR}/table/filter_block_test.cc")
pebblesdb_test("${PROJECT_SOURCE_DIR}/db/log_test.cc")
pebblesdb_test("${PROJECT_SOURCE_DIR}/table/table_test.cc")
pebblesdb_test("${PROJECT_SOURCE_DIR}/db/skiplist_test.cc")
pebblesdb_test("${PROJECT_SOURCE_DIR}/db/version_edit_test.cc")
pebblesdb_test("${PROJECT_SOURCE_DIR}/db/version_set_test.cc")
pebblesdb_test("${PROJECT_SOURCE_DIR}/db/write_batch_test.cc")
pebblesdb_test("${PROJECT_SOURCE_DIR}/issues/issue178_test.cc")
pebblesdb_test("${PROJECT_SOURCE_DIR}/issues/issue200_test.cc")
pebblesdb_test("${PROJECT_SOURCE_DIR}/demo/installation_test.cc")
pebblesdb_test("${PROJECT_SOURCE_DIR}/db/db_bench.cc")
pebblesdb_test("${PROJECT_SOURCE_DIR}/db/sec_idx_bench.cc")
# pebblesdb_test("${PROJECT_SOURCE_DIR}/db/sec_idx_test_mt.cc")
target_link_libraries(sec_idx_bench gflags)
endif (PEBBLESDB_BUILD_TESTS)
if(PEBBLESDB_INSTALL)
include(GNUInstallDirs)
install(TARGETS pebblesdb
EXPORT pebblesdbTargets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(
FILES
"${PROJECT_SOURCE_DIR}/${PEBBLESDB_PUBLIC_INCLUDE_DIR}/c.h"
"${PROJECT_SOURCE_DIR}/${PEBBLESDB_PUBLIC_INCLUDE_DIR}/cache.h"
"${PROJECT_SOURCE_DIR}/${PEBBLESDB_PUBLIC_INCLUDE_DIR}/comparator.h"
"${PROJECT_SOURCE_DIR}/${PEBBLESDB_PUBLIC_INCLUDE_DIR}/db.h"
"${PROJECT_SOURCE_DIR}/${PEBBLESDB_PUBLIC_INCLUDE_DIR}/env.h"
"${PROJECT_SOURCE_DIR}/${PEBBLESDB_PUBLIC_INCLUDE_DIR}/filter_policy.h"
"${PROJECT_SOURCE_DIR}/${PEBBLESDB_PUBLIC_INCLUDE_DIR}/iterator.h"
"${PROJECT_SOURCE_DIR}/${PEBBLESDB_PUBLIC_INCLUDE_DIR}/options.h"
"${PROJECT_SOURCE_DIR}/${PEBBLESDB_PUBLIC_INCLUDE_DIR}/slice.h"
"${PROJECT_SOURCE_DIR}/${PEBBLESDB_PUBLIC_INCLUDE_DIR}/replay_iterator.h"
"${PROJECT_SOURCE_DIR}/${PEBBLESDB_PUBLIC_INCLUDE_DIR}/status.h"
"${PROJECT_SOURCE_DIR}/${PEBBLESDB_PUBLIC_INCLUDE_DIR}/table_builder.h"
"${PROJECT_SOURCE_DIR}/${PEBBLESDB_PUBLIC_INCLUDE_DIR}/table.h"
"${PROJECT_SOURCE_DIR}/${PEBBLESDB_PUBLIC_INCLUDE_DIR}/write_batch.h"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/pebblesdb
)
endif(PEBBLESDB_INSTALL)
# Print out all the CMake variables
get_cmake_property(_variableNames VARIABLES)
list (SORT _variableNames)
foreach (_variableName ${_variableNames})
message(STATUS "${_variableName}=${${_variableName}}")
endforeach()