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