1097358799b85e25d898c8aac8106fdf73805d8b
[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 vpp_find_path(XDP_INCLUDE_DIR NAMES xdp/xsk.h)
15 if (NOT XDP_INCLUDE_DIR)
16   message(WARNING "libxdp 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 XDP_LIB libxdp.a)
22 vpp_plugin_find_library(af_xdp BPF_LIB libbpf.a)
23 vpp_plugin_find_library(af_xdp ELF_LIB elf)
24 vpp_plugin_find_library(af_xdp Z_LIB z)
25 if (NOT XDP_LIB OR NOT BPF_LIB OR NOT ELF_LIB OR NOT Z_LIB)
26   message(WARNING "af_xdp plugin - missing libraries - af_xdp plugin disabled")
27   return()
28 endif()
29
30 set(CMAKE_REQUIRED_FLAGS "-fPIC")
31 set(CMAKE_REQUIRED_INCLUDES "${XDP_INCLUDE_DIR}")
32 set(CMAKE_REQUIRED_LIBRARIES "${XDP_LIB}" "${BPF_LIB}" "${ELF_LIB}" "${Z_LIB}")
33 CHECK_C_SOURCE_COMPILES("
34 #include <xdp/xsk.h>
35 int main(void)
36 {
37     return xsk_socket__create (0, 0, 0, 0, 0, 0, 0);
38 }" XDP_COMPILES_CHECK)
39 if (NOT XDP_COMPILES_CHECK)
40 message(WARNING "af_xdp plugins - no working libxdp found - af_xdp plugin disabled")
41   return()
42 endif()
43
44 include_directories(${XDP_INCLUDE_DIR})
45
46 add_vpp_plugin(af_xdp
47   SOURCES
48   api.c
49   cli.c
50   device.c
51   format.c
52   unformat.c
53   plugin.c
54   input.c
55   output.c
56
57   MULTIARCH_SOURCES
58   input.c
59   output.c
60
61   API_FILES
62   af_xdp.api
63
64   API_TEST_SOURCES
65   unformat.c
66   test_api.c
67
68   LINK_LIBRARIES
69   ${XDP_LIB}
70   ${BPF_LIB}
71   ${ELF_LIB}
72   ${Z_LIB}
73 )