1# Copyright (c) 2018 Cisco and/or its affiliates.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at:
5#
6#     http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14find_path(IBVERBS_INCLUDE_DIR NAMES infiniband/verbs.h)
15
16if (NOT IBVERBS_INCLUDE_DIR)
17  message(WARNING "-- rdma headers not found - rdma plugin disabled")
18  return()
19endif()
20
21vpp_plugin_find_library(rdma IBVERBS_LIB libibverbs.a)
22vpp_plugin_find_library(rdma RDMA_UTIL_LIB librdma_util.a)
23vpp_plugin_find_library(rdma MLX5_LIB libmlx5.a)
24
25if (NOT IBVERBS_LIB OR NOT RDMA_UTIL_LIB OR NOT MLX5_LIB)
26  message(WARNING "rdma plugin - ibverbs not found - rdma plugin disabled")
27  return()
28endif()
29
30string_append(RDMA_LINK_FLAGS "-Wl,--whole-archive,${MLX5_LIB},--no-whole-archive")
31
32set(CMAKE_REQUIRED_FLAGS "-fPIC -shared -pthread -Wno-unused-command-line-argument ${RDMA_LINK_FLAGS} ${IBVERBS_LIB} ${RDMA_UTIL_LIB}")
33set(CMAKE_REQUIRED_INCLUDES "${IBVERBS_INCLUDE_DIR}")
34set(CMAKE_REQUIRED_LIBRARIES "c") # force linkage by including libc explicitely
35CHECK_C_SOURCE_COMPILES("
36#include <infiniband/verbs.h>
37int main(void)
38{
39    return 0 != ibv_get_device_list(0);
40}" IBVERBS_COMPILES_CHECK)
41
42if (NOT IBVERBS_COMPILES_CHECK)
43  message(WARNING "rdma plugins - no working ibverbs found - rdma plugin disabled")
44  return()
45endif()
46
47include_directories(${IBVERBS_INCLUDE_DIR})
48
49add_vpp_plugin(rdma
50  SOURCES
51  api.c
52  cli.c
53  device.c
54  format.c
55  plugin.c
56  unformat.c
57  input.c
58  output.c
59
60  MULTIARCH_SOURCES
61  input.c
62  output.c
63
64  API_FILES
65  rdma.api
66
67  API_TEST_SOURCES
68  unformat.c
69  test_api.c
70
71  LINK_FLAGS
72  "${RDMA_LINK_FLAGS}"
73
74  LINK_LIBRARIES
75  ${IBVERBS_LIB}
76  ${RDMA_UTIL_LIB}
77)
78