forked from linux-rdma/rdma-core
-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
294 lines (260 loc) · 9.63 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
# COPYRIGHT (c) 2016 Obsidian Research Corporation. See COPYING file
# Run cmake as:
# mkdir build
# cmake -GNinja ..
# ninja
#
# Common options passed to cmake are:
# -DCMAKE_EXPORT_COMPILE_COMMANDS=1
# Write a compile_commands.json file for clang tooling
# -DENABLE_VALGRIND=1 (default disabled)
# Embed valgrind notations, this has a tiny negative performance impact
# -DENABLE_RESOLVE_NEIGH=0 (default enabled)
# Do not link to libnl and do not resolve neighbours internally for Ethernet,
# and do not build iwpmd.
cmake_minimum_required(VERSION 2.8.11 FATAL_ERROR)
project(RDMA C)
# CMake likes to use -rdynamic too much, they fixed it in 3.4.
if(POLICY CMP0065)
cmake_policy(SET CMP0065 NEW)
else()
# .. but we really do want to opt out.
string(REPLACE "-rdynamic" "" CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS}")
endif()
set(PACKAGE_NAME "RDMA")
# FIXME versioning strategy?
set(PACKAGE_VERSION "1")
#-------------------------
# Basic standard paths
include(GNUInstallDirs)
# C include root
set(BUILD_INCLUDE ${CMAKE_BINARY_DIR}/include)
# Executables
set(BUILD_BIN ${CMAKE_BINARY_DIR}/bin)
# Libraries
set(BUILD_LIB ${CMAKE_BINARY_DIR}/lib)
# Location to place provider .driver files
set(CONFIG_DIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}/libibverbs.d")
set(CMAKE_INSTALL_INITDDIR "${CMAKE_INSTALL_SYSCONFDIR}/init.d"
CACHE PATH "Location for init.d files")
set(CMAKE_INSTALL_SYSTEMD_SERVICEDIR "${CMAKE_INSTALL_PREFIX}/lib/systemd"
CACHE PATH "Location for systemd service files")
set(ACM_PROVIDER_DIR "${CMAKE_INSTALL_FULL_LIBDIR}/ibacm"
CACHE PATH "Location for ibacm provider plugin shared library files.")
#-------------------------
# Load CMake components
set(BUILDLIB "${CMAKE_SOURCE_DIR}/buildlib")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${BUILDLIB}")
include(FindPkgConfig)
include(CheckCCompilerFlag)
include(CheckIncludeFile)
include(CheckTypeSize)
include(RDMA_EnableCStd)
include(RDMA_DoFixup)
include(publish_headers)
include(rdma_functions)
#-------------------------
# Setup the basic C compiler
include_directories(${BUILD_INCLUDE})
# FIXME: Eliminate HAVE_CONFIG_H, we always have it.
add_definitions(-DHAVE_CONFIG_H)
# Require GNU99 mode
RDMA_EnableCStd()
# Extra warnings. Turn on -Wextra to keep aware of interesting developments from gcc,
# but turn off some that are not terribly useful for this source.
# FIXME: I wonder how many of the signed compares are bugs?
RDMA_AddOptCFlag(CMAKE_C_FLAGS HAVE_C_WARNINGS
"-Wall -Wextra -Wno-sign-compare -Wno-unused-parameter")
# At some point around 5.4 gcc fixed missing-field-initializers to ignore this
# common idiom we use extensively. Since this is a useful warning for
# developers try and leave it on if the compiler supports it.
CHECK_C_SOURCE_COMPILES("
struct foo { int a; int b; };
int main(int argc,const char *argv[]) { struct foo tmp = {}; return tmp.a; }"
HAVE_C_WORKING_MISSING_FIELD_INITIALIZERS
FAIL_REGEX "warning")
if (NOT HAVE_C_WORKING_MISSING_FIELD_INITIALIZERS)
RDMA_AddOptCFlag(CMAKE_C_FLAGS HAVE_C_WNO_MISSING_FIELD_INITIALIZERS "-Wno-missing-field-initializers")
endif()
# Check that the compiler supports -fno-strict-aliasing.
# The use of this flag in the source is discouraged
set(NO_STRICT_ALIASING_FLAGS "")
RDMA_AddOptCFlag(NO_STRICT_ALIASING_FLAGS HAVE_NO_STRICT_ALIASING
"-fno-strict-aliasing")
# The code does not do the racy fcntl if the various CLOEXEC's are not
# supported so it really doesn't work right if this isn't available. Thus hard
# require it.
CHECK_C_SOURCE_COMPILES("
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <fcntl.h>
int main(int argc,const char *argv[]) {
open(\".\",O_RDONLY | O_CLOEXEC);
socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0);
return 0;
}" HAS_CLOEXEC)
if (NOT HAS_CLOEXEC)
message(FATAL_ERROR "O_CLOEXEC/SOCK_CLOEXEC/fopen(..,\"e\") support is required but not found")
endif()
# always_inline is supported
CHECK_C_SOURCE_COMPILES("
inline __attribute__((always_inline)) int foo(void) {return 0;}
int main(int argc,const char *argv[]) { return foo(); }"
HAVE_FUNC_ATTRIBUTE_ALWAYS_INLINE
FAIL_REGEX "warning")
# Enable development support features
# Prune unneeded shared libraries during linking
RDMA_AddOptCFlag(CMAKE_EXE_LINKER_FLAGS SUPPORTS_AS_NEEDED "-Wl,--as-needed")
RDMA_AddOptCFlag(CMAKE_SHARED_LINKER_FLAGS SUPPORTS_AS_NEEDED "-Wl,--as-needed")
RDMA_AddOptCFlag(CMAKE_MODULE_LINKER_FLAGS SUPPORTS_AS_NEEDED "-Wl,--as-needed")
# Ensure all shared ELFs have fully described linking
RDMA_AddOptCFlag(CMAKE_EXE_LINKER_FLAGS SUPPORTS_NO_UNDEFINED "-Wl,--no-undefined")
RDMA_AddOptCFlag(CMAKE_SHARED_LINKER_FLAGS SUPPORTS_NO_UNDEFINED "-Wl,--no-undefined")
# Enable gold linker - gold has different linking checks
#RDMA_AddOptCFlag(CMAKE_EXE_LINKER_FLAGS SUPPORTS_NO_UNDEFINED "-fuse-ld=gold")
#RDMA_AddOptCFlag(CMAKE_SHARED_LINKER_FLAGS SUPPORTS_NO_UNDEFINED "-fuse-ld=gold")
#RDMA_AddOptCFlag(CMAKE_MODULE_LINKER_FLAGS SUPPORTS_NO_UNDEFINED "-fuse-ld=gold")
# Verify that GNU --version-script and asm(".symver") works
find_package(LDSymVer REQUIRED)
#-------------------------
# Find libraries
# pthread
FIND_PACKAGE (Threads REQUIRED)
# libnl
if (NOT DEFINED ENABLE_RESOLVE_NEIGH)
set(ENABLE_RESOLVE_NEIGH "ON" CACHE BOOL "Enable internal resolution of neighbours for Etherent")
endif()
if (ENABLE_RESOLVE_NEIGH)
# FIXME use of pkgconfig is discouraged
pkg_check_modules(NL3 libnl-3.0 libnl-route-3.0)
if (NL3_FOUND)
set(NL_KIND 3)
set(NL_INCLUDE_DIRS ${NL3_INCLUDE_DIRS})
set(NL_LIBRARIES ${NL3_LIBRARIES})
else()
# FIXME: I don't know why we have this fallback, all supported distros
# have libnl3
pkg_check_modules(NL1 libnl-1)
if (NL1_FOUND)
set(NL_KIND 1)
set(NL_INCLUDE_DIRS ${NL1_INCLUDE_DIRS})
set(NL_LIBRARIES ${NL1_LIBRARIES})
else()
message(FATAL_ERROR "Cannot find libnl-3.0 or libnl-1")
endif()
endif()
include_directories(${NL_INCLUDE_DIRS})
else()
set(NL_KIND 0)
set(NL_LIBRARIES "")
endif()
# Statically determine sizeof(long), this is largely unnecessary, no new code
# should rely on this.
check_type_size("long" SIZEOF_LONG BUILTIN_TYPES_ONLY LANGUAGE C)
# Are our kernel headers new enough?
# If not replace them with built-in copies so we can continue to build.
CHECK_INCLUDE_FILE("rdma/rdma_user_rxe.h" HAVE_RDMA_USER_RXE)
RDMA_DoFixup("${HAVE_RDMA_USER_RXE}" "rdma/rdma_user_rxe.h")
#-------------------------
# Apply fixups
# FIXME: We should probably always enable memcheck.h, and only selectively
# turn it off in the real high performance paths. There is no reason umad
# should ever have memcheck disabled for instance.
if (ENABLE_VALGRIND)
CHECK_INCLUDE_FILE("valgrind/memcheck.h" HAVE_VALGRIND_MEMCHECK)
CHECK_INCLUDE_FILE("valgrind/drd.h" HAVE_VALGRIND_DRD)
else()
set(HAVE_VALGRIND_MEMCHECK 0)
set(HAVE_VALGRIND_DRD 0)
endif()
RDMA_DoFixup("${HAVE_VALGRIND_MEMCHECK}" "valgrind/memcheck.h")
RDMA_DoFixup("${HAVE_VALGRIND_DRD}" "valgrind/drd.h")
# Older glibc does not include librt
CHECK_C_SOURCE_COMPILES("
#include <time.h>
int main(int argc,const char *argv[]) {
clock_gettime(CLOCK_MONOTONIC,0);
clock_nanosleep(CLOCK_MONOTONIC,0,0,0);
return 0;
};" LIBC_HAS_LIBRT)
if (NOT LIBC_HAS_LIBRT)
set(RT_LIBRARIES "rt")
endif()
#-------------------------
# Build Prep
# Write out a git ignore file to the build directory if it isn't the source
# directory. For developer convenience
if (NOT ${CMAKE_CURRENT_BINARY_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
file(WRITE ${CMAKE_BINARY_DIR}/.gitignore "*")
endif()
configure_file("${BUILDLIB}/config.h.in" "${BUILD_INCLUDE}/config.h" ESCAPE_QUOTES @ONLY)
#-------------------------
# Sub-directories
# Libraries
add_subdirectory(libibumad/src)
add_subdirectory(libibumad/man)
add_subdirectory(libibverbs/src)
add_subdirectory(libibverbs/man)
add_subdirectory(librdmacm/src)
add_subdirectory(librdmacm/man)
add_subdirectory(libibcm/src)
# Providers
add_subdirectory(libcxgb3/src)
add_subdirectory(libcxgb4/src)
add_subdirectory(libhfi1verbs/src)
add_subdirectory(libi40iw/src)
add_subdirectory(libipathverbs/src)
add_subdirectory(libipathverbs/)
add_subdirectory(libmlx4/src)
add_subdirectory(libmlx5/src)
add_subdirectory(libmthca/src)
add_subdirectory(libnes/src)
add_subdirectory(libocrdma/src)
add_subdirectory(librxe/src)
add_subdirectory(librxe/man)
add_subdirectory(librxe/)
# Binaries
add_subdirectory(ibacm)
if (NOT NL_KIND EQUAL 0)
add_subdirectory(iwpmd)
add_subdirectory(iwpmd/src)
endif()
add_subdirectory(libibcm/examples)
add_subdirectory(libibumad/tests)
add_subdirectory(libibverbs/examples)
add_subdirectory(librdmacm/examples)
add_subdirectory(srp_daemon/srp_daemon)
add_subdirectory(srp_daemon/man)
rdma_finalize_libs()
#-------------------------
# Display a summary
# Only report things that are non-ideal.
message(STATUS "Missing Optional Items:")
if (NOT HAVE_FUNC_ATTRIBUTE_ALWAYS_INLINE)
message(STATUS " Compiler attribute always_inline NOT supported")
endif()
if (NOT HAVE_VALGRIND_MEMCHECK)
message(STATUS " Valgrind memcheck.h NOT enabled")
endif()
if (NOT HAVE_VALGRIND_DRD)
message(STATUS " Valgrind drd.h NOT enabled")
endif()
if (NL_KIND EQUAL 1)
message(STATUS " libnl 3 NOT found (using libnl 1 compat)")
endif()
if (NL_KIND EQUAL 0)
message(STATUS " neighbour resolution NOT enabled")
endif()
if (NOT HAVE_RDMA_USER_RXE)
message(STATUS " rdma/rdma_user_rxe.h NOT found (old system kernel headers)")
endif()
if (NOT HAVE_C_WARNINGS)
message(STATUS " extended C warnings NOT supported")
endif()
if (NOT HAVE_NO_STRICT_ALIASING)
message(STATUS " -fno-strict-aliasing NOT supported")
endif()
if (NOT HAVE_C_WORKING_MISSING_FIELD_INITIALIZERS)
message(STATUS " -Wmissing-field-initializers does NOT work")
endif()