]> The Tcpdump Group git mirrors - libpcap/blob - cmake/Modules/Finddpdk.cmake
ATM: Simplify protocol and message type handling.
[libpcap] / cmake / Modules / Finddpdk.cmake
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 #
35
36 #
37 # If pkg-config is not available; the last line of the output is:
38 # "-- Could NOT find dpdk (missing: dpdk_INCLUDE_DIRS dpdk_LIBRARIES)"
39 # More than 20 lines before that there is the root cause:
40 # "-- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)"
41 # Print a message to make the cause and the effect easier to relate,
42 # whether the attempt fails or not.
43 #
44 message(STATUS "Using pkg-config to find DPDK: ${PKG_CONFIG_FOUND}")
45
46 if(PKG_CONFIG_FOUND)
47 set(save_PKG_CONFIG_PATH $ENV{PKG_CONFIG_PATH})
48 if(dpdk_ROOT)
49 set(ENV{PKG_CONFIG_PATH} "${dpdk_ROOT}/pkgconfig:$ENV{PKG_CONFIG_PATH}")
50 endif()
51 pkg_check_modules(dpdk QUIET libdpdk)
52 if(dpdk_FOUND)
53 #
54 # Get link information for DPDK.
55 #
56 pkg_get_link_info(dpdk libdpdk)
57 endif()
58 set(ENV{PKG_CONFIG_PATH} "${save_PKG_CONFIG_PATH}")
59 endif()
60
61 mark_as_advanced(dpdk_INCLUDE_DIRS dpdk_LIBRARIES dpdk_STATIC_LIBRARIES dpdk_REQUIRES_PRIVATE)
62
63 include(FindPackageHandleStandardArgs)
64 find_package_handle_standard_args(dpdk DEFAULT_MSG
65 dpdk_INCLUDE_DIRS
66 dpdk_LIBRARIES)
67
68 if(dpdk_FOUND)
69 #
70 # This depends on CMake support for "imported targets",
71 # which are not supported until CMake 3.19.
72 #
73 # Ubuntu 20.04 provides CMake 3.16.3, so we are *NOT*
74 # going to require CMake 3.19. If you want to use
75 # Shiny New Features(TM), wait until all the OSes on
76 # which a build might conceivably be done, and that
77 # provide CMake, provide 3.19 or later.
78 #
79 # Just don't do this stuff on earlier versions. If that
80 # breaks something, figure out a way to do it *without*
81 # "imported targets", and either do this that way, or,
82 # at least, do it that way on older versions of CMake.
83 #
84 # (One good thing about autotools is that only the builders
85 # of a package, and people doing configure-script development,
86 # have to care about the autoconf etc. version; you don't
87 # even need to have autotools installed in order to be able
88 # to run an autotools-generated configure script, you just
89 # need an environment UN*Xy enough, and modern enough, to
90 # run the stuff in the script.
91 #
92 # This is *NOT* the case for CMake; not only do you need
93 # CMake in order to build a package using CMake, you need
94 # a version recent enough to run the stuff the package's
95 # CMake files use.
96 #
97 # Please keep this in mind when changing any CMake files,
98 # and keep in mind what versions of CMake come with, for
99 # example, commonly-used versions of commonly-used
100 # Linux distributions.)
101 #
102 if(NOT CMAKE_VERSION VERSION_LESS 3.19)
103 if(NOT TARGET dpdk::cflags)
104 if(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x86_64|AMD64")
105 set(rte_cflags "-march=core2")
106 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm|ARM")
107 set(rte_cflags "-march=armv7-a")
108 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|AARCH64")
109 set(rte_cflags "-march=armv8-a+crc")
110 endif()
111 add_library(dpdk::cflags INTERFACE IMPORTED)
112 if (rte_cflags)
113 set_target_properties(dpdk::cflags PROPERTIES
114 INTERFACE_COMPILE_OPTIONS "${rte_cflags}")
115 endif()
116 endif()
117
118 if(NOT TARGET dpdk::dpdk)
119 add_library(dpdk::dpdk INTERFACE IMPORTED)
120 find_package(Threads QUIET)
121 list(APPEND dpdk_LIBRARIES
122 Threads::Threads
123 dpdk::cflags)
124 set_target_properties(dpdk::dpdk PROPERTIES
125 INTERFACE_LINK_LIBRARIES "${dpdk_LIBRARIES}"
126 INTERFACE_INCLUDE_DIRECTORIES "${dpdk_INCLUDE_DIRS}")
127 endif()
128 endif()
129 endif()