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