From 088cba271e3e9e87425d0a060a493af193a571d9 Mon Sep 17 00:00:00 2001 From: Joerg Hofrichter Date: Fri, 20 Sep 2024 21:45:50 +0200 Subject: [PATCH] dpdk: find DPDK using pkg-config The parameters for compiling and linking against DPDK (DPDK_CFLAGS and DPDK_LDFLAGS or DPDK_INCLUDE_DIRS, DPDK_LIBRARIES and DPDK_LIBRARY_DIRS) are not trivial to determine and can be best provided by pkg-config. Therefore, use pkg-config to find DPDK and do not allow user provided DPDK variables. To compile UHD against DPDK which was installed to a custom prefix, e.g. /opt/dpdk-22.11, provide this path as parameter CMAKE_PREFIX_PATH: cmake .. -DCMAKE_PREFIX_PATH=/opt/dpdk-22.11 --- host/cmake/Modules/FindDPDK.cmake | 88 ++++--------------------------- host/lib/CMakeLists.txt | 6 ++- 2 files changed, 16 insertions(+), 78 deletions(-) diff --git a/host/cmake/Modules/FindDPDK.cmake b/host/cmake/Modules/FindDPDK.cmake index 75d9a0c1d..94779ae60 100644 --- a/host/cmake/Modules/FindDPDK.cmake +++ b/host/cmake/Modules/FindDPDK.cmake @@ -4,86 +4,20 @@ # # SPDX-License-Identifier: GPL-3.0-or-later # -# - Find DPDK -# Find the DPDK includes and client library -# This module defines -# DPDK_INCLUDE_DIRS, where to find rte_config.h and rte_version.h -# DPDK_LIBRARIES, the libraries needed by a DPDK user +# Find DPDK by using pkg-config. This sets various variables prefixed +# with "DPDK_". +# +# The following variables are used by the UHD build system: +# DPDK_INCLUDE_DIRS, the include directories +# DPDK_CFLAGS, the compiler flags +# DPDK_LDFLAGS, the linker flags +# DPDK_LIBRARIES, the list of libraries # DPDK_FOUND, If false, do not try to use DPDK. -# also defined, but not for general use are -# DPDK_LIBRARY, where to find the DPDK library. include(FindPackageHandleStandardArgs) -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}) - - 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) +PKG_CHECK_MODULES(DPDK 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_CONFIG_INCLUDE_DIR rte_config.h - HINTS ${PC_DPDK_INCLUDE_DIRS} - PATHS ENV RTE_INCLUDE - PATH_SUFFIXES dpdk -) - -# 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 -) - -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_USER_PROVIDED) - DPDK_READ_VERSION(DPDK_VERSION ${DPDK_INCLUDE_DIRS}) -else() - set(DPDK_LIBRARIES ${PC_DPDK_LINK_LIBRARIES}) - - if(DPDK_LIBRARY) - list(APPEND DPDK_LIBRARIES ${DPDK_LIBRARY}) - list(REMOVE_DUPLICATES DPDK_LIBRARIES) - endif() - - 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_DIRS DPDK_LIBRARIES - VERSION_VAR DPDK_VERSION -) +find_package_handle_standard_args(DPDK DEFAULT_MSG DPDK_INCLUDE_DIRS DPDK_CFLAGS DPDK_LDFLAGS DPDK_LIBRARIES) +mark_as_advanced(DPDK_INCLUDE_DIRS DPDK_CFLAGS DPDK_LDFLAGS DPDK_LIBRARIES) diff --git a/host/lib/CMakeLists.txt b/host/lib/CMakeLists.txt index 62e052d64..412197c81 100644 --- a/host/lib/CMakeLists.txt +++ b/host/lib/CMakeLists.txt @@ -60,7 +60,7 @@ endmacro(INCLUDE_SUBDIRECTORY) message(STATUS "") # Dependencies find_package(LIBUSB) -find_package(DPDK 18.11...21.11) +find_package(DPDK) LIBUHD_REGISTER_COMPONENT("USB" ENABLE_USB ON "ENABLE_LIBUHD;LIBUSB_FOUND" OFF OFF) # Devices LIBUHD_REGISTER_COMPONENT("B100" ENABLE_B100 ON "ENABLE_LIBUHD;ENABLE_USB" OFF OFF) @@ -182,6 +182,10 @@ if(ENABLE_MPMD) endif() add_library(uhd SHARED ${libuhd_sources}) target_link_libraries(uhd ${Boost_LIBRARIES} ${libuhd_libs}) +if(DPDK_FOUND) + target_compile_options(uhd PRIVATE ${DPDK_CFLAGS}) + target_link_options(uhd PUBLIC ${DPDK_LDFLAGS}) +endif() if(APPLE) target_link_options(uhd PRIVATE "LINKER:-undefined,dynamic_lookup") target_link_options(uhd PRIVATE "-flat_namespace")