-
Notifications
You must be signed in to change notification settings - Fork 83
build(deps): Add task-based installation and cmake find module script for LibLZMA dependency. #1184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4448dd0
ab7a6d3
9188735
306a447
4f863e5
150cd4c
18f42c4
3112d8e
024a9ed
b144c1c
ae41525
f5e981a
8f1ad98
785b76d
f3e8965
8875633
fc9b372
dfdadcd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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() | ||
Bill-hbrhbr marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+21
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||
|
||
# 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||
# 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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):
Also applies to: 43-53 🤖 Prompt for AI Agents
|
||
# 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() |
There was a problem hiding this comment.
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:
📝 Committable suggestion
🤖 Prompt for AI Agents