1# Try to find dpdk 2# 3# Once done, this will define 4# 5# dpdk_FOUND 6# dpdk_INCLUDE_DIRS 7# dpdk_LIBRARIES 8# dpdk_STATIC_LIBRARIES 9# dpdk_LIBS_STATIC 10# dpdk_REQUIRES_PRIVATE 11# dpdk_PACKAGE_NAME 12 13# 14# We only try to find DPDK using pkg-config; DPDK is *SO* 15# complicated - DPDK 19.02, for example, has about 117(!) 16# libraries, and the precise set of libraries required has 17# changed over time - so attempting to guess which libraries 18# you need, and hardcoding that in an attempt to find the 19# libraries without DPDK, rather than relying on DPDK to 20# tell you, with a .pc file, what libraries are needed, 21# is *EXTREMELY* fragile and has caused some bug reports, 22# so we're just not going to do it. 23# 24# If that causes a problem, the only thing we will do is 25# accept an alternative way of finding the appropriate 26# library set for the installed version of DPDK that is 27# as robust as pkg-config (i.e., it had better work as well 28# as pkg-config with *ALL* versions of DPDK that provide a 29# libdpdk.pc file). 30# 31# If dpdk_ROOT is set, add ${dpdk_ROOT}/pkgconfig 32# to PKG_CONFIG_PATH, so we look for the .pc file there, 33# first. 34# 35if(PKG_CONFIG_FOUND) 36 set(save_PKG_CONFIG_PATH $ENV{PKG_CONFIG_PATH}) 37 if(dpdk_ROOT) 38 set(ENV{PKG_CONFIG_PATH} "${dpdk_ROOT}/pkgconfig:$ENV{PKG_CONFIG_PATH}") 39 endif() 40 pkg_check_modules(dpdk QUIET libdpdk) 41 if(dpdk_FOUND) 42 # 43 # Get link information for DPDK. 44 # 45 pkg_get_link_info(dpdk libdpdk) 46 endif() 47 set(ENV{PKG_CONFIG_PATH} "${save_PKG_CONFIG_PATH}") 48endif() 49 50mark_as_advanced(dpdk_INCLUDE_DIRS dpdk_LIBRARIES dpdk_STATIC_LIBRARIES dpdk_REQUIRES_PRIVATE) 51 52include(FindPackageHandleStandardArgs) 53find_package_handle_standard_args(dpdk DEFAULT_MSG 54 dpdk_INCLUDE_DIRS 55 dpdk_LIBRARIES) 56 57if(dpdk_FOUND) 58 # 59 # This depends on CMake support for "imported targets", 60 # which are not supported until CMake 3.19. 61 # 62 # Ubuntu 20.04 provides CMake 3.16.3, so we are *NOT* 63 # going to require CMake 3.19. If you want to use 64 # Shiny New Features(TM), wait until all the OSes on 65 # which a build might conceivably be done, and that 66 # provide CMake, provide 3.19 or later. 67 # 68 # Just don't do this stuff on earlier versions. If that 69 # breaks something, figure out a way to do it *without* 70 # "imported targets", and either do this that way, or, 71 # at least, do it that way on older versions of CMake. 72 # 73 # (One good thing about autotools is that only the builders 74 # of a package, and people doing configure-script development, 75 # have to care about the autoconf etc. version; you don't 76 # even need to have autotools installed in order to be able 77 # to run an autotools-generated configure script, you just 78 # need an environment UN*Xy enough, and modern enough, to 79 # run the stuff in the script. 80 # 81 # This is *NOT* the case for CMake; not only do you need 82 # CMake in order to build a package using CMake, you need 83 # a version recent enough to run the stuff the package's 84 # CMake files use. 85 # 86 # Please keep this in mind when changing any CMake files, 87 # and keep in mind what versions of CMake come with, for 88 # example, commonly-used versions of commonly-used 89 # Linux distributiions.) 90 # 91 if(NOT CMAKE_VERSION VERSION_LESS 3.19) 92 if(NOT TARGET dpdk::cflags) 93 if(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x86_64|AMD64") 94 set(rte_cflags "-march=core2") 95 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm|ARM") 96 set(rte_cflags "-march=armv7-a") 97 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|AARCH64") 98 set(rte_cflags "-march=armv8-a+crc") 99 endif() 100 add_library(dpdk::cflags INTERFACE IMPORTED) 101 if (rte_cflags) 102 set_target_properties(dpdk::cflags PROPERTIES 103 INTERFACE_COMPILE_OPTIONS "${rte_cflags}") 104 endif() 105 endif() 106 107 if(NOT TARGET dpdk::dpdk) 108 add_library(dpdk::dpdk INTERFACE IMPORTED) 109 find_package(Threads QUIET) 110 list(APPEND dpdk_LIBRARIES 111 Threads::Threads 112 dpdk::cflags) 113 set_target_properties(dpdk::dpdk PROPERTIES 114 INTERFACE_LINK_LIBRARIES "${dpdk_LIBRARIES}" 115 INTERFACE_INCLUDE_DIRECTORIES "${dpdk_INCLUDE_DIRS}") 116 endif() 117 endif() 118endif() 119