crypto: fixed ipsec_mb lib dependencies
[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_LESS "20.8.0")
103 add_vpp_plugin(dpdk
104   SOURCES
105   buffer.c
106   main.c
107   thread.c
108   device/cli.c
109   device/common.c
110   device/device.c
111   device/flow.c
112   device/format.c
113   device/init.c
114   device/node.c
115   ipsec/cli.c
116   ipsec/crypto_node.c
117   ipsec/esp_decrypt.c
118   ipsec/esp_encrypt.c
119   ipsec/ipsec.c
120   cryptodev/cryptodev.c
121
122   MULTIARCH_SOURCES
123   buffer.c
124   device/device.c
125   device/node.c
126   ipsec/crypto_node.c
127   ipsec/esp_decrypt.c
128   ipsec/esp_encrypt.c
129
130   INSTALL_HEADERS
131   device/dpdk.h
132   ipsec/ipsec.h
133
134   LINK_FLAGS
135   "${DPDK_LINK_FLAGS}"
136
137   LINK_LIBRARIES
138   ${DPDK_LINK_LIBRARIES}
139
140   COMPONENT
141   vpp-plugin-dpdk
142 )
143
144 else ()
145 add_vpp_plugin(dpdk
146   SOURCES
147   buffer.c
148   main.c
149   thread.c
150   device/cli.c
151   device/common.c
152   device/device.c
153   device/flow.c
154   device/format.c
155   device/init.c
156   device/node.c
157   ipsec/cli.c
158   ipsec/crypto_node.c
159   ipsec/esp_decrypt.c
160   ipsec/esp_encrypt.c
161   ipsec/ipsec.c
162   cryptodev/cryptodev_dp_api.c
163
164   MULTIARCH_SOURCES
165   buffer.c
166   device/device.c
167   device/node.c
168   ipsec/crypto_node.c
169   ipsec/esp_decrypt.c
170   ipsec/esp_encrypt.c
171
172   INSTALL_HEADERS
173   device/dpdk.h
174   ipsec/ipsec.h
175
176   LINK_FLAGS
177   "${DPDK_LINK_FLAGS}"
178
179   LINK_LIBRARIES
180   ${DPDK_LINK_LIBRARIES}
181
182   COMPONENT
183   vpp-plugin-dpdk
184 )
185
186 endif ()