]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: add WITH_SYSTEM_SPDK to link a system-installed SPDK 69185/head
authorSun Yuechi <sunyuechi@iscas.ac.cn>
Sat, 30 May 2026 06:15:12 +0000 (14:15 +0800)
committerSun Yuechi <sunyuechi@iscas.ac.cn>
Sun, 31 May 2026 00:33:11 +0000 (08:33 +0800)
By default ceph builds the bundled src/spdk fork via BuildSPDK. Add a
WITH_SYSTEM_SPDK option that instead locates a distro-provided SPDK
through a new Findspdk.cmake (pkg-config based, modelled on
Finddpdk.cmake), exposing the same spdk::spdk target.

Signed-off-by: Sun Yuechi <sunyuechi@iscas.ac.cn>
CMakeLists.txt
cmake/modules/Findspdk.cmake [new file with mode: 0644]

index 3c7b3b579c1e1da781c42bbf68ddabb2488c275c..8aefd36e16b93eff0a68e2dda34f6098c432e351 100644 (file)
@@ -326,13 +326,18 @@ if(WITH_BLUESTORE_PMEM)
 endif()
 
 CMAKE_DEPENDENT_OPTION(WITH_SPDK "Enable SPDK" OFF
-  "CMAKE_SYSTEM_PROCESSOR MATCHES i386|i686|amd64|x86_64|AMD64|aarch64" OFF)
+  "CMAKE_SYSTEM_PROCESSOR MATCHES i386|i686|amd64|x86_64|AMD64|aarch64|riscv64" OFF)
+option(WITH_SYSTEM_SPDK "Require a system SPDK instead of building bundled src/spdk" OFF)
 if(WITH_SPDK)
   if(NOT WITH_BLUESTORE)
     message(SEND_ERROR "Please enable WITH_BLUESTORE for using SPDK")
   endif()
-  include(BuildSPDK)
-  build_spdk()
+  if(WITH_SYSTEM_SPDK)
+    find_package(spdk REQUIRED)
+  else()
+    include(BuildSPDK)
+    build_spdk()
+  endif()
   set(HAVE_SPDK TRUE)
 endif(WITH_SPDK)
 
diff --git a/cmake/modules/Findspdk.cmake b/cmake/modules/Findspdk.cmake
new file mode 100644 (file)
index 0000000..eef8275
--- /dev/null
@@ -0,0 +1,26 @@
+# Findspdk.cmake -- locate a system-installed SPDK via pkg-config.
+#
+# Paired with WITH_SYSTEM_SPDK: link a distro-provided spdk-devel instead of
+# building the bundled src/spdk fork. Modelled on Finddpdk.cmake.
+#
+# Provides: spdk::spdk, spdk_FOUND, SPDK_INCLUDE_DIRS
+
+find_package(PkgConfig REQUIRED QUIET)
+
+pkg_check_modules(SPDK IMPORTED_TARGET spdk_nvme spdk_env_dpdk)
+
+# spdk's .so leave ISA-L symbols (crc32_iscsi, xor_gen, ...) undefined for the
+# final link and don't Require isa-l in their .pc; pull it in explicitly.
+pkg_check_modules(ISAL REQUIRED IMPORTED_TARGET libisal)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(spdk
+  REQUIRED_VARS SPDK_FOUND SPDK_INCLUDE_DIRS)
+
+if(spdk_FOUND AND NOT TARGET spdk::spdk)
+  add_library(spdk::spdk INTERFACE IMPORTED)
+  # SPDK/DPDK register drivers via C constructors; keep the libs in DT_NEEDED
+  # (shared-lib equivalent of the bundled target's --whole-archive).
+  set_target_properties(spdk::spdk PROPERTIES
+    INTERFACE_LINK_LIBRARIES "-Wl,--no-as-needed;PkgConfig::SPDK;PkgConfig::ISAL")
+endif()