af_xdp: AF_XDP input plugin
[vpp.git] / src / plugins / af_xdp / CMakeLists.txt
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
14 find_path(BPF_INCLUDE_DIR NAMES bpf/xsk.h)
15 if (NOT BPF_INCLUDE_DIR)
16   message(WARNING "libbpf headers not found - af_xdp plugin disabled")
17   return()
18 endif()
19
20 set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS TRUE)
21 vpp_plugin_find_library(af_xdp BPF_LIB libbpf.a)
22 vpp_plugin_find_library(af_xdp BPF_ELF_LIB elf)
23 vpp_plugin_find_library(af_xdp BPF_Z_LIB z)
24 if (NOT BPF_LIB OR NOT BPF_ELF_LIB OR NOT BPF_Z_LIB)
25   message(WARNING "af_xdp plugin - missing libraries - af_xdp plugin disabled")
26   return()
27 endif()
28
29 set(CMAKE_REQUIRED_FLAGS "-fPIC")
30 set(CMAKE_REQUIRED_INCLUDES "${BPF_INCLUDE_DIR}")
31 set(CMAKE_REQUIRED_LIBRARIES "${BPF_LIB}" "${BPF_ELF_LIB}" "${BPF_Z_LIB}")
32 CHECK_C_SOURCE_COMPILES("
33 #include <bpf/xsk.h>
34 int main(void)
35 {
36     return xsk_socket__create (0, 0, 0, 0, 0, 0, 0);
37 }" BPF_COMPILES_CHECK)
38 if (NOT BPF_COMPILES_CHECK)
39   message(WARNING "af_xdp plugins - no working libbpf found - af_xdp plugin disabled")
40   return()
41 endif()
42
43 include_directories(${BPF_INCLUDE_DIR})
44
45 add_vpp_plugin(af_xdp
46   SOURCES
47   api.c
48   cli.c
49   device.c
50   format.c
51   unformat.c
52   plugin.c
53   input.c
54   output.c
55
56   MULTIARCH_SOURCES
57   input.c
58   output.c
59
60   API_FILES
61   af_xdp.api
62
63   API_TEST_SOURCES
64   unformat.c
65   test_api.c
66
67   LINK_LIBRARIES
68   ${BPF_LIB}
69   ${BPF_ELF_LIB}
70   ${BPF_Z_LIB}
71 )