summaryrefslogtreecommitdiffstats
path: root/cmake/modules/BuildDPDK.cmake
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
commit483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch)
treee5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /cmake/modules/BuildDPDK.cmake
parentInitial commit. (diff)
downloadceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz
ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'cmake/modules/BuildDPDK.cmake')
-rw-r--r--cmake/modules/BuildDPDK.cmake140
1 files changed, 140 insertions, 0 deletions
diff --git a/cmake/modules/BuildDPDK.cmake b/cmake/modules/BuildDPDK.cmake
new file mode 100644
index 00000000..fe4a0acf
--- /dev/null
+++ b/cmake/modules/BuildDPDK.cmake
@@ -0,0 +1,140 @@
+function(do_build_dpdk dpdk_dir)
+ # mk/machine/native/rte.vars.mk
+ # rte_cflags are extracted from mk/machine/${machine}/rte.vars.mk
+ # only 3 of them have -march=<arch> defined, so copying them here.
+ # we need to pass the -march=<arch> to ${cc} as some headers in dpdk
+ # require it to compile. for instance, dpdk/include/rte_memcpy.h.
+ if(CMAKE_SYSTEM_PROCESSOR MATCHES "i386")
+ set(arch "x86_64")
+ set(machine "default")
+ set(machine_tmpl "native")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "i686")
+ set(arch "i686")
+ set(machine "default")
+ set(machine_tmpl "native")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x86_64|AMD64")
+ set(arch "x86_64")
+ set(machine "default")
+ set(machine_tmpl "native")
+ set(rte_cflags "-march=core2")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm|ARM")
+ set(arch "arm")
+ set(machine "armv7a")
+ set(machine_tmpl "armv7a")
+ set(rte_cflags "-march=armv7-a")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|AARCH64")
+ set(arch "arm64")
+ set(machine "armv8a")
+ set(machine_tmpl "armv8a")
+ set(rte_cflags "-march=armv8-a+crc")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "(powerpc|ppc)64")
+ set(arch "ppc_64")
+ set(machine "power8")
+ set(machine_tmpl "power8")
+ else()
+ message(FATAL_ERROR "not able to build DPDK support: "
+ "unknown arch \"${CMAKE_SYSTEM_PROCESSOR}\"")
+ endif()
+ set(dpdk_rte_CFLAGS "${rte_cflags}" CACHE INTERNAL "")
+ if(CMAKE_SYSTEM_NAME MATCHES "Linux")
+ set(execenv "linuxapp")
+ elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
+ set(execenv "bsdapp")
+ else()
+ message(FATAL_ERROR "not able to build DPDK support: "
+ "unsupported OS \"${CMAKE_SYSTEM_NAME}\"")
+ endif()
+
+ if(CMAKE_C_COMPILER_ID STREQUAL GNU)
+ set(toolchain "gcc")
+ elseif(CMAKE_C_COMPILER_ID STREQUAL Clang)
+ set(toolchain "clang")
+ elseif(CMAKE_C_COMPILER_ID STREQUAL Intel)
+ set(toolchain "icc")
+ else()
+ message(FATAL_ERROR "not able to build DPDK support: "
+ "unknown compiler \"${CMAKE_C_COMPILER_ID}\"")
+ endif()
+
+ set(target "${arch}-${machine_tmpl}-${execenv}-${toolchain}")
+
+ execute_process(
+ COMMAND ${CMAKE_MAKE_PROGRAM} showconfigs
+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/src/spdk/dpdk
+ OUTPUT_VARIABLE supported_targets
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ string(REPLACE "\n" ";" supported_targets "${supported_targets}")
+ list(FIND supported_targets ${target} found)
+ if(found EQUAL -1)
+ message(FATAL_ERROR "not able to build DPDK support: "
+ "unsupported target. "
+ "\"${target}\" not listed in ${supported_targets}")
+ endif()
+
+ set(EXTRA_CFLAGS "-Wno-unknown-warning-option -Wno-stringop-truncation -Wno-address-of-packed-member -fPIC")
+
+ include(ExternalProject)
+ ExternalProject_Add(dpdk-ext
+ SOURCE_DIR ${CMAKE_SOURCE_DIR}/src/spdk/dpdk
+ CONFIGURE_COMMAND $(MAKE) config O=${dpdk_dir} T=${target}
+ BUILD_COMMAND env CC=${CMAKE_C_COMPILER} $(MAKE) O=${dpdk_dir} EXTRA_CFLAGS=${EXTRA_CFLAGS}
+ BUILD_IN_SOURCE 1
+ INSTALL_COMMAND "true")
+ ExternalProject_Add_Step(dpdk-ext patch-config
+ COMMAND ${CMAKE_MODULE_PATH}/patch-dpdk-conf.sh ${dpdk_dir} ${machine} ${arch}
+ DEPENDEES configure
+ DEPENDERS build)
+ # easier to adjust the config
+ ExternalProject_Add_StepTargets(dpdk-ext configure patch-config build)
+endfunction()
+
+function(build_dpdk dpdk_dir)
+ do_build_dpdk(${dpdk_dir})
+ set(DPDK_INCLUDE_DIR ${dpdk_dir}/include)
+ # create the directory so cmake won't complain when looking at the imported
+ # target
+ file(MAKE_DIRECTORY ${DPDK_INCLUDE_DIR})
+
+ if(NOT TARGET dpdk::cflags)
+ add_library(dpdk::cflags INTERFACE IMPORTED)
+ if (dpdk_rte_CFLAGS)
+ set_target_properties(dpdk::cflags PROPERTIES
+ INTERFACE_COMPILE_OPTIONS "${dpdk_rte_CFLAGS}")
+ endif()
+ endif()
+
+ foreach(c
+ bus_pci
+ eal
+ ethdev
+ kvargs
+ mbuf
+ mempool
+ mempool_ring
+ pci
+ ring)
+ add_library(dpdk::${c} STATIC IMPORTED)
+ add_dependencies(dpdk::${c} dpdk-ext)
+ set(dpdk_${c}_LIBRARY
+ "${dpdk_dir}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}rte_${c}${CMAKE_STATIC_LIBRARY_SUFFIX}")
+ set_target_properties(dpdk::${c} PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES ${DPDK_INCLUDE_DIR}
+ INTERFACE_LINK_LIBRARIES dpdk::cflags
+ IMPORTED_LOCATION "${dpdk_${c}_LIBRARY}")
+ list(APPEND DPDK_LIBRARIES dpdk::${c})
+ list(APPEND DPDK_ARCHIVES "${dpdk_${c}_LIBRARY}")
+ endforeach()
+
+ add_library(dpdk::dpdk INTERFACE IMPORTED)
+ add_dependencies(dpdk::dpdk
+ ${DPDK_LIBRARIES})
+ # workaround for https://gitlab.kitware.com/cmake/cmake/issues/16947
+ set_target_properties(dpdk::dpdk PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES ${DPDK_INCLUDE_DIR}
+ INTERFACE_LINK_LIBRARIES
+ "-Wl,--whole-archive $<JOIN:${DPDK_ARCHIVES}, > -Wl,--no-whole-archive")
+ if(dpdk_rte_CFLAGS)
+ set_target_properties(dpdk::dpdk PROPERTIES
+ INTERFACE_COMPILE_OPTIONS "${dpdk_rte_CFLAGS}")
+ endif()
+endfunction()