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