ceph-mirror/cmake/modules/FindJerasure.cmake
Kefu Chai e35375b673 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 <k.chai@proxmox.com>
2026-04-08 18:42:19 +08:00

67 lines
2.1 KiB
CMake

# - 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)