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