dpdk: add support for system libdpdk
[vpp.git] / src / plugins / dpdk / CMakeLists.txt
1 # Copyright (c) 2016 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 ##############################################################################
15 # Check if we want to use the system DPDK
16 ##############################################################################
17 option(VPP_USE_SYSTEM_DPDK "Use the system installation of DPDK." OFF)
18 if(VPP_USE_SYSTEM_DPDK)
19     find_package(PkgConfig REQUIRED)
20     pkg_check_modules(DPDK REQUIRED libdpdk)
21     message(WARNING "-- linking dpdk plugin against system libdpdk, version ${DPDK_VERSION}")
22     set(DPDK_LINK_FLAGS ${DPDK_LDFLAGS})
23 else()
24     ##############################################################################
25     # Find lib and include files
26     ##############################################################################
27     find_path(DPDK_INCLUDE_DIR PATH_SUFFIXES dpdk NAMES rte_config.h)
28     vpp_plugin_find_library(dpdk DPDK_LIB "libdpdk.a")
29
30     if (NOT DPDK_INCLUDE_DIR)
31       message(WARNING "-- DPDK headers not found - dpdk plugin disabled")
32       return()
33     endif()
34
35     if (NOT DPDK_LIB)
36       vpp_plugin_find_library(dpdk DPDK_SHLIB "libdpdk.so")
37       set(DPDK_IS_SHARED_LIB 1)
38       message(WARNING "-- linking dpdk plugin against DPDK shared libs")
39     endif()
40
41     ##############################################################################
42     # Parse DPDK config and version header files
43     ##############################################################################
44     file(STRINGS ${DPDK_INCLUDE_DIR}/rte_config.h rte_config)
45     file(STRINGS ${DPDK_INCLUDE_DIR}/rte_version.h rte_version)
46     file(STRINGS ${DPDK_INCLUDE_DIR}/rte_build_config.h rte_build_config)
47
48     foreach(l ${rte_config} ${rte_build_config} ${rte_version}})
49       if (l MATCHES "^#define[\t ]*RTE_")
50         STRING(REGEX REPLACE "^#define[\t ]*([A-Z1-9_]+)[\t ]*(.+)" "\\1;\\2" v "${l}")
51         list(GET v 0 name)
52         list(GET v 1 value)
53         set(DPDK_${name} ${value})
54       endif()
55     endforeach()
56
57     set(DPDK_VERSION
58         "${DPDK_RTE_VER_YEAR}.${DPDK_RTE_VER_MONTH}.${DPDK_RTE_VER_MINOR}")
59
60     ##############################################################################
61     # verify headroom size
62     ##############################################################################
63     if(NOT ${DPDK_RTE_PKTMBUF_HEADROOM} EQUAL ${PRE_DATA_SIZE})
64       message(
65         FATAL_ERROR
66         "DPDK RTE_PKTMBUF_HEADROOM (${DPDK_RTE_PKTMBUF_HEADROOM}) "
67          "must be equal to PRE_DATA_SIZE (${PRE_DATA_SIZE})"
68       )
69     endif()
70
71     ##############################################################################
72     # static or dynamic linking
73     ##############################################################################
74     unset(DPDK_LINK_LIBRARIES)
75     unset(DPDK_LINK_FLAGS)
76     message(STATUS "Found DPDK ${DPDK_VERSION} in ${DPDK_INCLUDE_DIR}")
77     include_directories (${DPDK_INCLUDE_DIR})
78
79     if(DPDK_IS_SHARED_LIB)
80       get_filename_component(DPDK_LIB_DIR ${DPDK_SHLIB} DIRECTORY)
81       string_append(DPDK_LINK_FLAGS "-L${DPDK_LIB_DIR}")
82       list(APPEND DPDK_LINK_LIBRARIES ${DPDK_SHLIB})
83     else()
84       get_filename_component(DPDK_LIB_DIR ${DPDK_LIB} DIRECTORY)
85       string_append(DPDK_LINK_FLAGS "-L${DPDK_LIB_DIR}")
86       string_append(DPDK_LINK_FLAGS "-Wl,--whole-archive,${DPDK_LIB},--no-whole-archive")
87     endif()
88
89     ##############################################################################
90     # libnuma
91     ##############################################################################
92     vpp_plugin_find_library(dpdk NUMA_LIB "numa")
93     list(APPEND DPDK_LINK_LIBRARIES ${NUMA_LIB})
94
95     ##############################################################################
96     # Mellanox libraries
97     ##############################################################################
98     if(DPDK_RTE_LIBRTE_MLX4_PMD OR DPDK_RTE_LIBRTE_MLX5_PMD)
99       if (DPDK_RTE_IBVERBS_LINK_DLOPEN)
100         message(STATUS "DPDK depends on libmnl (Mellanox PMD requirement)")
101         vpp_plugin_find_library(dpdk MNL_LIB "mnl")
102         list(APPEND DPDK_LINK_LIBRARIES "${MNL_LIB}")
103       else()
104         message(WARNING "EXPERIMENTAL: DPDK plugin without dlopen mode")
105         vpp_plugin_find_library(dpdk IBVERBS_LIB "libibverbs.a")
106         vpp_plugin_find_library(dpdk MLX5_LIB "libmlx5.a")
107         vpp_plugin_find_library(dpdk MLX4_LIB "libmlx4.a")
108         vpp_plugin_find_library(dpdk CCAN_LIB "libccan.a")
109         vpp_plugin_find_library(dpdk RDMA_UTIL_LIB "rdma_util")
110         string_append(DPDK_LINK_FLAGS "-Wl,--whole-archive,${IBVERBS_LIB},${MLX5_LIB},${MLX4_LIB},${CCAN_LIB},${RDMA_UTIL_LIB},--no-whole-archive")
111       endif()
112     endif()
113 endif()
114
115 ##############################################################################
116 # DPDK plugin
117 ##############################################################################
118
119 if (${DPDK_VERSION} VERSION_GREATER_EQUAL "20.8.0")
120   set(DPDK_CRYPTODEV_SOURCE cryptodev_dp_api)
121 else ()
122   set(DPDK_CRYPTODEV_SOURCE cryptodev)
123 endif ()
124
125 add_vpp_plugin(dpdk
126   SOURCES
127   buffer.c
128   main.c
129   thread.c
130   device/cli.c
131   device/common.c
132   device/device.c
133   device/flow.c
134   device/format.c
135   device/init.c
136   device/node.c
137   ipsec/cli.c
138   ipsec/crypto_node.c
139   ipsec/esp_decrypt.c
140   ipsec/esp_encrypt.c
141   ipsec/ipsec.c
142   cryptodev/${DPDK_CRYPTODEV_SOURCE}.c
143
144   MULTIARCH_SOURCES
145   buffer.c
146   device/device.c
147   device/node.c
148   ipsec/crypto_node.c
149   ipsec/esp_decrypt.c
150   ipsec/esp_encrypt.c
151
152   INSTALL_HEADERS
153   device/dpdk.h
154   ipsec/ipsec.h
155
156   LINK_FLAGS
157   "${DPDK_LINK_FLAGS}"
158
159   LINK_LIBRARIES
160   ${DPDK_LINK_LIBRARIES}
161
162   COMPONENT
163   vpp-plugin-dpdk
164 )