diff options
author | Alex Williams <alex.williams@ni.com> | 2020-01-14 15:35:42 -0800 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2020-01-22 12:52:35 -0800 |
commit | 9450345649f5d502cca89658f674161a5f45a376 (patch) | |
tree | 88ef8e60e7b8113011436e8ae01e8c5caa188dc0 /host | |
parent | a09dad7fc6da3fe0c8b6e64b6187bb8b15191ccf (diff) | |
download | uhd-9450345649f5d502cca89658f674161a5f45a376.tar.gz uhd-9450345649f5d502cca89658f674161a5f45a376.tar.bz2 uhd-9450345649f5d502cca89658f674161a5f45a376.zip |
cmake: Find DPDK via pkg-config, if available
Debian uses pkg-config without the libdpdk.so linker script. Use
the pkg-config file to grab the installed libraries and determine
what to link to.
Diffstat (limited to 'host')
-rw-r--r-- | host/cmake/Modules/FindDPDK.cmake | 80 | ||||
-rw-r--r-- | host/lib/transport/CMakeLists.txt | 1 | ||||
-rw-r--r-- | host/lib/transport/uhd-dpdk/CMakeLists.txt | 2 | ||||
-rw-r--r-- | host/lib/usrp/mpmd/CMakeLists.txt | 3 | ||||
-rw-r--r-- | host/lib/usrp/x300/CMakeLists.txt | 1 | ||||
-rw-r--r-- | host/tests/CMakeLists.txt | 4 |
6 files changed, 62 insertions, 29 deletions
diff --git a/host/cmake/Modules/FindDPDK.cmake b/host/cmake/Modules/FindDPDK.cmake index a5029b94c..90240e61d 100644 --- a/host/cmake/Modules/FindDPDK.cmake +++ b/host/cmake/Modules/FindDPDK.cmake @@ -1,12 +1,13 @@ # # Copyright 2018 Ettus Research, a National Instruments Company +# Copyright 2020 Ettus Research, a National Instruments Brand # # SPDX-License-Identifier: GPL-3.0-or-later # # - Find DPDK # Find the DPDK includes and client library # This module defines -# DPDK_INCLUDE_DIR, where to find rte_config.h +# DPDK_INCLUDE_DIRS, where to find rte_config.h and rte_version.h # DPDK_LIBRARIES, the libraries needed by a DPDK user # DPDK_FOUND, If false, do not try to use DPDK. # also defined, but not for general use are @@ -14,46 +15,75 @@ include(FindPackageHandleStandardArgs) -find_path ( DPDK_INCLUDE_CONFIG_DIR rte_config.h - PATHS ENV RTE_INCLUDE - PATH_SUFFIXES dpdk -) +function(DPDK_READ_VERSION DPDK_VERSION DPDK_INCLUDE_DIRS) + if(NOT DPDK_INCLUDE_DIRS) + return() + endif() + + file(READ "${DPDK_INCLUDE_DIRS}/rte_version.h" + DPDK_VERSION_STR + ) + string(REGEX MATCH "#define RTE_VER_YEAR ([0-9]+)" _ ${DPDK_VERSION_STR}) + set(DPDK_VERSION_MAJOR ${CMAKE_MATCH_1}) + + string(REGEX MATCH "#define RTE_VER_MONTH ([0-9]+)" _ ${DPDK_VERSION_STR}) + set(DPDK_VERSION_MINOR ${CMAKE_MATCH_1}) -find_path ( DPDK_INCLUDE_ETHDEV_DIR rte_ethdev.h + set(DPDK_VERSION "${DPDK_VERSION_MAJOR}.${DPDK_VERSION_MINOR}" PARENT_SCOPE) +endfunction() + +if(DPDK_LIBRARIES AND DPDK_INCLUDE_DIRS) + set(DPDK_USER_PROVIDED ON) +else() + set(DPDK_USER_PROVIDED OFF) +endif() + +find_package(PkgConfig) +PKG_CHECK_MODULES(PC_DPDK QUIET libdpdk>=18.11) + +find_path (DPDK_VERSION_INCLUDE_DIR rte_version.h + HINTS ${PC_DPDK_INCLUDE_DIRS} PATHS ENV RTE_INCLUDE PATH_SUFFIXES dpdk ) - -find_path ( DPDK_INCLUDE_VERSION_DIR rte_version.h +find_path (DPDK_CONFIG_INCLUDE_DIR rte_config.h + HINTS ${PC_DPDK_INCLUDE_DIRS} PATHS ENV RTE_INCLUDE PATH_SUFFIXES dpdk ) -set(DPDK_INCLUDE_DIR ${DPDK_INCLUDE_CONFIG_DIR} ${DPDK_INCLUDE_ETHDEV_DIR}) -list(REMOVE_DUPLICATES DPDK_INCLUDE_DIR) - +# Check for linker script that pulls in the APIs find_library(DPDK_LIBRARY + dpdk + HINTS ${PC_DPDK_LIBDIR} PATHS $ENV{RTE_SDK_DIR}/$ENV{RTE_TARGET}/lib ) -list(APPEND DPDK_LIBRARIES dpdk) +if(NOT DPDK_USER_PROVIDED) + set(DPDK_INCLUDE_DIRS ${PC_DPDK_INCLUDE_DIRS}) + list(APPEND DPDK_INCLUDE_DIRS ${DPDK_VERSION_INCLUDE_DIR}) + list(APPEND DPDK_INCLUDE_DIRS ${DPDK_CONFIG_INCLUDE_DIR}) + list(REMOVE_DUPLICATES DPDK_INCLUDE_DIRS) +endif() -if(DPDK_INCLUDE_VERSION_DIR) - file(READ "${DPDK_INCLUDE_VERSION_DIR}/rte_version.h" - DPDK_VERSION_STR - ) - - string(REGEX MATCH "#define RTE_VER_YEAR ([0-9]+)" _ ${DPDK_VERSION_STR}) - set(DPDK_VERSION_MAJOR ${CMAKE_MATCH_1}) - - string(REGEX MATCH "#define RTE_VER_MONTH ([0-9]+)" _ ${DPDK_VERSION_STR}) - set(DPDK_VERSION_MINOR ${CMAKE_MATCH_1}) -endif(DPDK_INCLUDE_VERSION_DIR) +if(DPDK_USER_PROVIDED) + DPDK_READ_VERSION(DPDK_VERSION ${DPDK_INCLUDE_DIRS}) +else() + set(DPDK_LIBRARIES ${PC_DPDK_LIBRARIES}) + if(DPDK_LIBRARY) + list(APPEND DPDK_LIBRARIES ${DPDK_LIBRARY}) + list(REMOVE_DUPLICATES DPDK_LIBRARIES) + endif() -set(DPDK_VERSION "${DPDK_VERSION_MAJOR}.${DPDK_VERSION_MINOR}") + if(PC_DPDK_FOUND) + set(DPDK_VERSION ${PC_DPDK_VERSION}) + else() + DPDK_READ_VERSION(DPDK_VERSION ${DPDK_INCLUDE_DIRS}) + endif(PC_DPDK_FOUND) +endif() find_package_handle_standard_args(DPDK - REQUIRED_VARS DPDK_INCLUDE_DIR DPDK_LIBRARIES + REQUIRED_VARS DPDK_INCLUDE_DIRS DPDK_LIBRARIES VERSION_VAR DPDK_VERSION ) diff --git a/host/lib/transport/CMakeLists.txt b/host/lib/transport/CMakeLists.txt index d88631ae3..2b1378978 100644 --- a/host/lib/transport/CMakeLists.txt +++ b/host/lib/transport/CMakeLists.txt @@ -143,6 +143,7 @@ endif(ENABLE_LIBERIO) if(ENABLE_DPDK) INCLUDE_SUBDIRECTORY(uhd-dpdk) + include_directories(${DPDK_INCLUDE_DIRS}) LIBUHD_APPEND_SOURCES( ${CMAKE_CURRENT_SOURCE_DIR}/udp_dpdk_link.cpp diff --git a/host/lib/transport/uhd-dpdk/CMakeLists.txt b/host/lib/transport/uhd-dpdk/CMakeLists.txt index a13886653..c19fcae78 100644 --- a/host/lib/transport/uhd-dpdk/CMakeLists.txt +++ b/host/lib/transport/uhd-dpdk/CMakeLists.txt @@ -26,7 +26,7 @@ if(ENABLE_DPDK) ${CMAKE_CURRENT_SOURCE_DIR}/dpdk_io_service.cpp PROPERTIES COMPILE_FLAGS "${UHD_DPDK_CFLAGS} -D_GNU_SOURCE" ) - include_directories(${DPDK_INCLUDE_DIR}) + include_directories(${DPDK_INCLUDE_DIRS}) LIBUHD_APPEND_LIBS(${DPDK_LIBRARIES}) endif(ENABLE_DPDK) diff --git a/host/lib/usrp/mpmd/CMakeLists.txt b/host/lib/usrp/mpmd/CMakeLists.txt index 1eab1f39b..5a6ce72c1 100644 --- a/host/lib/usrp/mpmd/CMakeLists.txt +++ b/host/lib/usrp/mpmd/CMakeLists.txt @@ -25,11 +25,12 @@ if(ENABLE_MPMD) ) set_property( SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/mpmd_link_if_mgr.cpp - PROPERTY COMPILE_DEFINITIONS HAVE_LIBERIO + PROPERTY COMPILE_DEFINITIONS HAVE_LIBERIO ) endif(ENABLE_LIBERIO) if(ENABLE_DPDK) + include_directories(${DPDK_INCLUDE_DIRS}) set_property( SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/mpmd_link_if_ctrl_udp.cpp diff --git a/host/lib/usrp/x300/CMakeLists.txt b/host/lib/usrp/x300/CMakeLists.txt index b00ee357c..d5a7eee4f 100644 --- a/host/lib/usrp/x300/CMakeLists.txt +++ b/host/lib/usrp/x300/CMakeLists.txt @@ -37,6 +37,7 @@ if(ENABLE_X300) ) if(ENABLE_DPDK) + include_directories(${DPDK_INCLUDE_DIRS}) add_definitions(-DHAVE_DPDK) endif(ENABLE_DPDK) endif(ENABLE_X300) diff --git a/host/tests/CMakeLists.txt b/host/tests/CMakeLists.txt index d25c88400..017778fb8 100644 --- a/host/tests/CMakeLists.txt +++ b/host/tests/CMakeLists.txt @@ -129,7 +129,7 @@ if(ENABLE_DPDK) ${CMAKE_SOURCE_DIR}/lib/transport/uhd-dpdk/dpdk_io_service.cpp ${CMAKE_SOURCE_DIR}/lib/transport/udp_dpdk_link.cpp INCLUDE_DIRS - ${DPDK_INCLUDE_DIR} + ${DPDK_INCLUDE_DIRS} EXTRA_LIBS ${DPDK_LIBRARIES} NOAUTORUN # Don't register for auto-run, it requires special config ) @@ -145,7 +145,7 @@ if(ENABLE_DPDK) ${CMAKE_SOURCE_DIR}/lib/transport/uhd-dpdk/dpdk_io_service.cpp ${CMAKE_SOURCE_DIR}/lib/transport/udp_dpdk_link.cpp INCLUDE_DIRS - ${DPDK_INCLUDE_DIR} + ${DPDK_INCLUDE_DIRS} EXTRA_LIBS ${DPDK_LIBRARIES} NOAUTORUN # Don't register for auto-run, it requires special config ) |