Always use 'lib' instead of 'lib64'
[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 find_library(DPDK_LIB NAMES libdpdk.a)
19
20 ##############################################################################
21 # Find DPDK Version
22 ##############################################################################
23 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dpdk_vars.c
24 "
25 #include <stdio.h>
26 #include <rte_version.h>
27 int main()
28 {
29   printf(\"VERSION=%s\\n\", strchr(rte_version(), ' ') + 1);
30   printf(\"RTE_PKTMBUF_HEADROOM=%u\\n\", RTE_PKTMBUF_HEADROOM);
31 #ifdef RTE_LIBRTE_PMD_AESNI_MB
32   printf(\"RTE_LIBRTE_PMD_AESNI_MB=%u\\n\", RTE_LIBRTE_PMD_AESNI_MB);
33 #endif
34 #ifdef RTE_LIBRTE_PMD_AESNI_GCM
35   printf(\"RTE_LIBRTE_PMD_AESNI_GCM=%u\\n\", RTE_LIBRTE_PMD_AESNI_GCM);
36 #endif
37   return 0;
38 }
39 ")
40
41 try_compile(DPDK_VARS_COMPILED
42   ${CMAKE_CURRENT_BINARY_DIR}
43   ${CMAKE_CURRENT_BINARY_DIR}/dpdk_vars.c
44   CMAKE_FLAGS
45   -DINCLUDE_DIRECTORIES=${DPDK_INCLUDE_DIR}
46   COPY_FILE ${CMAKE_CURRENT_BINARY_DIR}/dpdk_vars.bin
47 )
48
49 if(DPDK_VARS_COMPILED)
50   execute_process(
51     WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
52     COMMAND ./dpdk_vars.bin
53     OUTPUT_VARIABLE DPDK_VARS
54     OUTPUT_STRIP_TRAILING_WHITESPACE
55   )
56   string(REPLACE "\n" ";" DPDK_VARS ${DPDK_VARS})
57   foreach(v ${DPDK_VARS})
58     string(REPLACE "=" ";" v ${v})
59     list(GET v 0 name)
60     list(GET v 1 value)
61     set(DPDK_${name} ${value})
62   endforeach()
63 endif()
64
65 file(REMOVE
66   ${CMAKE_CURRENT_BINARY_DIR}/dpdk_vars.c
67   ${CMAKE_CURRENT_BINARY_DIR}/dpdk_vars.bin
68 )
69
70 if(NOT ${DPDK_RTE_PKTMBUF_HEADROOM} EQUAL ${PRE_DATA_SIZE})
71   message(
72     FATAL_ERROR
73     "DPDK RTE_PKTMBUF_HEADROOM (${DPDK_RTE_PKTMBUF_HEADROOM}) "
74      "must be equal to PRE_DATA_SIZE (${PRE_DATA_SIZE})"
75   )
76 endif()
77
78 ##############################################################################
79 # DPDK plugin
80 ##############################################################################
81 if(DPDK_INCLUDE_DIR AND DPDK_LIB)
82   include_directories (${DPDK_INCLUDE_DIR})
83
84   message(STATUS "Found DPDK ${DPDK_VERSION} in ${DPDK_INCLUDE_DIR}")
85   get_filename_component(DPDK_LIB_DIR ${DPDK_LIB} DIRECTORY)
86   set(DPDK_LINK_FLAGS "-L${DPDK_LIB_DIR} -Wl,--whole-archive,${DPDK_LIB},--no-whole-archive")
87   if(DPDK_RTE_LIBRTE_PMD_AESNI_MB OR DPDK_RTE_LIBRTE_PMD_AESNI_GCM)
88     set(DPDK_LINK_FLAGS "${DPDK_LINK_FLAGS} -Wl,--exclude-libs,libIPSec_MB.a,-l:libIPSec_MB.a")
89     message(STATUS "DPDK depends on IPSec MB library")
90   endif()
91   set(DPDK_LINK_FLAGS "${DPDK_LINK_FLAGS} -Wl,-lnuma")
92   add_vpp_plugin(dpdk
93     SOURCES
94     buffer.c
95     main.c
96     thread.c
97     api/dpdk_api.c
98     api/dpdk_test.c
99     device/cli.c
100     device/common.c
101     device/device.c
102     device/flow.c
103     device/format.c
104     device/init.c
105     device/node.c
106     hqos/hqos.c
107     ipsec/cli.c
108     ipsec/crypto_node.c
109     ipsec/esp_decrypt.c
110     ipsec/esp_encrypt.c
111     ipsec/ipsec.c
112
113     MULTIARCH_SOURCES
114     buffer.c
115     device/device.c
116     device/node.c
117
118     API_FILES
119     api/dpdk.api
120
121     API_TEST_SOURCES
122     api/dpdk_test.c
123
124     INSTALL_HEADERS
125     device/dpdk.h
126     api/dpdk_all_api_h.h
127     ipsec/ipsec.h
128
129     LINK_FLAGS
130     ${DPDK_LINK_FLAGS}
131
132     COMPONENT
133     vpp-plugin-dpdk
134   )
135 else()
136   message(WARNING "DPDK not found - dpdk disabled")
137 endif()
138