forked from pmem/pmemkv
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
390 lines (331 loc) · 11.6 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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2017-2020, Intel Corporation
cmake_minimum_required(VERSION 3.10)
project(pmemkv)
include(cmake/helpers.cmake)
set_version(VERSION)
# set the default build type
if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
set(DEFAULT_BUILD_TYPE "Debug")
else()
set(DEFAULT_BUILD_TYPE "RelWithDebInfo")
endif()
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting build type to the default one (${DEFAULT_BUILD_TYPE})")
set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}"
CACHE STRING "Choose a type of build (Debug, Release or RelWithDebInfo)" FORCE)
endif()
option(BUILD_DOC "build documentation" ON)
option(BUILD_EXAMPLES "build examples" ON)
option(BUILD_TESTS "build tests" ON)
option(BUILD_JSON_CONFIG "build the 'libpmemkv_json_config' library" ON)
option(TESTS_USE_FORCED_PMEM "run tests with PMEM_IS_PMEM_FORCE=1" OFF)
option(TESTS_USE_VALGRIND "enable tests with valgrind (if found)" ON)
option(TESTS_PMEMOBJ_DRD_HELGRIND "enable test of pmemobj engines under drd and helgrind (they should only be run on PMEM)")
option(COVERAGE "run coverage test" OFF)
if(COVERAGE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -coverage")
endif()
# Each engine can be enabled separately.
# By default all experimental engines are turned off.
option(ENGINE_CMAP "enable cmap engine" ON)
option(ENGINE_VCMAP "enable vcmap engine" ON)
option(ENGINE_VSMAP "enable vsmap engine" ON)
option(ENGINE_CACHING "enable experimental caching engine" OFF)
option(ENGINE_STREE "enable experimental stree engine" OFF)
option(ENGINE_TREE3 "enable experimental tree3 engine" OFF)
option(DEVELOPER_MODE "enable developer's checks" OFF)
option(CHECK_CPP_STYLE "check code style of C++ sources" OFF)
# Do not treat include directories from the interfaces
# of consumed Imported Targets as SYSTEM by default.
set(CMAKE_NO_SYSTEM_FROM_IMPORTED 1)
if(ENGINE_CMAP)
add_definitions(-DENGINE_CMAP)
message(STATUS "CMAP engine is ON")
else()
message(STATUS "CMAP engine is OFF")
endif()
if(ENGINE_VCMAP)
add_definitions(-DENGINE_VCMAP)
message(STATUS "VCMAP engine is ON")
else()
message(STATUS "VCMAP engine is OFF")
endif()
if(ENGINE_VSMAP)
add_definitions(-DENGINE_VSMAP)
message(STATUS "VSMAP engine is ON")
else()
message(STATUS "VSMAP engine is OFF")
endif()
if(ENGINE_CACHING)
add_definitions(-DENGINE_CACHING)
message(STATUS "CACHING engine is ON")
else()
message(STATUS "CACHING engine is OFF")
endif()
if(ENGINE_STREE)
add_definitions(-DENGINE_STREE)
message(STATUS "STREE engine is ON")
else()
message(STATUS "STREE engine is OFF")
endif()
if(ENGINE_TREE3)
add_definitions(-DENGINE_TREE3)
message(STATUS "TREE3 engine is ON")
else()
message(STATUS "TREE3 engine is OFF")
endif()
set(SOURCE_FILES
src/libpmemkv.cc
src/libpmemkv.h
src/engine.cc
src/engines/blackhole.cc
src/engines/blackhole.h
src/out.cc
src/out.h
)
# Add each engine source separately
if(ENGINE_CMAP)
list(APPEND SOURCE_FILES
src/engines/cmap.h
src/engines/cmap.cc
)
endif()
if(ENGINE_VCMAP)
list(APPEND SOURCE_FILES
src/engines/vcmap.h
src/engines/vcmap.cc
)
endif()
if(ENGINE_VSMAP)
list(APPEND SOURCE_FILES
src/engines/vsmap.h
src/engines/vsmap.cc
)
endif()
if(ENGINE_CACHING)
list(APPEND SOURCE_FILES
src/engines-experimental/caching.h
src/engines-experimental/caching.cc
)
endif()
if(ENGINE_STREE)
list(APPEND SOURCE_FILES
src/engines-experimental/stree.h
src/engines-experimental/stree.cc
src/engines-experimental/stree/persistent_b_tree.h
src/engines-experimental/stree/pstring.h
)
endif()
if(ENGINE_TREE3)
list(APPEND SOURCE_FILES
src/engines-experimental/tree3.h
src/engines-experimental/tree3.cc
)
endif()
set(CXX_STANDARD 11 CACHE STRING "C++ language standard")
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD ${CXX_STANDARD})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
set(LIBPMEMOBJ_CPP_REQUIRED_VERSION 1.9)
set(LIBPMEMOBJ_REQUIRED_VERSION 1.8)
set(LIBPMEM_REQUIRED_VERSION 1.7)
set(MEMKIND_REQUIRED_VERSION 1.8.0)
if(DEVELOPER_MODE)
add_common_flag(-Werror)
endif()
add_common_flag(-Wall)
add_common_flag(-Wpointer-arith)
add_common_flag(-Wsign-compare)
add_common_flag(-Wunreachable-code-return)
add_common_flag(-Wmissing-variable-declarations)
add_common_flag(-fno-common)
add_common_flag(-Wunused-macros)
add_common_flag(-Wsign-conversion)
add_common_flag(-ggdb DEBUG)
add_common_flag(-DDEBUG DEBUG)
add_common_flag("-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2" RELEASE)
find_package(PkgConfig QUIET)
include(FindPerl)
include(ExternalProject)
include(FindThreads)
include(CheckCXXSourceCompiles)
include(GNUInstallDirs)
set(PKG_CONFIG_REQUIRES)
set(DEB_DEPENDS)
set(RPM_DEPENDS)
if(ENGINE_VSMAP OR ENGINE_VCMAP OR ENGINE_CMAP OR ENGINE_STREE OR ENGINE_TREE3)
include(libpmemobj++)
list(APPEND PKG_CONFIG_REQUIRES "libpmemobj++ >= ${LIBPMEMOBJ_CPP_REQUIRED_VERSION}")
list(APPEND RPM_DEPENDS "libpmemobj >= ${LIBPMEMOBJ_REQUIRED_VERSION}")
list(APPEND DEB_DEPENDS "libpmemobj1 (>= ${LIBPMEMOBJ_REQUIRED_VERSION}) | libpmemobj (>= ${LIBPMEMOBJ_REQUIRED_VERSION})")
endif()
if(ENGINE_VSMAP OR ENGINE_VCMAP)
include(memkind)
list(APPEND PKG_CONFIG_REQUIRES "memkind >= ${MEMKIND_REQUIRED_VERSION}")
list(APPEND RPM_DEPENDS "memkind >= ${MEMKIND_REQUIRED_VERSION}")
list(APPEND DEB_DEPENDS "libmemkind0 (>= ${MEMKIND_REQUIRED_VERSION})")
endif()
if(ENGINE_VCMAP)
include(tbb)
list(APPEND PKG_CONFIG_REQUIRES tbb)
list(APPEND RPM_DEPENDS tbb)
list(APPEND DEB_DEPENDS libtbb2)
endif()
if(ENGINE_CACHING)
include(memcached-experimental)
include(redis-experimental)
list(APPEND PKG_CONFIG_REQUIRES libmemcached)
list(APPEND RPM_DEPENDS libmemcached)
list(APPEND DEB_DEPENDS libmemcached11)
endif()
string(REPLACE ";" " " PKG_CONFIG_REQUIRES "${PKG_CONFIG_REQUIRES}")
string(REPLACE ";" ", " RPM_PACKAGE_REQUIRES "${RPM_DEPENDS}")
string(REPLACE ";" ", " DEB_PACKAGE_REQUIRES "${DEB_DEPENDS}")
add_custom_target(checkers ALL)
add_custom_target(cppstyle)
add_custom_target(cppformat)
add_custom_target(check-whitespace)
add_custom_target(check-license
COMMAND ${CMAKE_SOURCE_DIR}/utils/check_license/check-headers.sh
${CMAKE_SOURCE_DIR}
BSD-3-Clause)
add_custom_target(check-whitespace-main
COMMAND ${PERL_EXECUTABLE}
${CMAKE_SOURCE_DIR}/utils/check_whitespace
${CMAKE_SOURCE_DIR}/utils/check_license/*.sh
${CMAKE_SOURCE_DIR}/*.md)
add_dependencies(check-whitespace check-whitespace-main)
if(CHECK_CPP_STYLE)
find_program(CLANG_FORMAT NAMES clang-format clang-format-9.0)
set(CLANG_FORMAT_REQUIRED "9.0")
if(CLANG_FORMAT)
get_program_version_major_minor(${CLANG_FORMAT} CLANG_FORMAT_VERSION)
if(NOT (CLANG_FORMAT_VERSION VERSION_EQUAL CLANG_FORMAT_REQUIRED))
message(FATAL_ERROR "required clang-format version is ${CLANG_FORMAT_REQUIRED} (version ${CLANG_FORMAT_VERSION} is installed)")
endif()
else()
message(WARNING "clang-format not found - C++ sources will not be checked (required version: ${CLANG_FORMAT_REQUIRED})")
endif()
endif()
if(DEVELOPER_MODE)
if(NOT PERL_FOUND)
message(FATAL_ERROR "Perl not found")
endif()
if (PERL_VERSION_STRING VERSION_LESS 5.16)
message(FATAL_ERROR "Minimum required version of Perl is 5.16)")
endif()
execute_process(COMMAND ${PERL_EXECUTABLE} -MText::Diff -e ""
ERROR_QUIET
RESULT_VARIABLE PERL_TEXT_DIFF_STATUS)
if (PERL_TEXT_DIFF_STATUS)
message(FATAL_ERROR "Text::Diff Perl module not found (install libtext-diff-perl or perl-Text-Diff)")
endif()
add_dependencies(checkers cppstyle)
add_dependencies(checkers check-whitespace)
add_dependencies(checkers check-license)
endif()
add_library(pmemkv SHARED ${SOURCE_FILES})
set_target_properties(pmemkv PROPERTIES SOVERSION 1)
target_link_libraries(pmemkv PRIVATE
-Wl,--version-script=${CMAKE_SOURCE_DIR}/src/libpmemkv.map)
if(ENGINE_VSMAP OR ENGINE_VCMAP OR ENGINE_CMAP OR ENGINE_STREE OR ENGINE_TREE3)
target_link_libraries(pmemkv PRIVATE ${LIBPMEMOBJ++_LIBRARIES})
endif()
if(ENGINE_VSMAP OR ENGINE_VCMAP)
target_link_libraries(pmemkv PRIVATE ${MEMKIND_LIBRARIES})
endif()
if(ENGINE_VCMAP)
target_link_libraries(pmemkv PRIVATE ${TBB_LIBRARIES})
endif()
if(ENGINE_CACHING)
target_link_libraries(pmemkv PRIVATE ${CMAKE_THREAD_LIBS_INIT} memcached)
target_link_libraries(pmemkv PRIVATE acl_cpp protocol acl)
endif()
target_include_directories(pmemkv PRIVATE src/valgrind)
# Enable libpmemobj-cpp valgrind annotations
target_compile_options(pmemkv PRIVATE -DLIBPMEMOBJ_CPP_VG_ENABLED=1)
set(TEST_DIR ${CMAKE_CURRENT_BINARY_DIR}/test
CACHE STRING "working directory for tests")
if(BUILD_TESTS)
if(PKG_CONFIG_FOUND)
pkg_check_modules(VALGRIND QUIET valgrind)
else()
find_package(VALGRIND QUIET)
endif()
if(NOT VALGRIND_FOUND AND TESTS_USE_VALGRIND)
message(FATAL_ERROR "Valgrind not found, but flag TESTS_USE_VALGRIND was set.")
endif()
if(VALGRIND_FOUND)
find_pmemcheck()
endif()
if(PKG_CONFIG_FOUND)
pkg_check_modules(LIBPMEMOBJ REQUIRED libpmemobj>=${LIBPMEMOBJ_REQUIRED_VERSION})
pkg_check_modules(LIBPMEM REQUIRED libpmem>=${LIBPMEM_REQUIRED_VERSION})
else()
find_package(LIBPMEMOBJ REQUIRED ${LIBPMEMOBJ_REQUIRED_VERSION})
find_package(LIBPMEM REQUIRED ${LIBPMEM_REQUIRED_VERSION})
endif()
enable_testing()
add_subdirectory(tests)
endif()
configure_file(libpmemkv.pc.in libpmemkv.pc @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/libpmemkv.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
set_target_properties(pmemkv PROPERTIES PUBLIC_HEADER "src/libpmemkv.h;src/libpmemkv.hpp")
if(BUILD_DOC)
add_subdirectory(doc)
endif()
install(TARGETS pmemkv
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
if(BUILD_JSON_CONFIG)
include(rapidjson)
add_definitions(-DBUILD_JSON_CONFIG)
set(SOURCE_FILES_JSON_CONFIG
src/libpmemkv_json_config.cc
src/libpmemkv_json_config.h
src/out.cc
src/out.h
)
add_library(pmemkv_json_config SHARED ${SOURCE_FILES_JSON_CONFIG})
set_target_properties(pmemkv_json_config PROPERTIES SOVERSION 1)
target_link_libraries(pmemkv_json_config PRIVATE pmemkv ${RapidJSON_LIBRARIES}
-Wl,--version-script=${CMAKE_SOURCE_DIR}/src/libpmemkv_json_config.map)
set_target_properties(pmemkv_json_config
PROPERTIES PUBLIC_HEADER "src/libpmemkv_json_config.h")
configure_file(libpmemkv_json_config.pc.in libpmemkv_json_config.pc @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/libpmemkv_json_config.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
install(TARGETS pmemkv_json_config
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
configure_file(
"${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
add_cppstyle(src ${CMAKE_CURRENT_SOURCE_DIR}/src/*.c*
${CMAKE_CURRENT_SOURCE_DIR}/src/*.h*
${CMAKE_CURRENT_SOURCE_DIR}/src/engines/*.c*
${CMAKE_CURRENT_SOURCE_DIR}/src/engines/*.h*
${CMAKE_CURRENT_SOURCE_DIR}/src/engines-experimental/*.c*
${CMAKE_CURRENT_SOURCE_DIR}/src/engines-experimental/*.h*
${CMAKE_CURRENT_SOURCE_DIR}/src/engines-experimental/stree/*.h*)
add_check_whitespace(src ${CMAKE_CURRENT_SOURCE_DIR}/src/*.c*
${CMAKE_CURRENT_SOURCE_DIR}/src/*.h*
${CMAKE_CURRENT_SOURCE_DIR}/src/engines/*.c*
${CMAKE_CURRENT_SOURCE_DIR}/src/engines/*.h*
${CMAKE_CURRENT_SOURCE_DIR}/src/engines-experimental/*.c*
${CMAKE_CURRENT_SOURCE_DIR}/src/engines-experimental/*.h*
${CMAKE_CURRENT_SOURCE_DIR}/src/engines-experimental/stree/*.h*)
if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
if(NOT "${CPACK_GENERATOR}" STREQUAL "")
include(${CMAKE_SOURCE_DIR}/cmake/packages.cmake)
endif()