Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
34 changes: 10 additions & 24 deletions components/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ if(PROJECT_IS_TOP_LEVEL)
# Include dependency settings if the project isn't being included as a subproject.
# NOTE: We mark the file optional since it's not required if the user happens to have the
# dependencies installed already.
include("${CMAKE_SOURCE_DIR}/../../build/deps/core/cmake-settings/all.cmake"
set(CLP_CORE_DEPS_DIR "${CMAKE_SOURCE_DIR}/../../build/deps/core")
include("${CLP_CORE_DEPS_DIR}/cmake-settings/all.cmake"
OPTIONAL
RESULT_VARIABLE CLP_DEPS_SETTINGS_FILE_PATH
)
Expand Down Expand Up @@ -308,31 +309,16 @@ 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)
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()
set(LibLZMA_ROOT ${LibLZMA-static_ROOT})
set(LibLZMA_USE_STATIC_LIBS ON)
else()
message(FATAL_ERROR "Could not find ${CLP_LIBS_STRING} libraries for Lzma")
set(LibLZMA_ROOT ${LibLZMA-shared_ROOT})
endif()
Comment on lines +312 to 318
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Avoid per-variant LibLZMA_ROOT; rely on CLP_CORE_DEPS_DIR and toggle only LibLZMA_USE_STATIC_LIBS.

Per retrieved learnings, our Find modules already search within CLP_CORE_DEPS_DIR and handle static/shared selection via LibLZMA_USE_STATIC_LIBS. The LibLZMA-static_ROOT / LibLZMA-shared_ROOT overrides are unnecessary and add maintenance burden.

Apply this diff:

 if(CLP_NEED_LIBLZMA)
     if(CLP_USE_STATIC_LIBS)
-        set(LibLZMA_ROOT ${LibLZMA-static_ROOT})
         set(LibLZMA_USE_STATIC_LIBS ON)
     else()
-        set(LibLZMA_ROOT ${LibLZMA-shared_ROOT})
+        # Be explicit to avoid stale cache values from toolchain/user presets.
+        set(LibLZMA_USE_STATIC_LIBS OFF)
     endif()
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if(CLP_NEED_LIBLZMA)
if(CLP_USE_STATIC_LIBS)
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()
set(LibLZMA_ROOT ${LibLZMA-static_ROOT})
set(LibLZMA_USE_STATIC_LIBS ON)
else()
message(FATAL_ERROR "Could not find ${CLP_LIBS_STRING} libraries for Lzma")
set(LibLZMA_ROOT ${LibLZMA-shared_ROOT})
endif()
if(CLP_NEED_LIBLZMA)
if(CLP_USE_STATIC_LIBS)
set(LibLZMA_USE_STATIC_LIBS ON)
else()
# Be explicit to avoid stale cache values from toolchain/user presets.
set(LibLZMA_USE_STATIC_LIBS OFF)
endif()
🤖 Prompt for AI Agents
In components/core/CMakeLists.txt around lines 312 to 318, remove the
per-variant assignments to LibLZMA_ROOT (LibLZMA-static_ROOT /
LibLZMA-shared_ROOT) and instead only toggle LibLZMA_USE_STATIC_LIBS when
CLP_USE_STATIC_LIBS is true; rely on the existing CLP_CORE_DEPS_DIR-aware Find
modules to locate the library. Concretely, eliminate the set(LibLZMA_ROOT ...)
calls and keep or add only set(LibLZMA_USE_STATIC_LIBS ON) under the
CLP_USE_STATIC_LIBS branch so the Find module picks static vs shared
automatically. Ensure no other code expects LibLZMA_ROOT to be set; if it does,
remove or adapt those expectations to use the Find module behavior.

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)
message(STATUS "Found LibLZMA ${LibLZMA_VERSION}")
endif()

# sqlite dependencies
Expand Down Expand Up @@ -759,6 +745,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 @@ -771,7 +758,6 @@ if(CLP_BUILD_TESTING)
clp::string_utils
ystdlib::containers
ystdlib::error_handling
${LIBLZMA_LIBRARIES}
${zstd_TARGET}
)
target_compile_features(unitTest
Expand Down
96 changes: 96 additions & 0 deletions components/core/cmake/Modules/FindLibLZMA.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# 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 CLP_CORE_DEPS_DIR)
set(ENV{liblzma_ORIG_PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}")
set(ENV{PKG_CONFIG_PATH} "${CLP_CORE_DEPS_DIR}:$ENV{PKG_CONFIG_PATH}")
endif()
Comment on lines +21 to +24
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

Use platform-appropriate PKG_CONFIG_PATH separator and handle empty PATH robustly

On Windows, PKG_CONFIG_PATH must use “;” instead of “:”. Also guard for an initially empty PKG_CONFIG_PATH to avoid leading/trailing separators.

Apply:

-if(DEFINED CLP_CORE_DEPS_DIR)
-    set(ENV{liblzma_ORIG_PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}")
-    set(ENV{PKG_CONFIG_PATH} "${CLP_CORE_DEPS_DIR}:$ENV{PKG_CONFIG_PATH}")
-endif()
+if(DEFINED CLP_CORE_DEPS_DIR)
+    set(ENV{liblzma_ORIG_PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}")
+    if(WIN32)
+        set(_liblzma_pkgconf_sep ";")
+    else()
+        set(_liblzma_pkgconf_sep ":")
+    endif()
+    if("$ENV{PKG_CONFIG_PATH}" STREQUAL "")
+        set(ENV{PKG_CONFIG_PATH} "${CLP_CORE_DEPS_DIR}")
+    else()
+        set(ENV{PKG_CONFIG_PATH} "${CLP_CORE_DEPS_DIR}${_liblzma_pkgconf_sep}$ENV{PKG_CONFIG_PATH}")
+    endif()
+    unset(_liblzma_pkgconf_sep)
+endif()
🤖 Prompt for AI Agents
In components/core/cmake/Modules/FindLibLZMA.cmake around lines 21 to 24, the
code unconditionally concatenates CLP_CORE_DEPS_DIR into PKG_CONFIG_PATH with
":" which breaks on Windows and can produce stray separators when
PKG_CONFIG_PATH is empty; update it to choose the separator based on the
platform (use ";" on Windows (WIN32) and ":" otherwise), preserve the original
PKG_CONFIG_PATH in an env var as before, and build the new PKG_CONFIG_PATH by
checking if the existing PKG_CONFIG_PATH is empty—if empty, set it to
CLP_CORE_DEPS_DIR only, otherwise join CLP_CORE_DEPS_DIR and the existing value
with the selected separator—so no leading/trailing separators appear.


# 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 "${CMAKE_STATIC_LIBRARY_SUFFIX}")
endif()

Comment on lines +36 to +41
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

Prefer static when requested but gracefully fall back to shared

Current logic restricts suffixes to static (when LibLZMA_USE_STATIC_LIBS is ON), which will hard-fail if the static variant isn’t installed or the resolved libdir points at the shared install. Align with the project’s pattern: prefer static, then fall back to shared.

Option A (single-pass preference via suffix ordering):

 if(LibLZMA_USE_STATIC_LIBS)
-    set(liblzma_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
-    set(CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_STATIC_LIBRARY_SUFFIX}")
+    set(liblzma_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
+    # Prefer static by putting it first, but keep originals for fallback.
+    set(CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_STATIC_LIBRARY_SUFFIX};${CMAKE_FIND_LIBRARY_SUFFIXES}")
 endif()
@@
 find_library(LibLZMA_LIBRARY
         NAMES "${liblzma_LIBNAME}"
         HINTS ${liblzma_PKGCONF_LIBDIR} ${CLP_CORE_DEPS_DIR}
-        PATH_SUFFIXES lib
+        PATH_SUFFIXES lib lib64
         )
 
 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()

Option B (two-pass fallback if you want strict separation):

  • First try with static-only suffix list.
  • If not found, restore suffixes and try again without static preference, emitting a STATUS message.
    Ask if you want me to draft this variant.

Also applies to: 43-53

🤖 Prompt for AI Agents
In components/core/cmake/Modules/FindLibLZMA.cmake around lines 36-41 (and
similar logic at 43-53): currently you replace CMAKE_FIND_LIBRARY_SUFFIXES with
the static suffix only, which hard-fails if static lib is not present; implement
a two-pass fallback instead: save the original CMAKE_FIND_LIBRARY_SUFFIXES, set
it to the static-only suffix and attempt the library find, and if that fails
restore the original suffixes, emit a STATUS message about falling back to
shared, and attempt the find again; in all cases ensure the original suffix list
is restored before returning.

# 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 CLP_CORE_DEPS_DIR)
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 @@ -455,9 +455,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
49 changes: 49 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,54 @@ tasks:
TARBALL_SHA256: "1250e4cc58bf06ee631567523f48848dc4596133e163f02615c97f78bab6c811"
TARBALL_URL: "https://github.com/fmtlib/fmt/archive/refs/tags/10.2.1.tar.gz"

liblzma:
internal: true
vars:
COMMON_CMAKE_GEN_ARGS:
- "-DBUILD_TESTING=OFF"
- "-DCMAKE_BUILD_TYPE=Release"
- "-DCMAKE_INSTALL_MESSAGE=LAZY"
- "-DXZ_DOC=OFF"
- "-DXZ_TOOL_LZMADEC=OFF"
- "-DXZ_TOOL_LZMAINFO=OFF"
- "-DXZ_TOOL_SCRIPTS=OFF"
- "-DXZ_TOOL_SYMLINKS_LZMA=OFF"
- "-DXZ_TOOL_XZ=OFF"
- "-DXZ_TOOL_XZDEC=OFF"
TARBALL_SHA256: "507825b599356c10dca1cd720c9d0d0c9d5400b9de300af00e4d1ea150795543"
TARBALL_URL: "https://github.com/tukaani-project/xz/releases/download/v5.8.1/xz-5.8.1.tar.gz"
run: "once"
deps:
- task: "liblzma-install"
vars:
BUILD_SHARED_LIBS: true
COMMON_CMAKE_GEN_ARGS:
ref: ".COMMON_CMAKE_GEN_ARGS"
TARBALL_SHA256: "{{.TARBALL_SHA256}}"
TARBALL_URL: "{{.TARBALL_URL}}"
- task: "liblzma-install"
vars:
BUILD_SHARED_LIBS: false
COMMON_CMAKE_GEN_ARGS:
ref: ".COMMON_CMAKE_GEN_ARGS"
TARBALL_SHA256: "{{.TARBALL_SHA256}}"
TARBALL_URL: "{{.TARBALL_URL}}"

liblzma-install:
internal: true
requires:
vars: ["BUILD_SHARED_LIBS", "COMMON_CMAKE_GEN_ARGS", "TARBALL_SHA256", "TARBALL_URL"]
cmds:
- task: "utils:install-remote-cmake-lib"
vars:
CMAKE_GEN_ARGS:
- "-DBUILD_SHARED_LIBS={{ if .BUILD_SHARED_LIBS }}ON{{ else }}OFF{{ end }}"
- >-
{{ join " " .COMMON_CMAKE_GEN_ARGS }}
LIB_NAME: "LibLZMA-{{ if .BUILD_SHARED_LIBS }}shared{{ else }}static{{ end }}"
TARBALL_SHA256: "{{.TARBALL_SHA256}}"
TARBALL_URL: "{{.TARBALL_URL}}"

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