This repository has been archived by the owner on Mar 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
CMakeLists.txt
293 lines (249 loc) · 10.2 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
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2018-2023, Intel Corporation
cmake_minimum_required(VERSION 3.16)
project(pmemstream C CXX)
set(PMEMSTREAM_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
include(${PMEMSTREAM_ROOT_DIR}/cmake/functions.cmake)
# ----------------------------------------------------------------- #
## Set required and useful variables
# ----------------------------------------------------------------- #
set(VERSION_MAJOR 0)
set(VERSION_MINOR 2)
set(VERSION_PATCH 1)
# after release it's set to "devel" for package naming (when 'git' is not available)
set(VERSION_PRERELEASE devel)
# XXX: do we need "VERSION" at all?
set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
if(VERSION_PRERELEASE)
set(VERSION ${VERSION}-${VERSION_PRERELEASE})
endif()
# set SRCVERSION, it's more accurate and "current" than VERSION
set_source_ver()
message(STATUS "pmemstream version: ${VERSION} (source ver: ${SRCVERSION})")
set(C_STANDARD 11 CACHE STRING "C language standard")
set(C_STANDARD_REQUIRED ON)
set(CMAKE_C_STANDARD ${C_STANDARD})
set(CXX_STANDARD 17 CACHE STRING "C++ language standard")
set(CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD ${CXX_STANDARD})
# Specify and print the build type
set(DEFAULT_BUILD_TYPE "RelWithDebInfo")
set(predefined_build_types
Debug
Release
RelWithDebInfo
MinSizeRel)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE ${DEFAULT_BUILD_TYPE}
CACHE STRING "choose the type of build (${predefined_build_types})" FORCE)
message(STATUS "CMAKE_BUILD_TYPE not set, setting the default one: ${CMAKE_BUILD_TYPE}")
else()
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
if(NOT CMAKE_BUILD_TYPE IN_LIST predefined_build_types)
message(WARNING "Unusual build type was set, please make sure it's proper one. "
"By default supported are only following: ${predefined_build_types}.")
endif()
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PMEMSTREAM_ROOT_DIR}/cmake)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
set(LIBPMEM2_REQUIRED_VERSION 1.10)
set(MINIASYNC_REQUIRED_VERSION 0.1.0)
# Only pmreorder in ver. >= 1.9 guarantees reliable output
set(PMREORDER_REQUIRED_VERSION 1.9)
set(PKG_CONFIG_REQUIRES)
set(DEB_DEPENDS)
set(RPM_DEPENDS)
set(TEST_DIR ${CMAKE_CURRENT_BINARY_DIR}/tests CACHE STRING "working directory for tests")
message(STATUS "TEST_DIR set to: \"${TEST_DIR}\"")
# Do not treat include directories from the interfaces
# of consumed Imported Targets as SYSTEM by default.
set(CMAKE_NO_SYSTEM_FROM_IMPORTED 1)
# ----------------------------------------------------------------- #
## CMake build options
# ----------------------------------------------------------------- #
option(BUILD_EXAMPLES "build examples" ON)
option(BUILD_TESTS "build tests" ON)
option(BUILD_DOC "build documentation" ON)
option(BUILD_BENCHMARKS "build benchmarks" OFF)
option(USE_CCACHE "use ccache if it is available in the system" ON)
option(COVERAGE "enable collecting of coverage data" OFF)
option(DEVELOPER_MODE "enable developer checks" OFF)
option(CHECK_CPP_STYLE "check code style of C++ sources" OFF)
option(TRACE_TESTS "more verbose test outputs" OFF)
option(ENABLE_FORTIFY_3 "enable increased (3rd) level of FORTIFY_SOURCE compiler flag" OFF)
option(USE_LIBUNWIND "use libunwind for more reliable stack traces from tests (it's disabled when running on Valgrind)" ON)
option(USE_ASAN "enable AddressSanitizer checks" OFF)
option(USE_UBSAN "enable UndefinedBehaviorSanitizer checks" OFF)
option(USE_TSAN "enable ThreadSanitizer checks" OFF)
option(TESTS_USE_FORCED_PMEM "run tests with PMEM2_FORCE_GRANULARITY=CACHE_LINE - it speeds up tests execution on emulated pmem" OFF)
option(TESTS_USE_VALGRIND "enable tests with valgrind (fail build if Valgrind not found)" ON)
option(TESTS_PMREORDER "enable tests with pmreorder (if pmreorder found; it requires PMDK ver. >= 1.9)" OFF)
option(TESTS_LONG "enable long running tests" OFF)
option(TESTS_RAPIDCHECK "enable rapidcheck tests" ON)
# ----------------------------------------------------------------- #
## Setup environment, find packages, set compiler's flags,
## add additional custom targets, ...
# ----------------------------------------------------------------- #
include(CMakeDependentOption)
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
# set it up only within the source dir (and its own CMake file) ?
#include(CheckCSourceCompiles)
include(FindThreads)
if(NOT WIN32)
find_package(PkgConfig QUIET)
endif()
# all our components require libpmem2 and libminiasync
if(PKG_CONFIG_FOUND)
pkg_check_modules(LIBPMEM2 REQUIRED libpmem2>=${LIBPMEM2_REQUIRED_VERSION})
else()
find_package(LIBPMEM2 REQUIRED ${LIBPMEM2_REQUIRED_VERSION})
endif()
include_directories(${LIBPMEM2_INCLUDE_DIRS})
link_directories(${LIBPMEM2_LIBRARY_DIRS})
list(APPEND PKG_CONFIG_REQUIRES "libpmem2 >= ${LIBPMEM2_REQUIRED_VERSION}")
list(APPEND RPM_DEPENDS "libpmem2-devel >= ${LIBPMEM2_REQUIRED_VERSION}")
list(APPEND DEB_DEPENDS "libpmem2-dev(>= ${LIBPMEM2_REQUIRED_VERSION})")
if(PKG_CONFIG_FOUND)
pkg_check_modules(MINIASYNC REQUIRED libminiasync>=${MINIASYNC_REQUIRED_VERSION})
else()
find_package(MINIASYNC REQUIRED ${MINIASYNC_REQUIRED_VERSION})
endif()
include_directories(${MINIASYNC_INCLUDE_DIRS})
link_directories(${MINIASYNC_LIBRARY_DIRS})
list(APPEND PKG_CONFIG_REQUIRES "libminiasync >= ${MINIASYNC_REQUIRED_VERSION}")
list(APPEND RPM_DEPENDS "libminiasync-devel >= ${MINIASYNC_REQUIRED_VERSION}")
list(APPEND DEB_DEPENDS "libminiasync-dev(>= ${MINIASYNC_REQUIRED_VERSION})")
# Configure the ccache as compiler launcher
find_program(CCACHE_FOUND ccache)
if(USE_CCACHE AND CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
endif()
if(USE_ASAN)
add_sanitizer_flag(address)
endif()
if(USE_UBSAN)
add_sanitizer_flag(undefined)
endif()
if(USE_TSAN)
if (USE_LIBUNWIND)
message(FATAL_ERROR "Cannot use TSAN and UNWIND. TSAN reports errors in signal handler.")
endif()
add_common_flag(-DPMEMSTREAM_USE_TSAN=1)
add_sanitizer_flag(thread)
endif()
if(COVERAGE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -coverage")
endif()
add_common_flag(-Wall)
add_common_flag(-Wmissing-variable-declarations)
add_common_flag(-Wpointer-arith)
add_common_flag(-Wsign-conversion)
add_common_flag(-Wsign-compare)
add_common_flag(-Wunreachable-code-return)
add_common_flag(-Wunused-macros)
add_common_flag(-Wno-maybe-uninitialized)
add_common_flag(-fno-common)
add_common_flag(-ggdb DEBUG)
add_common_flag(-DDEBUG DEBUG)
if(ENABLE_FORTIFY_3)
add_common_flag("-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3" RELEASE)
else()
add_common_flag("-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2" RELEASE)
endif()
add_custom_target(checkers ALL)
add_custom_target(cppstyle)
add_custom_target(cppformat)
add_custom_target(check-whitespace)
add_custom_target(check-license
COMMAND ${PMEMSTREAM_ROOT_DIR}/utils/check_license/check-headers.sh
${PMEMSTREAM_ROOT_DIR}
BSD-3-Clause -v)
add_custom_target(copyright-format
COMMAND ${PMEMSTREAM_ROOT_DIR}/utils/check_license/check-headers.sh
${PMEMSTREAM_ROOT_DIR}
BSD-3-Clause -d)
# XXX: consider checking code formatting only for patches (not to re-format the whole repository)
if(CHECK_CPP_STYLE)
find_program(CLANG_FORMAT NAMES clang-format-11 clang-format-11.0 clang-format)
set(CLANG_FORMAT_REQUIRED "11.1")
if(CLANG_FORMAT)
get_program_version_major_minor(${CLANG_FORMAT} CLANG_FORMAT_VERSION)
message(STATUS "Found clang-format: ${CLANG_FORMAT} (version: ${CLANG_FORMAT_VERSION})")
if(NOT (CLANG_FORMAT_VERSION VERSION_EQUAL CLANG_FORMAT_REQUIRED))
message(FATAL_ERROR "required clang-format version is ${CLANG_FORMAT_REQUIRED}")
endif()
else()
message(FATAL_ERROR "CHECK_CPP_STYLE=ON, but clang-format not found (required version: ${CLANG_FORMAT_REQUIRED})")
endif()
add_dependencies(checkers cppstyle)
endif()
if(DEVELOPER_MODE)
# treat compiler warnings as errors
if(WIN32)
add_common_flag(-WX)
else()
add_common_flag(-Werror)
# check for required programs for whitespace and license checks and add dependencies to ALL
include(FindPerl)
if(NOT PERL_FOUND)
message(FATAL_ERROR "Perl not found")
endif()
if(PERL_VERSION_STRING VERSION_LESS 5.16)
message(FATAL_ERROR "Too old Perl (<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 check-license)
add_dependencies(checkers check-whitespace)
add_check_whitespace(main ${PMEMSTREAM_ROOT_DIR}/CMakeLists.txt
${PMEMSTREAM_ROOT_DIR}/cmake/*.*
${PMEMSTREAM_ROOT_DIR}/*.*)
endif()
endif()
# ----------------------------------------------------------------- #
## Add/include sub-directories (if build options enabled them)
# ----------------------------------------------------------------- #
add_subdirectory(src)
if(BUILD_DOC)
add_subdirectory(doc)
endif()
if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
if(BUILD_BENCHMARKS)
add_subdirectory(benchmarks)
endif()
if(BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
# ----------------------------------------------------------------- #
## Configure make install/uninstall and packages
# ----------------------------------------------------------------- #
string(REPLACE ";" " " PKG_CONFIG_REQUIRES "${PKG_CONFIG_REQUIRES}")
string(REPLACE ";" ", " RPM_PACKAGE_REQUIRES "${RPM_DEPENDS}")
string(REPLACE ";" ", " DEB_PACKAGE_REQUIRES "${DEB_DEPENDS}")
configure_file(${PMEMSTREAM_ROOT_DIR}/cmake/libpmemstream.pc.in
${CMAKE_CURRENT_BINARY_DIR}/libpmemstream.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpmemstream.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
install(DIRECTORY examples/ DESTINATION ${CMAKE_INSTALL_DOCDIR}/examples)
install(TARGETS pmemstream
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
configure_file(
"${PMEMSTREAM_ROOT_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)
if(NOT "${CPACK_GENERATOR}" STREQUAL "")
include(${PMEMSTREAM_ROOT_DIR}/cmake/packages.cmake)
endif()