CMake as an alternative to autotools (experimental)
[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 HINTS
18           ${DPDK_INCLUDE_DIR_HINT})
19 find_library(DPDK_LIB NAMES libdpdk.a HINTS ${DPDK_LIB_DIR_HINT})
20
21 ##############################################################################
22 # Find DPDK Version
23 ##############################################################################
24 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dpdk_version.c
25 "
26 #include <stdio.h>
27 #include <rte_version.h>
28 int main()
29 {
30   puts(strchr(rte_version(), ' ') + 1);
31   return 0;
32 }
33 ")
34
35 try_compile(DPDK_VERSION_COMPILED
36   ${CMAKE_CURRENT_BINARY_DIR}
37   ${CMAKE_CURRENT_BINARY_DIR}/dpdk_version.c
38   CMAKE_FLAGS
39   -DINCLUDE_DIRECTORIES=${DPDK_INCLUDE_DIR}
40   COPY_FILE ${CMAKE_CURRENT_BINARY_DIR}/dpdk_version.bin
41 )
42
43 if(DPDK_VERSION_COMPILED)
44   execute_process(
45     WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
46     COMMAND ./dpdk_version.bin
47     OUTPUT_VARIABLE DPDK_VERSION
48     OUTPUT_STRIP_TRAILING_WHITESPACE
49   )
50 endif()
51
52 file(REMOVE
53   ${CMAKE_CURRENT_BINARY_DIR}/dpdk_version.c
54   ${CMAKE_CURRENT_BINARY_DIR}/dpdk_version.bin
55 )
56
57
58 ##############################################################################
59 # DPDK plugin
60 ##############################################################################
61 if(DPDK_INCLUDE_DIR AND DPDK_LIB)
62   include_directories (${DPDK_INCLUDE_DIR})
63   add_vpp_plugin(dpdk_plugin
64     buffer.c
65     main.c
66     thread.c
67     api/dpdk_api.c
68     api/dpdk_test.c
69     device/cli.c
70     device/common.c
71     device/device.c
72     device/flow.c
73     device/format.c
74     device/init.c
75     device/node.c
76     hqos/hqos.c
77     ipsec/cli.c
78     ipsec/crypto_node.c
79     ipsec/esp_decrypt.c
80     ipsec/esp_encrypt.c
81     ipsec/ipsec.c
82     api/dpdk.api
83   )
84
85   vpp_library_set_multiarch_sources(dpdk_plugin
86     buffer.c
87     device/device.c
88     device/node.c
89   )
90
91   get_filename_component(DPDK_LIB_DIR ${DPDK_LIB} DIRECTORY)
92   set(DPDK_LINK_FLAGS "-L${DPDK_LIB_DIR} -Wl,--whole-archive,${DPDK_LIB},--no-whole-archive")
93   set(DPDK_LINK_FLAGS "${DPDK_LINK_FLAGS} -Wl,--exclude-libs,libIPSec_MB.a,-l:libIPSec_MB.a")
94   set(DPDK_LINK_FLAGS "${DPDK_LINK_FLAGS} -Wl,-lnuma")
95   set_target_properties(dpdk_plugin PROPERTIES LINK_FLAGS "${DPDK_LINK_FLAGS}")
96   message("-- Found DPDK ${DPDK_VERSION}: ${DPDK_INCLUDE_DIR} ${DPDK_LIB}")
97 else()
98   message("-- DPDK not found - dpdk_plugin disabled")
99 endif()
100