]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: add WITH_SYSTEM_JERASURE option for system jerasure and gf-complete
authorKefu Chai <k.chai@proxmox.com>
Wed, 8 Apr 2026 10:37:25 +0000 (18:37 +0800)
committerKefu Chai <k.chai@proxmox.com>
Wed, 8 Apr 2026 10:42:19 +0000 (18:42 +0800)
Add a cmake option to build ceph's erasure code plugins (ec_jerasure
and ec_shec) against system-provided jerasure and gf-complete libraries
instead of the vendored copies.

This allows downstream distributions to build with their own packaged
versions of these libraries. For instance, Debian has shipped
libjerasure-dev and libgf-complete-dev as build dependencies for ceph
since 2021, but the build always used the vendored copies because there
was no cmake option to use the system ones.

Using system libraries also lets distributions benefit from any
optimizations or fixes applied to their packages without having to
carry patches against ceph's vendored copies. For example, the vendored
gf-complete requires a downstream -O1 workaround to avoid emitting
SSE 4.1 instructions that crash on older CPUs. But with system libraries,
that becomes the library package's responsibility.

The option is OFF by default, preserving the current behavior of
building from vendored sources.

A new FindJerasure.cmake module locates the system jerasure and
gf-complete headers and libraries, and creates the Jerasure::jerasure
imported target with the same target name that the vendored build now
provides (see previous commit).

Signed-off-by: Kefu Chai <k.chai@proxmox.com>
CMakeLists.txt
cmake/modules/FindJerasure.cmake [new file with mode: 0644]
src/erasure-code/CMakeLists.txt
src/erasure-code/jerasure/CMakeLists.txt

index 7217da88de583764450b83d70be990168ad8f61a..3c7b3b579c1e1da781c42bbf68ddabb2488c275c 100644 (file)
@@ -733,6 +733,12 @@ if(sanitizers)
   string(APPEND CMAKE_SHARED_LINKER_FLAGS " ${sanitiers_compile_flags}")
 endif()
 
+# Jerasure & GF-Complete
+option(WITH_SYSTEM_JERASURE "require and build with system jerasure and gf-complete" OFF)
+if(WITH_SYSTEM_JERASURE)
+  find_package(Jerasure REQUIRED)
+endif()
+
 # Rocksdb
 option(WITH_SYSTEM_ROCKSDB "require and build with system rocksdb" OFF)
 if (WITH_SYSTEM_ROCKSDB)
diff --git a/cmake/modules/FindJerasure.cmake b/cmake/modules/FindJerasure.cmake
new file mode 100644 (file)
index 0000000..b27b687
--- /dev/null
@@ -0,0 +1,66 @@
+# - Find Jerasure and GF-Complete
+# Find the jerasure and gf-complete libraries and includes
+#
+# Jerasure_INCLUDE_DIR - where to find jerasure.h
+# Jerasure_SUBHEADER_DIR - where to find galois.h, cauchy.h, etc.
+# Jerasure_LIBRARY - the jerasure library
+# GFComplete_INCLUDE_DIR - where to find gf_complete.h
+# GFComplete_LIBRARY - the gf-complete library
+# Jerasure_FOUND - True if both jerasure and gf-complete found.
+
+find_path(Jerasure_INCLUDE_DIR jerasure.h)
+
+# jerasure sub-headers (galois.h, cauchy.h, etc.) may be installed in a
+# jerasure/ subdirectory. The main jerasure.h includes them with bare
+# #include "galois.h", so this directory must be on the include path.
+find_path(Jerasure_SUBHEADER_DIR galois.h
+  PATH_SUFFIXES jerasure)
+
+find_library(Jerasure_LIBRARY NAMES Jerasure)
+
+find_path(GFComplete_INCLUDE_DIR gf_complete.h)
+
+find_library(GFComplete_LIBRARY NAMES gf_complete)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(Jerasure
+  REQUIRED_VARS
+    Jerasure_INCLUDE_DIR
+    Jerasure_SUBHEADER_DIR
+    Jerasure_LIBRARY
+    GFComplete_INCLUDE_DIR
+    GFComplete_LIBRARY)
+
+if(Jerasure_FOUND)
+  set(Jerasure_INCLUDE_DIRS
+    ${Jerasure_INCLUDE_DIR}
+    ${Jerasure_SUBHEADER_DIR}
+    ${GFComplete_INCLUDE_DIR})
+  set(Jerasure_LIBRARIES
+    ${Jerasure_LIBRARY}
+    ${GFComplete_LIBRARY})
+
+  if(NOT TARGET Jerasure::jerasure)
+    add_library(Jerasure::jerasure UNKNOWN IMPORTED GLOBAL)
+    set_target_properties(Jerasure::jerasure PROPERTIES
+      INTERFACE_INCLUDE_DIRECTORIES "${Jerasure_INCLUDE_DIR};${Jerasure_SUBHEADER_DIR}"
+      IMPORTED_LINK_INTERFACE_LANGUAGES "C"
+      IMPORTED_LOCATION "${Jerasure_LIBRARY}"
+      INTERFACE_LINK_LIBRARIES "${GFComplete_LIBRARY}")
+  endif()
+
+  if(NOT TARGET Jerasure::GFComplete)
+    add_library(Jerasure::GFComplete UNKNOWN IMPORTED GLOBAL)
+    set_target_properties(Jerasure::GFComplete PROPERTIES
+      INTERFACE_INCLUDE_DIRECTORIES "${GFComplete_INCLUDE_DIR}"
+      IMPORTED_LINK_INTERFACE_LANGUAGES "C"
+      IMPORTED_LOCATION "${GFComplete_LIBRARY}")
+  endif()
+endif()
+
+mark_as_advanced(
+  Jerasure_INCLUDE_DIR
+  Jerasure_SUBHEADER_DIR
+  Jerasure_LIBRARY
+  GFComplete_INCLUDE_DIR
+  GFComplete_LIBRARY)
index cc5a84e9dc1bea1c543d8ca69bf6ab3f07c4fec5..167a1ba39a82ff40c42457194367b155d0c160b4 100644 (file)
@@ -3,8 +3,12 @@
 set(erasure_plugin_dir ${CEPH_INSTALL_PKGLIBDIR}/erasure-code)
 
 #jerasure subdir must be before shec so jerasure & neon obj libs are declared
-include_directories(SYSTEM jerasure/jerasure/include)
-include_directories(SYSTEM jerasure/gf-complete/include)
+if(WITH_SYSTEM_JERASURE)
+  include_directories(SYSTEM ${Jerasure_INCLUDE_DIRS})
+else()
+  include_directories(SYSTEM jerasure/jerasure/include)
+  include_directories(SYSTEM jerasure/gf-complete/include)
+endif()
 include_directories(jerasure)
 
 # legacy jerasure flavors. these are left here for backward compatibility
index acd063c59240ec3b015c99b4de6d6d7ed3846f7b..c97888fd989cbdab2a52245cfbc94b29703ee3d3 100644 (file)
@@ -11,6 +11,7 @@ target_link_libraries(jerasure_utils legacy-option-headers)
 # not part of the jerasure library itself.
 add_library(jerasure_init_objs OBJECT jerasure_init.cc)
 
+if(NOT WITH_SYSTEM_JERASURE)
 # Set the CFLAGS correctly for gf-complete based on SIMD compiler support
 set(GF_COMPILE_FLAGS)
 if(HAVE_ARMV8_SIMD)
@@ -92,6 +93,7 @@ add_library(jerasure_vendored STATIC
   $<TARGET_OBJECTS:gf-complete_objs>
   $<TARGET_OBJECTS:jerasure_lib_objs>)
 add_library(Jerasure::jerasure ALIAS jerasure_vendored)
+endif()
 
 # ec_jerasure plugin
 set(ec_jerasure_objs