This repository has been archived by the owner on Nov 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
/
CMakeLists.txt
201 lines (170 loc) · 7.48 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
cmake_minimum_required(VERSION 3.12.4)
project(KVDK VERSION 1.0
DESCRIPTION "A fast persistent KV engine for Persistent Memory"
LANGUAGES CXX C)
set(KVDK_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
include(${KVDK_ROOT_DIR}/cmake/functions.cmake)
include(GNUInstallDirs)
set(CMAKE_CXX_STANDARD 11)
option(COVERAGE "code coverage" OFF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx512f -mrdseed -mrdrnd -mclwb -mclflushopt")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
if (CMAKE_BUILD_TYPE STREQUAL "Release")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2")
elseif (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
elseif (CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
elseif (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer")
elseif (CMAKE_BUILD_TYPE STREQUAL "FastDebug")
set(CMAKE_CXX_FLAGS "-Wall -Wextra -g -O2 -march=native")
set(CMAKE_C_FLAGS "-Wall -Wextra -g -O2 -march=native")
else ()
message(FATAL_ERROR "Invalid build type!")
endif ()
if (CMAKE_BUILD_TYPE STREQUAL "Release")
add_compile_definitions(KVDK_DEBUG_LEVEL=0)
else ()
add_compile_definitions(KVDK_DEBUG_LEVEL=1)
add_compile_definitions(KVDK_ENABLE_CRASHPOINT)
endif ()
# code coverage
if (COVERAGE)
if(NOT ${CMAKE_BUILD_TYPE} MATCHES Debug)
message(WARNING "Code coverage results with an optimised (non-Debug) build may be misleading" )
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage -fprofile-arcs -ftest-coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -fprofile-arcs -ftest-coverage")
endif()
# source files
set(SOURCES
engine/c/kvdk_basic_op.cpp
engine/c/kvdk_batch.cpp
engine/c/kvdk_transaction.cpp
engine/c/kvdk_hash.cpp
engine/c/kvdk_list.cpp
engine/c/kvdk_sorted.cpp
engine/c/kvdk_string.cpp
engine/utils/utils.cpp
engine/utils/sync_point.cpp
engine/engine.cpp
engine/kv_engine.cpp
engine/kv_engine_cleaner.cpp
engine/kv_engine_hash.cpp
engine/kv_engine_list.cpp
engine/kv_engine_sorted.cpp
engine/kv_engine_string.cpp
engine/logger.cpp
engine/hash_table.cpp
engine/sorted_collection/skiplist.cpp
engine/sorted_collection/rebuilder.cpp
engine/hash_collection/hash_list.cpp
engine/list_collection/list.cpp
engine/write_batch_impl.cpp
engine/transaction_impl.cpp
engine/dram_allocator.cpp
engine/pmem_allocator/pmem_allocator.cpp
engine/thread_manager.cpp
engine/pmem_allocator/free_list.cpp
engine/data_record.cpp
engine/dl_list.cpp
engine/version/old_records_cleaner.cpp
)
# .so library
add_library(engine SHARED ${SOURCES})
target_include_directories(engine PUBLIC ./include ./extern)
target_link_libraries(engine PUBLIC pthread pmem gflags hwloc atomic)
configure_file(kvdk.pc.in kvdk.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kvdk.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
set(KVDK_PUBLIC_HEADERS
${PROJECT_SOURCE_DIR}/include/kvdk/comparator.hpp
${PROJECT_SOURCE_DIR}/include/kvdk/configs.hpp
${PROJECT_SOURCE_DIR}/include/kvdk/engine.h
${PROJECT_SOURCE_DIR}/include/kvdk/engine.hpp
${PROJECT_SOURCE_DIR}/include/kvdk/iterator.hpp
${PROJECT_SOURCE_DIR}/include/kvdk/write_batch.hpp
${PROJECT_SOURCE_DIR}/extern/libpmemobj++/string_view.hpp
)
set_target_properties(engine PROPERTIES PUBLIC_HEADER "${KVDK_PUBLIC_HEADERS}")
install(TARGETS engine
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/kvdk
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
# executables
add_executable(bench benchmark/bench.cpp)
target_link_libraries(bench PUBLIC engine)
target_include_directories(bench PUBLIC ./include ./extern ./)
option(BUILD_TESTING "Build the tests" OFF)
if (BUILD_TESTING)
add_subdirectory(${CMAKE_SOURCE_DIR}/extern/gtest)
add_subdirectory(tests)
endif ()
option(BUILD_TUTORIAL "Build the tutorial" OFF)
add_subdirectory(examples/tutorial)
option(BUILD_GRAPH_SIMULATOR "Build the graph simulator" OFF)
add_subdirectory(examples/graph_sim)
add_custom_target(checkers ALL)
add_custom_target(cppstyle)
add_custom_target(cppformat)
find_program(CLANG_FORMAT NAMES clang-format-9 clang-format-9.0 clang-format)
set(CLANG_FORMAT_MINIMUM_REQUIRED "9.0")
if (CLANG_FORMAT)
get_program_version_major_minor(${CLANG_FORMAT} CLANG_FORMAT_VERSION)
message(STATUS "Found clang-format: ${CLANG_FORMAT} (version: ${CLANG_FORMAT_VERSION})")
endif ()
if (CHECK_CPP_STYLE)
if (CLANG_FORMAT)
if (NOT (CLANG_FORMAT_VERSION VERSION_GREATER_EQUAL CLANG_FORMAT_MINIMUM_REQUIRED))
message(FATAL_ERROR "minimum required clang-format version is ${CCLANG_FORMAT_MINIMUM_REQUIRED}")
endif ()
else ()
message(FATAL_ERROR "CHECK_CPP_STYLE=ON, but clang-format not found (required version: ${CLANG_FORMAT_MINIMUM_REQUIRED})")
endif ()
add_dependencies(checkers cppstyle)
endif ()
add_cppstyle(src ${CMAKE_CURRENT_SOURCE_DIR}/engine/*.c*
${CMAKE_CURRENT_SOURCE_DIR}/engine/*.h*
${CMAKE_CURRENT_SOURCE_DIR}/engine/pmem_allocator/*.h*
${CMAKE_CURRENT_SOURCE_DIR}/engine/pmem_allocator/*.c*
${CMAKE_CURRENT_SOURCE_DIR}/engine/utils/*.c*
${CMAKE_CURRENT_SOURCE_DIR}/engine/utils/*.h*
${CMAKE_CURRENT_SOURCE_DIR}/examples/tutorial/*.c*
${CMAKE_CURRENT_SOURCE_DIR}/benchmark/*.c*
${CMAKE_CURRENT_SOURCE_DIR}/include/kvdk/*.h*
${CMAKE_CURRENT_SOURCE_DIR}/tests/*.c*
${CMAKE_CURRENT_SOURCE_DIR}/tests/*.h*)
option(WITH_JNI "Build with JNI" OFF)
if(WITH_JNI OR JNI)
message(STATUS "JNI library is enabled")
set(KVDK_SHARED_LIB engine)
set(KVDK_STATIC_LIB engine-static)
include(FindPackageHandleStandardArgs)
find_library(LIBPMEM_STATIC_LIB NAMES "${CMAKE_STATIC_LIBRARY_PREFIX}pmem${CMAKE_STATIC_LIBRARY_SUFFIX}")
find_package_handle_standard_args(libpmem REQUIRED_VARS LIBPMEM_STATIC_LIB)
if(NOT libpmem_FOUND)
message(FATAL_ERROR "libpmem.a not found")
endif()
find_library(ATOMIC_SHARED_LIB NAMES "${CMAKE_SHARED_LIBRARY_PREFIX}atomic${CMAKE_SHARED_LIBRARY_SUFFIX}.1")
find_package_handle_standard_args(atomic REQUIRED_VARS ATOMIC_SHARED_LIB)
if(NOT atomic_FOUND)
message(FATAL_ERROR "libatomic.so.1 not found")
endif()
find_library(STD_CPP_SHARED_LIB NAMES "${CMAKE_SHARED_LIBRARY_PREFIX}stdc++${CMAKE_SHARED_LIBRARY_SUFFIX}.6")
find_package_handle_standard_args(std_cpp REQUIRED_VARS STD_CPP_SHARED_LIB)
if(NOT std_cpp_FOUND)
message(FATAL_ERROR "libstdc++.so.6 not found")
endif()
add_library(${KVDK_STATIC_LIB} STATIC ${SOURCES})
target_include_directories(${KVDK_STATIC_LIB} PUBLIC ./include ./extern)
target_link_libraries(${KVDK_STATIC_LIB} PRIVATE ${LIBPMEM_STATIC_LIB})
target_link_libraries(${KVDK_STATIC_LIB} PRIVATE pthread gflags hwloc atomic)
set_property(TARGET ${KVDK_STATIC_LIB} PROPERTY POSITION_INDEPENDENT_CODE ON)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/java)
add_cppstyle(jni_src
${CMAKE_CURRENT_SOURCE_DIR}/java/kvdkjni/*.c*
${CMAKE_CURRENT_SOURCE_DIR}/java/kvdkjni/*.h*)
else()
message(STATUS "JNI library is disabled")
endif()