-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
260 lines (204 loc) · 7.41 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
#
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2020-2021, Intel Corporation
#
cmake_minimum_required(VERSION 3.3)
project(rpma C)
set(VERSION_MAJOR 0)
set(VERSION_MINOR 9)
set(VERSION_PATCH 0)
# set(VERSION_PRERELEASE rc1)
set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
if (VERSION_PRERELEASE)
set(VERSION ${VERSION}-${VERSION_PRERELEASE})
endif()
set(LIBRPMA_LIBRARIES rpma)
set(LIBRPMA_LIBRARY_DIRS ${CMAKE_BINARY_DIR}/src/)
set(LIBRPMA_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/src/include/)
set(LIBRPMA_SOURCE_DIR ${CMAKE_SOURCE_DIR}/src/)
# required only for some examples
set(LIBPMEM_REQUIRED_VERSION 1.6)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
include(FindPerl)
include(FindThreads)
include(CMakePackageConfigHelpers)
include(CheckCCompilerFlag)
include(GNUInstallDirs)
include(${CMAKE_SOURCE_DIR}/cmake/functions.cmake)
option(BUILD_EXAMPLES "build examples" ON)
option(BUILD_TESTS "build tests" ON)
option(BUILD_DOC "build documentation" ON)
option(COVERAGE "run coverage test" OFF)
option(DEVELOPER_MODE "enable developer checks" OFF)
option(CHECK_CSTYLE "check code style of C sources" OFF)
option(TRACE_TESTS "more verbose test outputs" OFF)
option(USE_ASAN "enable AddressSanitizer (debugging)" OFF)
option(USE_UBSAN "enable UndefinedBehaviorSanitizer (debugging)" OFF)
option(TESTS_SOFT_ROCE "enable tests that require a SoftRoCE-configured network interface" ON)
option(TESTS_NO_FORTIFY_SOURCE "enable tests that do not pass when -D_FORTIFY_SOURCE=2 flag set" OFF)
option(TESTS_USE_FORCED_PMEM "run tests with PMEM_IS_PMEM_FORCE=1" OFF)
option(TESTS_USE_VALGRIND "enable tests with valgrind (if found)" OFF)
option(TESTS_USE_VALGRIND_PMEMCHECK "enable tests with valgrind pmemcheck (if found)" OFF)
option(TESTS_LONG "enable long running tests" OFF)
option(TESTS_USE_FAULT_INJECTION "run tests with fault injection" OFF)
# Do not treat include directories from the interfaces
# of consumed Imported Targets as SYSTEM by default.
set(CMAKE_NO_SYSTEM_FROM_IMPORTED 1)
set(TEST_DIR ${CMAKE_CURRENT_BINARY_DIR}/test
CACHE STRING "working directory for tests")
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
endif()
if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
execute_process(COMMAND git describe
OUTPUT_VARIABLE SRCVERSION
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET)
if(NOT SRCVERSION)
execute_process(COMMAND git log -1 --format=%h
OUTPUT_VARIABLE SRCVERSION
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
else()
execute_process(COMMAND cat .version
OUTPUT_VARIABLE SRCVERSION
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
find_package(PkgConfig REQUIRED)
if(NOT PERL_FOUND)
message(FATAL_ERROR "Perl not found")
endif()
pkg_check_modules(LIBIBVERBS libibverbs)
if(NOT LIBIBVERBS_FOUND)
find_package(LIBIBVERBS REQUIRED libibverbs)
endif()
pkg_check_modules(LIBRDMACM librdmacm)
if(NOT LIBRDMACM_FOUND)
find_package(LIBRDMACM REQUIRED librdmacm)
endif()
pkg_check_modules(LIBPMEM libpmem>=${LIBPMEM_REQUIRED_VERSION})
pkg_check_modules(LIBPROTOBUFC libprotobuf-c)
# check if libibverbs has ODP support
is_ODP_supported(ON_DEMAND_PAGING_SUPPORTED)
if(ON_DEMAND_PAGING_SUPPORTED)
message(STATUS "On-Demand Paging (ODP) in libibverbs supported - Success")
add_flag(-DON_DEMAND_PAGING_SUPPORTED=1)
else()
message(WARNING "On-Demand Paging (ODP) is NOT supported and will be disabled (too old version of libibverbs)!")
endif()
# check if librdmacm has correct signature of rdma_getaddrinfo()
check_signature_rdma_getaddrinfo(RDMA_GETADDRINFO_NEW_SIGNATURE)
if(RDMA_GETADDRINFO_NEW_SIGNATURE)
message(STATUS "Using a new signature of rdma_getaddrinfo()")
else()
message(STATUS "Using an old signature of rdma_getaddrinfo()")
add_flag(-DRDMA_GETADDRINFO_OLD_SIGNATURE=1)
endif()
add_custom_target(checkers ALL)
add_custom_target(cstyle)
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-commits
COMMAND ${CMAKE_SOURCE_DIR}/utils/check-commits.sh)
add_custom_target(check-whitespace-main
COMMAND ${PERL_EXECUTABLE}
${CMAKE_SOURCE_DIR}/utils/check_whitespace
${CMAKE_SOURCE_DIR}/utils/check_license/*
${CMAKE_SOURCE_DIR}/README.md)
add_dependencies(check-whitespace check-whitespace-main)
add_flag(-Wpointer-arith)
add_flag(-Wunused-macros)
add_flag(-Wsign-conversion)
add_flag(-Wsign-compare)
add_flag(-Wunreachable-code-return)
add_flag(-Wmissing-variable-declarations)
add_flag(-fno-common)
add_flag(-std=gnu99)
add_flag(-ggdb DEBUG)
add_flag(-DDEBUG DEBUG)
add_flag("-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2" RELEASE)
if(USE_ASAN)
add_sanitizer_flag(address)
endif()
if(USE_UBSAN)
add_sanitizer_flag(undefined)
endif()
if(COVERAGE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -coverage")
endif()
if(DEVELOPER_MODE)
set(TESTS_NO_FORTIFY_SOURCE ON)
add_flag(-Wall)
add_flag(-Werror)
if(CHECK_CSTYLE)
add_dependencies(checkers cstyle)
endif()
add_dependencies(checkers check-whitespace)
add_dependencies(checkers check-license)
add_dependencies(checkers check-commits)
endif()
add_check_whitespace(cmake-main ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt)
add_check_whitespace(cmake-helpers ${CMAKE_CURRENT_SOURCE_DIR}/cmake/*.cmake)
configure_file(${CMAKE_SOURCE_DIR}/cmake/librpma.pc.in
${CMAKE_CURRENT_BINARY_DIR}/librpma.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/librpma.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
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)
configure_package_config_file(${CMAKE_SOURCE_DIR}/cmake/librpma-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/librpma-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/librpma/cmake
PATH_VARS CMAKE_INSTALL_LIBDIR CMAKE_INSTALL_INCLUDEDIR)
write_basic_package_version_file(librpma-config-version.cmake
VERSION ${VERSION}
COMPATIBILITY AnyNewerVersion)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/librpma-config.cmake ${CMAKE_CURRENT_BINARY_DIR}/librpma-config-version.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/librpma/cmake)
pkg_check_modules(VALGRIND valgrind)
if(VALGRIND_FOUND)
add_flag(-DVG_MEMCHECK_ENABLED=1)
add_flag(-DVG_DRD_ENABLED=1)
add_flag(-DVG_HELGRIND_ENABLED=1)
include_directories(${VALGRIND_INCLUDE_DIRS})
if(TESTS_USE_VALGRIND_PMEMCHECK)
find_pmemcheck()
endif()
if(VALGRIND_PMEMCHECK_FOUND)
add_flag(-DVG_PMEMCHECK_ENABLED=1)
endif()
endif()
add_subdirectory(src)
if(BUILD_TESTS)
if(TEST_DIR)
enable_testing()
else()
message(WARNING "TEST_DIR is empty - 'make test' will not work")
endif()
add_subdirectory(tests)
endif()
if(BUILD_DOC)
add_subdirectory(doc)
endif()
if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
if(NOT "${CPACK_GENERATOR}" STREQUAL "")
include(${CMAKE_SOURCE_DIR}/cmake/packages.cmake)
endif()
add_custom_target(config_softroce
COMMAND ${CMAKE_SOURCE_DIR}/tools/config_softroce.sh)
add_custom_target(run_all_examples
COMMAND ${CMAKE_SOURCE_DIR}/examples/run-all-on-SoftRoCE.sh ${CMAKE_BINARY_DIR}/examples)
add_custom_target(run_all_examples_under_valgrind
COMMAND ${CMAKE_SOURCE_DIR}/examples/run-all-on-SoftRoCE.sh ${CMAKE_BINARY_DIR}/examples --valgrind)