2017-11-15 12:54:46 +00:00
|
|
|
macro(build_spdk)
|
2018-09-05 07:16:26 +00:00
|
|
|
set(DPDK_DIR ${CMAKE_BINARY_DIR}/src/dpdk)
|
2017-11-15 12:54:46 +00:00
|
|
|
if(NOT TARGET dpdk-ext)
|
|
|
|
include(BuildDPDK)
|
2018-09-05 07:16:26 +00:00
|
|
|
build_dpdk(${DPDK_DIR})
|
2017-11-15 12:54:46 +00:00
|
|
|
endif()
|
|
|
|
find_package(CUnit REQUIRED)
|
2017-11-19 18:09:35 +00:00
|
|
|
if(LINUX)
|
|
|
|
find_package(aio REQUIRED)
|
2017-11-28 10:00:37 +00:00
|
|
|
find_package(uuid REQUIRED)
|
2017-11-19 18:09:35 +00:00
|
|
|
endif()
|
2020-04-03 04:39:16 +00:00
|
|
|
include(FindMake)
|
|
|
|
find_make("MAKE_EXECUTABLE" "make_cmd")
|
2019-03-21 05:16:13 +00:00
|
|
|
|
2019-06-12 13:27:33 +00:00
|
|
|
set(spdk_CFLAGS "-fPIC")
|
|
|
|
include(CheckCCompilerFlag)
|
|
|
|
check_c_compiler_flag("-Wno-address-of-packed-member" HAS_WARNING_ADDRESS_OF_PACKED_MEMBER)
|
|
|
|
if(HAS_WARNING_ADDRESS_OF_PACKED_MEMBER)
|
|
|
|
set(spdk_CFLAGS "${spdk_CFLAGS} -Wno-address-of-packed-member")
|
|
|
|
endif()
|
2017-11-15 12:54:46 +00:00
|
|
|
include(ExternalProject)
|
2020-08-27 09:06:37 +00:00
|
|
|
if(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x86_64|AMD64")
|
|
|
|
# a safer option than relying on the build host's arch
|
|
|
|
set(target_arch core2)
|
|
|
|
else()
|
|
|
|
# default arch used by SPDK
|
|
|
|
set(target_arch native)
|
|
|
|
endif()
|
2021-03-04 07:04:13 +00:00
|
|
|
|
|
|
|
set(source_dir "${CMAKE_SOURCE_DIR}/src/spdk")
|
|
|
|
foreach(c lvol env_dpdk sock nvmf bdev nvme conf thread trace notify accel event_accel blob vmd event_vmd event_bdev sock_posix event_sock event rpc jsonrpc json util log)
|
|
|
|
add_library(spdk::${c} STATIC IMPORTED)
|
|
|
|
set(lib_path "${source_dir}/build/lib/${CMAKE_STATIC_LIBRARY_PREFIX}spdk_${c}${CMAKE_STATIC_LIBRARY_SUFFIX}")
|
|
|
|
set_target_properties(spdk::${c} PROPERTIES
|
|
|
|
IMPORTED_LOCATION "${lib_path}"
|
|
|
|
INTERFACE_INCLUDE_DIRECTORIES "${source_dir}/include")
|
|
|
|
list(APPEND spdk_libs "${lib_path}")
|
|
|
|
list(APPEND SPDK_LIBRARIES spdk::${c})
|
|
|
|
endforeach()
|
|
|
|
|
2017-11-15 12:54:46 +00:00
|
|
|
ExternalProject_Add(spdk-ext
|
|
|
|
DEPENDS dpdk-ext
|
2021-03-04 07:04:13 +00:00
|
|
|
SOURCE_DIR ${source_dir}
|
2020-08-27 09:06:37 +00:00
|
|
|
CONFIGURE_COMMAND ./configure
|
|
|
|
--with-dpdk=${DPDK_DIR}
|
|
|
|
--without-isal
|
|
|
|
--without-vhost
|
|
|
|
--target-arch=${target_arch}
|
2017-11-15 12:54:46 +00:00
|
|
|
# unset $CFLAGS, otherwise it will interfere with how SPDK sets
|
|
|
|
# its include directory.
|
|
|
|
# unset $LDFLAGS, otherwise SPDK will fail to mock some functions.
|
2019-06-12 13:27:33 +00:00
|
|
|
BUILD_COMMAND env -i PATH=$ENV{PATH} CC=${CMAKE_C_COMPILER} ${make_cmd} EXTRA_CFLAGS="${spdk_CFLAGS}"
|
2017-11-15 12:54:46 +00:00
|
|
|
BUILD_IN_SOURCE 1
|
2021-03-04 07:04:13 +00:00
|
|
|
BUILD_BYPRODUCTS ${spdk_libs}
|
2021-03-04 07:16:37 +00:00
|
|
|
INSTALL_COMMAND "")
|
2019-03-21 05:16:13 +00:00
|
|
|
unset(make_cmd)
|
2021-03-04 07:04:13 +00:00
|
|
|
foreach(spdk_lib ${SPDK_LIBRARIES})
|
|
|
|
add_dependencies(${spdk_lib} spdk-ext)
|
2017-11-15 12:54:46 +00:00
|
|
|
endforeach()
|
2021-03-04 07:04:13 +00:00
|
|
|
|
2017-11-15 12:54:46 +00:00
|
|
|
set_target_properties(spdk::env_dpdk PROPERTIES
|
2018-09-05 07:16:26 +00:00
|
|
|
INTERFACE_LINK_LIBRARIES "dpdk::dpdk;rt")
|
2018-06-14 01:32:08 +00:00
|
|
|
set_target_properties(spdk::lvol PROPERTIES
|
|
|
|
INTERFACE_LINK_LIBRARIES spdk::util)
|
|
|
|
set_target_properties(spdk::util PROPERTIES
|
|
|
|
INTERFACE_LINK_LIBRARIES ${UUID_LIBRARIES})
|
2017-11-15 12:54:46 +00:00
|
|
|
set(SPDK_INCLUDE_DIR "${source_dir}/include")
|
|
|
|
unset(source_dir)
|
|
|
|
endmacro()
|