From: Kefu Chai Date: Wed, 8 Apr 2026 10:37:25 +0000 (+0800) Subject: cmake: add WITH_SYSTEM_JERASURE option for system jerasure and gf-complete X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e35375b67324a875bd5e99a7758faf07259cc9ca;p=ceph.git cmake: add WITH_SYSTEM_JERASURE option for system jerasure and gf-complete 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 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 7217da88de5..3c7b3b579c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 index 00000000000..b27b687e8c8 --- /dev/null +++ b/cmake/modules/FindJerasure.cmake @@ -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) diff --git a/src/erasure-code/CMakeLists.txt b/src/erasure-code/CMakeLists.txt index cc5a84e9dc1..167a1ba39a8 100644 --- a/src/erasure-code/CMakeLists.txt +++ b/src/erasure-code/CMakeLists.txt @@ -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 diff --git a/src/erasure-code/jerasure/CMakeLists.txt b/src/erasure-code/jerasure/CMakeLists.txt index acd063c5924..c97888fd989 100644 --- a/src/erasure-code/jerasure/CMakeLists.txt +++ b/src/erasure-code/jerasure/CMakeLists.txt @@ -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 $ $) add_library(Jerasure::jerasure ALIAS jerasure_vendored) +endif() # ec_jerasure plugin set(ec_jerasure_objs