xref: /freebsd/contrib/libpcap/cmake/Modules/Finddpdk.cmake (revision afdbf109c6a661a729938f68211054a0a50d38ac)
16f9cba8fSJoseph Mingrone# Try to find dpdk
26f9cba8fSJoseph Mingrone#
36f9cba8fSJoseph Mingrone# Once done, this will define
46f9cba8fSJoseph Mingrone#
56f9cba8fSJoseph Mingrone# dpdk_FOUND
66f9cba8fSJoseph Mingrone# dpdk_INCLUDE_DIRS
76f9cba8fSJoseph Mingrone# dpdk_LIBRARIES
86f9cba8fSJoseph Mingrone# dpdk_STATIC_LIBRARIES
96f9cba8fSJoseph Mingrone# dpdk_LIBS_STATIC
106f9cba8fSJoseph Mingrone# dpdk_REQUIRES_PRIVATE
116f9cba8fSJoseph Mingrone# dpdk_PACKAGE_NAME
126f9cba8fSJoseph Mingrone
136f9cba8fSJoseph Mingrone#
146f9cba8fSJoseph Mingrone# We only try to find DPDK using pkg-config; DPDK is *SO*
156f9cba8fSJoseph Mingrone# complicated - DPDK 19.02, for example, has about 117(!)
166f9cba8fSJoseph Mingrone# libraries, and the precise set of libraries required has
176f9cba8fSJoseph Mingrone# changed over time  - so attempting to guess which libraries
186f9cba8fSJoseph Mingrone# you need, and hardcoding that in an attempt to find the
196f9cba8fSJoseph Mingrone# libraries without DPDK, rather than relying on DPDK to
206f9cba8fSJoseph Mingrone# tell you, with a .pc file, what libraries are needed,
216f9cba8fSJoseph Mingrone# is *EXTREMELY* fragile and has caused some bug reports,
226f9cba8fSJoseph Mingrone# so we're just not going to do it.
236f9cba8fSJoseph Mingrone#
246f9cba8fSJoseph Mingrone# If that causes a problem, the only thing we will do is
256f9cba8fSJoseph Mingrone# accept an alternative way of finding the appropriate
266f9cba8fSJoseph Mingrone# library set for the installed version of DPDK that is
276f9cba8fSJoseph Mingrone# as robust as pkg-config (i.e., it had better work as well
286f9cba8fSJoseph Mingrone# as pkg-config with *ALL* versions of DPDK that provide a
296f9cba8fSJoseph Mingrone# libdpdk.pc file).
306f9cba8fSJoseph Mingrone#
316f9cba8fSJoseph Mingrone# If dpdk_ROOT is set, add ${dpdk_ROOT}/pkgconfig
326f9cba8fSJoseph Mingrone# to PKG_CONFIG_PATH, so we look for the .pc file there,
336f9cba8fSJoseph Mingrone# first.
346f9cba8fSJoseph Mingrone#
356f9cba8fSJoseph Mingroneif(PKG_CONFIG_FOUND)
366f9cba8fSJoseph Mingrone  set(save_PKG_CONFIG_PATH $ENV{PKG_CONFIG_PATH})
376f9cba8fSJoseph Mingrone  if(dpdk_ROOT)
386f9cba8fSJoseph Mingrone    set(ENV{PKG_CONFIG_PATH} "${dpdk_ROOT}/pkgconfig:$ENV{PKG_CONFIG_PATH}")
396f9cba8fSJoseph Mingrone  endif()
406f9cba8fSJoseph Mingrone  pkg_check_modules(dpdk QUIET libdpdk)
416f9cba8fSJoseph Mingrone  if(dpdk_FOUND)
426f9cba8fSJoseph Mingrone    #
436f9cba8fSJoseph Mingrone    # Get link information for DPDK.
446f9cba8fSJoseph Mingrone    #
456f9cba8fSJoseph Mingrone    pkg_get_link_info(dpdk libdpdk)
466f9cba8fSJoseph Mingrone  endif()
476f9cba8fSJoseph Mingrone  set(ENV{PKG_CONFIG_PATH} "${save_PKG_CONFIG_PATH}")
486f9cba8fSJoseph Mingroneendif()
496f9cba8fSJoseph Mingrone
506f9cba8fSJoseph Mingronemark_as_advanced(dpdk_INCLUDE_DIRS dpdk_LIBRARIES dpdk_STATIC_LIBRARIES dpdk_REQUIRES_PRIVATE)
516f9cba8fSJoseph Mingrone
526f9cba8fSJoseph Mingroneinclude(FindPackageHandleStandardArgs)
536f9cba8fSJoseph Mingronefind_package_handle_standard_args(dpdk DEFAULT_MSG
546f9cba8fSJoseph Mingrone  dpdk_INCLUDE_DIRS
556f9cba8fSJoseph Mingrone  dpdk_LIBRARIES)
566f9cba8fSJoseph Mingrone
576f9cba8fSJoseph Mingroneif(dpdk_FOUND)
586f9cba8fSJoseph Mingrone  #
596f9cba8fSJoseph Mingrone  # This depends on CMake support for "imported targets",
606f9cba8fSJoseph Mingrone  # which are not supported until CMake 3.19.
616f9cba8fSJoseph Mingrone  #
626f9cba8fSJoseph Mingrone  # Ubuntu 20.04 provides CMake 3.16.3, so we are *NOT*
636f9cba8fSJoseph Mingrone  # going to require CMake 3.19.  If you want to use
646f9cba8fSJoseph Mingrone  # Shiny New Features(TM), wait until all the OSes on
656f9cba8fSJoseph Mingrone  # which a build might conceivably be done, and that
666f9cba8fSJoseph Mingrone  # provide CMake, provide 3.19 or later.
676f9cba8fSJoseph Mingrone  #
686f9cba8fSJoseph Mingrone  # Just don't do this stuff on earlier versions.  If that
696f9cba8fSJoseph Mingrone  # breaks something, figure out a way to do it *without*
706f9cba8fSJoseph Mingrone  # "imported targets", and either do this that way, or,
716f9cba8fSJoseph Mingrone  # at least, do it that way on older versions of CMake.
726f9cba8fSJoseph Mingrone  #
736f9cba8fSJoseph Mingrone  # (One good thing about autotools is that only the builders
746f9cba8fSJoseph Mingrone  # of a package, and people doing configure-script development,
756f9cba8fSJoseph Mingrone  # have to care about the autoconf etc. version; you don't
766f9cba8fSJoseph Mingrone  # even need to have autotools installed in order to be able
776f9cba8fSJoseph Mingrone  # to run an autotools-generated configure script, you just
786f9cba8fSJoseph Mingrone  # need an environment UN*Xy enough, and modern enough, to
796f9cba8fSJoseph Mingrone  # run the stuff in the script.
806f9cba8fSJoseph Mingrone  #
816f9cba8fSJoseph Mingrone  # This is *NOT* the case for CMake; not only do you need
826f9cba8fSJoseph Mingrone  # CMake in order to build a package using CMake, you need
836f9cba8fSJoseph Mingrone  # a version recent enough to run the stuff the package's
846f9cba8fSJoseph Mingrone  # CMake files use.
856f9cba8fSJoseph Mingrone  #
866f9cba8fSJoseph Mingrone  # Please keep this in mind when changing any CMake files,
876f9cba8fSJoseph Mingrone  # and keep in mind what versions of CMake come with, for
886f9cba8fSJoseph Mingrone  # example, commonly-used versions of commonly-used
89*afdbf109SJoseph Mingrone  # Linux distributions.)
906f9cba8fSJoseph Mingrone  #
916f9cba8fSJoseph Mingrone  if(NOT CMAKE_VERSION VERSION_LESS 3.19)
926f9cba8fSJoseph Mingrone    if(NOT TARGET dpdk::cflags)
936f9cba8fSJoseph Mingrone       if(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x86_64|AMD64")
946f9cba8fSJoseph Mingrone        set(rte_cflags "-march=core2")
956f9cba8fSJoseph Mingrone      elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm|ARM")
966f9cba8fSJoseph Mingrone        set(rte_cflags "-march=armv7-a")
976f9cba8fSJoseph Mingrone      elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|AARCH64")
986f9cba8fSJoseph Mingrone        set(rte_cflags "-march=armv8-a+crc")
996f9cba8fSJoseph Mingrone      endif()
1006f9cba8fSJoseph Mingrone      add_library(dpdk::cflags INTERFACE IMPORTED)
1016f9cba8fSJoseph Mingrone      if (rte_cflags)
1026f9cba8fSJoseph Mingrone        set_target_properties(dpdk::cflags PROPERTIES
1036f9cba8fSJoseph Mingrone          INTERFACE_COMPILE_OPTIONS "${rte_cflags}")
1046f9cba8fSJoseph Mingrone      endif()
1056f9cba8fSJoseph Mingrone    endif()
1066f9cba8fSJoseph Mingrone
1076f9cba8fSJoseph Mingrone    if(NOT TARGET dpdk::dpdk)
1086f9cba8fSJoseph Mingrone      add_library(dpdk::dpdk INTERFACE IMPORTED)
1096f9cba8fSJoseph Mingrone      find_package(Threads QUIET)
1106f9cba8fSJoseph Mingrone      list(APPEND dpdk_LIBRARIES
1116f9cba8fSJoseph Mingrone        Threads::Threads
1126f9cba8fSJoseph Mingrone        dpdk::cflags)
1136f9cba8fSJoseph Mingrone      set_target_properties(dpdk::dpdk PROPERTIES
1146f9cba8fSJoseph Mingrone        INTERFACE_LINK_LIBRARIES "${dpdk_LIBRARIES}"
1156f9cba8fSJoseph Mingrone        INTERFACE_INCLUDE_DIRECTORIES "${dpdk_INCLUDE_DIRS}")
1166f9cba8fSJoseph Mingrone    endif()
1176f9cba8fSJoseph Mingrone  endif()
1186f9cba8fSJoseph Mingroneendif()
119