Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 6 additions & 24 deletions components/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -308,31 +308,13 @@ if(CLP_NEED_ZSTD)
endif()
endif()

# Find and setup LZMA Library
# TODO: Add a script in ./cmake/Modules to properly import LZMA in find_package()'s module mode
if(CLP_NEED_LZMA)
if(CLP_NEED_LIBLZMA)
if(CLP_USE_STATIC_LIBS)
set(LIBLZMA_USE_STATIC_LIBS ON)
set(LibLZMA_USE_STATIC_LIBS ON)
endif()
find_package(LibLZMA REQUIRED)
if(LIBLZMA_FOUND)
message(STATUS "Found Lzma ${LIBLZMA_VERSION_STRING}")
message(STATUS "Lzma library location: ${LIBLZMA_LIBRARIES}")
message(STATUS "Lzma Include Dir: ${LIBLZMA_INCLUDE_DIRS}")

# Version 5.8.1 and above address CVE-2024-3094 and CVE-2025-31115.
set(REQUIRED_LIBLZMA_VERSION "5.8.1")
if(LIBLZMA_VERSION_STRING VERSION_LESS ${REQUIRED_LIBLZMA_VERSION})
message(
FATAL_ERROR
"Detected LibLZMA version ${LIBLZMA_VERSION_STRING} is older than required"
" ${REQUIRED_LIBLZMA_VERSION}"
)
endif()
else()
message(FATAL_ERROR "Could not find ${CLP_LIBS_STRING} libraries for Lzma")
endif()
include_directories(${LIBLZMA_INCLUDE_DIRS})
# Version 5.8.1 and above address CVE-2024-3094 and CVE-2025-31115.
find_package(LibLZMA 5.8.1 REQUIRED MODULE)
message(STATUS "Found LibLZMA ${LibLZMA_VERSION}")
endif()

# sqlite dependencies
Expand Down Expand Up @@ -756,6 +738,7 @@ if(CLP_BUILD_TESTING)
fmt::fmt
log_surgeon::log_surgeon
LibArchive::LibArchive
LibLZMA::LibLZMA
MariaDBClient::MariaDBClient
${MONGOCXX_TARGET}
nlohmann_json::nlohmann_json
Expand All @@ -769,7 +752,6 @@ if(CLP_BUILD_TESTING)
yaml-cpp
ystdlib::containers
ystdlib::error_handling
${LIBLZMA_LIBRARIES}
${zstd_TARGET}
)
target_compile_features(unitTest
Expand Down
98 changes: 98 additions & 0 deletions components/core/cmake/Modules/FindLibLZMA.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Try to find LibLZMA
# NOTE: The FindLibLZMA.cmake included with CMake has no support for static libraries, so we use our
# own.
#
# Set LibLZMA_USE_STATIC_LIBS=ON to look for static libraries.
#
# Once done, this will define:
# LibLZMA_FOUND - Whether the library was found on the system
# LibLZMA_INCLUDE_DIR - The library include directories
# LibLZMA_LIBRARY - The path to the library file
# LibLZMA_VERSION - The version of the library installed on the system
#
# Conventions:
# - Variables only for use within the script are prefixed with "liblzma_"
# - Variables that should be externally visible are prefixed with "LibLZMA_"

set(liblzma_HEADER "lzma.h")
set(liblzma_LIBNAME "lzma")
set(liblzma_PKGCONFIG_NAME "liblzma")

if(DEFINED LibLZMA_ROOT)
set(liblzma_PKGCONFIG_DIR "${LibLZMA_ROOT}/lib/pkgconfig")
set(ENV{liblzma_ORIG_PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}")
set(ENV{PKG_CONFIG_PATH} "${liblzma_PKGCONFIG_DIR}:$ENV{PKG_CONFIG_PATH}")
endif()

# Run pkg-config
find_package(PkgConfig)
pkg_check_modules(liblzma_PKGCONF QUIET "${liblzma_PKGCONFIG_NAME}")

# Set include directory
find_path(LibLZMA_INCLUDE_DIR ${liblzma_HEADER}
HINTS ${liblzma_PKGCONF_INCLUDEDIR}
PATH_SUFFIXES include
)

Comment on lines +30 to +35
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add CLP_CORE_DEPS_DIR and lib64 to HINTS/PATH_SUFFIXES to reduce reliance on pkg-config

If pkg-config doesn’t resolve (or resolves to the “other” variant), discovery may fail. Adding CLP_CORE_DEPS_DIR to HINTS and lib64 to PATH_SUFFIXES makes the module resilient and deterministic within your deps prefix.

 find_path(LibLZMA_INCLUDE_DIR ${liblzma_HEADER}
-        HINTS ${liblzma_PKGCONF_INCLUDEDIR}
+        HINTS ${liblzma_PKGCONF_INCLUDEDIR} ${CLP_CORE_DEPS_DIR}
         PATH_SUFFIXES include
         )
@@
 find_library(LibLZMA_LIBRARY
         NAMES "${liblzma_LIBNAME}"
-        HINTS ${liblzma_PKGCONF_LIBDIR}
-        PATH_SUFFIXES lib
+        HINTS ${liblzma_PKGCONF_LIBDIR} ${CLP_CORE_DEPS_DIR}
+        PATH_SUFFIXES lib lib64
         )

Also applies to: 43-47

🤖 Prompt for AI Agents
In components/core/cmake/Modules/FindLibLZMA.cmake around lines 30-35 (and
similarly lines 43-47), the find_path/find_library calls only use pkg-config
hints and "include" suffixes which can fail for non-pkg-config installs; add
CLP_CORE_DEPS_DIR to the HINTS list and add "lib64" to PATH_SUFFIXES so the
search will also look under the deps prefix and 64-bit lib directories; update
both the include and library search blocks to include these new HINTS and
PATH_SUFFIXES entries to make discovery deterministic.

# Handle static libraries
if(LibLZMA_USE_STATIC_LIBS)
set(liblzma_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
endif()

# Find library
find_library(LibLZMA_LIBRARY
NAMES "${liblzma_LIBNAME}"
HINTS ${liblzma_PKGCONF_LIBDIR}
PATH_SUFFIXES lib
)

if(LibLZMA_USE_STATIC_LIBS)
# Restore original value of CMAKE_FIND_LIBRARY_SUFFIXES
set(CMAKE_FIND_LIBRARY_SUFFIXES ${liblzma_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
unset(liblzma_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES)
endif()

# Set version
set(LibLZMA_VERSION ${liblzma_PKGCONF_VERSION})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LibLZMA
REQUIRED_VARS LibLZMA_LIBRARY LibLZMA_INCLUDE_DIR
VERSION_VAR LibLZMA_VERSION
)

if(NOT TARGET LibLZMA::LibLZMA)
# Add library to build
if (LibLZMA_USE_STATIC_LIBS)
add_library(LibLZMA::LibLZMA STATIC IMPORTED)
else()
# NOTE: We use UNKNOWN so that if the user doesn't have the SHARED
# libraries installed, we can still use the STATIC libraries
add_library(LibLZMA::LibLZMA UNKNOWN IMPORTED)
endif()

# Set include directories for library
if(LibLZMA_INCLUDE_DIR)
set_target_properties(LibLZMA::LibLZMA
PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${LibLZMA_INCLUDE_DIR}"
)
endif()

# Set location of library
if(EXISTS "${LibLZMA_LIBRARY}")
set_target_properties(LibLZMA::LibLZMA
PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${LibLZMA_LIBRARY}"
)
endif()
endif()

# Restore original value of PKG_CONFIG_PATH
if(DEFINED LibLZMA_ROOT)
set(ENV{PKG_CONFIG_PATH} "$ENV{liblzma_ORIG_PKG_CONFIG_PATH}")
unset(ENV{liblzma_ORIG_PKG_CONFIG_PATH})
endif()

6 changes: 3 additions & 3 deletions components/core/cmake/Options/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ function(set_clp_tests_dependencies)
CLP_NEED_DATE
CLP_NEED_FMT
CLP_NEED_LIBARCHIVE
CLP_NEED_LIBLZMA
CLP_NEED_LOG_SURGEON
CLP_NEED_LZMA
CLP_NEED_MARIADB
CLP_NEED_MONGOCXX
CLP_NEED_NLOHMANN_JSON
Expand Down Expand Up @@ -456,9 +456,9 @@ function (convert_clp_dependency_properties_to_variables)
CLP_NEED_CURL
CLP_NEED_DATE
CLP_NEED_FMT
CLP_NEED_LOG_SURGEON
CLP_NEED_LIBARCHIVE
CLP_NEED_LZMA
CLP_NEED_LIBLZMA
CLP_NEED_LOG_SURGEON
CLP_NEED_MARIADB
CLP_NEED_MONGOCXX
CLP_NEED_MSGPACKCXX
Expand Down
16 changes: 16 additions & 0 deletions taskfiles/deps/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ tasks:
- task: "catch2"
- task: "date"
- task: "fmt"
- task: "liblzma"
- task: "log-surgeon"
- task: "lz4"
- task: "microsoft.gsl"
Expand Down Expand Up @@ -221,6 +222,21 @@ tasks:
TARBALL_SHA256: "1250e4cc58bf06ee631567523f48848dc4596133e163f02615c97f78bab6c811"
TARBALL_URL: "https://github.com/fmtlib/fmt/archive/refs/tags/10.2.1.tar.gz"

liblzma:
internal: true
run: "once"
cmds:
- task: "utils:install-remote-cmake-lib"
vars:
CMAKE_GEN_ARGS:
- "-DBUILD_SHARED_LIBS=ON"
- "-DCMAKE_BUILD_TYPE=Release"
- "-DCMAKE_INSTALL_MESSAGE=LAZY"
LIB_NAME: "LibLZMA"
TARBALL_SHA256: "507825b599356c10dca1cd720c9d0d0c9d5400b9de300af00e4d1ea150795543"
TARBALL_URL: "https://github.com/tukaani-project/xz/releases/download/v5.8.1\
/xz-5.8.1.tar.gz"

log-surgeon:
internal: true
run: "once"
Expand Down
Loading