2017-11-15 12:54:46 +00:00
|
|
|
function(do_build_dpdk dpdk_dir)
|
2018-08-17 04:27:49 +00:00
|
|
|
# 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.
|
2017-11-15 12:54:46 +00:00
|
|
|
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")
|
2018-08-17 04:27:49 +00:00
|
|
|
set(rte_cflags "-march=core2")
|
2017-11-15 12:54:46 +00:00
|
|
|
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm|ARM")
|
|
|
|
set(arch "arm")
|
|
|
|
set(machine "armv7a")
|
|
|
|
set(machine_tmpl "armv7a")
|
2018-08-17 04:27:49 +00:00
|
|
|
set(rte_cflags "-march=armv7-a")
|
2017-11-15 12:54:46 +00:00
|
|
|
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|AARCH64")
|
|
|
|
set(arch "arm64")
|
|
|
|
set(machine "armv8a")
|
|
|
|
set(machine_tmpl "armv8a")
|
2018-08-17 04:27:49 +00:00
|
|
|
set(rte_cflags "-march=armv8-a+crc")
|
2017-11-15 12:54:46 +00:00
|
|
|
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()
|
2018-08-29 07:38:25 +00:00
|
|
|
set(dpdk_rte_CFLAGS "${rte_cflags}" CACHE INTERNAL "")
|
2017-11-15 12:54:46 +00:00
|
|
|
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
|
2019-06-12 07:21:45 +00:00
|
|
|
set(execenv "linux")
|
2017-11-15 12:54:46 +00:00
|
|
|
elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
|
2019-06-12 07:21:45 +00:00
|
|
|
set(execenv "freebsd")
|
2017-11-15 12:54:46 +00:00
|
|
|
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}")
|
|
|
|
|
2020-04-03 04:39:16 +00:00
|
|
|
include(FindMake)
|
|
|
|
find_make("MAKE_EXECUTABLE" "make_cmd")
|
2017-11-15 12:54:46 +00:00
|
|
|
execute_process(
|
2019-03-21 05:16:13 +00:00
|
|
|
COMMAND ${MAKE_EXECUTABLE} showconfigs
|
2017-11-15 12:54:46 +00:00
|
|
|
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: "
|
2017-11-21 09:45:44 +00:00
|
|
|
"unsupported target. "
|
|
|
|
"\"${target}\" not listed in ${supported_targets}")
|
2017-11-15 12:54:46 +00:00
|
|
|
endif()
|
|
|
|
|
2019-11-06 09:34:32 +00:00
|
|
|
if(Seastar_DPDK AND WITH_SPDK)
|
|
|
|
message(FATAL_ERROR "not able to build DPDK with "
|
|
|
|
"both Seastar_DPDK and WITH_SPDK enabled")
|
|
|
|
elseif(Seastar_DPDK)
|
|
|
|
set(dpdk_source_dir ${CMAKE_SOURCE_DIR}/src/seastar/dpdk)
|
|
|
|
else() # WITH_SPDK or WITH_DPDK is enabled
|
|
|
|
set(dpdk_source_dir ${CMAKE_SOURCE_DIR}/src/spdk/dpdk)
|
|
|
|
endif()
|
|
|
|
|
2017-11-15 12:54:46 +00:00
|
|
|
include(ExternalProject)
|
|
|
|
ExternalProject_Add(dpdk-ext
|
2019-11-06 09:34:32 +00:00
|
|
|
SOURCE_DIR ${dpdk_source_dir}
|
2019-03-21 05:16:13 +00:00
|
|
|
CONFIGURE_COMMAND ${make_cmd} config O=${dpdk_dir} T=${target}
|
2019-06-12 07:21:45 +00:00
|
|
|
BUILD_COMMAND ${make_cmd} O=${dpdk_dir} CC=${CMAKE_C_COMPILER} EXTRA_CFLAGS=-fPIC
|
2017-11-15 12:54:46 +00:00
|
|
|
BUILD_IN_SOURCE 1
|
|
|
|
INSTALL_COMMAND "true")
|
2019-11-14 04:35:37 +00:00
|
|
|
if(NUMA_FOUND)
|
|
|
|
set(numa "y")
|
|
|
|
else()
|
|
|
|
set(numa "n")
|
|
|
|
endif()
|
2017-11-15 12:54:46 +00:00
|
|
|
ExternalProject_Add_Step(dpdk-ext patch-config
|
2019-11-14 04:35:37 +00:00
|
|
|
COMMAND ${CMAKE_MODULE_PATH}/patch-dpdk-conf.sh ${dpdk_dir} ${machine} ${arch} ${numa}
|
2017-11-15 12:54:46 +00:00
|
|
|
DEPENDEES configure
|
|
|
|
DEPENDERS build)
|
|
|
|
# easier to adjust the config
|
|
|
|
ExternalProject_Add_StepTargets(dpdk-ext configure patch-config build)
|
|
|
|
endfunction()
|
|
|
|
|
2019-10-24 06:07:18 +00:00
|
|
|
function(do_export_dpdk dpdk_dir)
|
2018-09-05 07:16:26 +00:00
|
|
|
set(DPDK_INCLUDE_DIR ${dpdk_dir}/include)
|
2017-11-15 12:54:46 +00:00
|
|
|
# create the directory so cmake won't complain when looking at the imported
|
|
|
|
# target
|
|
|
|
file(MAKE_DIRECTORY ${DPDK_INCLUDE_DIR})
|
2018-08-29 07:38:25 +00:00
|
|
|
|
|
|
|
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()
|
|
|
|
|
2019-11-06 09:27:39 +00:00
|
|
|
list(APPEND dpdk_components
|
|
|
|
bus_pci
|
|
|
|
eal
|
|
|
|
kvargs
|
|
|
|
mbuf
|
|
|
|
mempool
|
|
|
|
mempool_ring
|
|
|
|
pci
|
2020-08-19 18:26:32 +00:00
|
|
|
ring
|
|
|
|
telemetry)
|
2019-11-06 09:27:39 +00:00
|
|
|
if(Seastar_DPDK)
|
|
|
|
list(APPEND dpdk_components
|
|
|
|
bus_vdev
|
|
|
|
cfgfile
|
|
|
|
hash
|
|
|
|
net
|
|
|
|
pmd_bnxt
|
|
|
|
pmd_cxgbe
|
|
|
|
pmd_e1000
|
|
|
|
pmd_ena
|
|
|
|
pmd_enic
|
|
|
|
pmd_i40e
|
|
|
|
pmd_ixgbe
|
|
|
|
pmd_nfp
|
|
|
|
pmd_qede
|
|
|
|
pmd_ring
|
|
|
|
pmd_sfc_efx
|
|
|
|
timer)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
foreach(c ${dpdk_components})
|
2017-11-15 12:54:46 +00:00
|
|
|
add_library(dpdk::${c} STATIC IMPORTED)
|
|
|
|
add_dependencies(dpdk::${c} dpdk-ext)
|
|
|
|
set(dpdk_${c}_LIBRARY
|
2018-09-05 07:16:26 +00:00
|
|
|
"${dpdk_dir}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}rte_${c}${CMAKE_STATIC_LIBRARY_SUFFIX}")
|
2017-11-15 12:54:46 +00:00
|
|
|
set_target_properties(dpdk::${c} PROPERTIES
|
|
|
|
INTERFACE_INCLUDE_DIRECTORIES ${DPDK_INCLUDE_DIR}
|
2018-08-17 04:27:49 +00:00
|
|
|
INTERFACE_LINK_LIBRARIES dpdk::cflags
|
2017-11-15 12:54:46 +00:00
|
|
|
IMPORTED_LOCATION "${dpdk_${c}_LIBRARY}")
|
|
|
|
list(APPEND DPDK_LIBRARIES dpdk::${c})
|
2018-08-29 07:38:25 +00:00
|
|
|
list(APPEND DPDK_ARCHIVES "${dpdk_${c}_LIBRARY}")
|
2017-11-15 12:54:46 +00:00
|
|
|
endforeach()
|
2018-08-29 07:38:25 +00:00
|
|
|
|
2019-11-14 04:35:37 +00:00
|
|
|
if(NUMA_FOUND)
|
|
|
|
set(dpdk_numa " -Wl,-lnuma")
|
|
|
|
endif()
|
2018-08-17 04:27:49 +00:00
|
|
|
add_library(dpdk::dpdk INTERFACE IMPORTED)
|
2018-08-29 07:38:25 +00:00
|
|
|
add_dependencies(dpdk::dpdk
|
|
|
|
${DPDK_LIBRARIES})
|
|
|
|
# workaround for https://gitlab.kitware.com/cmake/cmake/issues/16947
|
2018-08-17 04:27:49 +00:00
|
|
|
set_target_properties(dpdk::dpdk PROPERTIES
|
2018-08-29 07:38:25 +00:00
|
|
|
INTERFACE_INCLUDE_DIRECTORIES ${DPDK_INCLUDE_DIR}
|
|
|
|
INTERFACE_LINK_LIBRARIES
|
2019-11-28 12:18:09 +00:00
|
|
|
"-Wl,--whole-archive $<JOIN:${DPDK_ARCHIVES}, > -Wl,--no-whole-archive ${dpdk_numa} -Wl,-lpthread,-ldl")
|
2018-08-29 07:38:25 +00:00
|
|
|
if(dpdk_rte_CFLAGS)
|
|
|
|
set_target_properties(dpdk::dpdk PROPERTIES
|
|
|
|
INTERFACE_COMPILE_OPTIONS "${dpdk_rte_CFLAGS}")
|
|
|
|
endif()
|
2018-09-05 07:16:26 +00:00
|
|
|
endfunction()
|
2019-10-24 06:07:18 +00:00
|
|
|
|
|
|
|
function(build_dpdk dpdk_dir)
|
2019-11-14 04:35:37 +00:00
|
|
|
find_package(NUMA QUIET)
|
2019-10-24 06:07:18 +00:00
|
|
|
if(NOT TARGET dpdk-ext)
|
|
|
|
do_build_dpdk(${dpdk_dir})
|
|
|
|
endif()
|
|
|
|
if(NOT TARGET dpdk::dpdk)
|
|
|
|
do_export_dpdk(${dpdk_dir})
|
|
|
|
endif()
|
|
|
|
endfunction()
|