Skip to content
Open
Show file tree
Hide file tree
Changes from 10 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
6 changes: 6 additions & 0 deletions components/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ if(CLP_NEED_BOOST)
endif()
endif()

if(CLP_USE_STATIC_LIBS)
set(BZip2_USE_STATIC_LIBS ON)
endif()
find_package(BZip2 REQUIRED)
message(STATUS "Found BZip2")

if(CLP_NEED_CATCH2)
find_package(Catch2 REQUIRED)
if (Catch2_FOUND)
Expand Down
125 changes: 125 additions & 0 deletions components/core/cmake/Modules/FindBZip2.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# Try to find BZip2
# NOTE: The FindBZip2.cmake included with CMake has no support for static libraries, so we use our
# own.
#
# Set BZip2_USE_STATIC_LIBS=ON to look for static libraries.
#
# Once done, this will define:
# BZip2_FOUND - Whether the library was found on the system
# BZip2_INCLUDE_DIR - The library include directories
# BZip2_LIBRARY - The path to the library file
#
# And will define the following if applicable:
# BZip2_VERSION - The version of the library installed on the system
# BZip2_LIBRARY_DEPENDENCIES - Any additional modules required to link with the library
#
# Conventions:
# - Variables only for use within the script are prefixed with "bzip2_"
# - Variables that should be externally visible are prefixed with "BZip2_"

include(cmake/Modules/FindLibraryDependencies.cmake)

set(bzip2_HEADER "bzlib.h")
set(bzip2_LIBNAME "bz2")
set(bzip2_LOCAL_PREFIX "bzip2")
set(bzip2_PKGCONFIG_NAME "bzip2")

if(DEFINED BZip2_ROOT)
set(bzip2_PKGCONFIG_DIR "${BZip2_ROOT}/lib/pkgconfig")
set(ENV{bzip2_ORIG_PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}")
set(ENV{PKG_CONFIG_PATH} "${bzip2_PKGCONFIG_DIR};$ENV{PKG_CONFIG_PATH}")
endif()

# Run pkg-config
find_package(PkgConfig)
pkg_check_modules(bzip2_PKGCONF QUIET "${bzip2_PKGCONFIG_NAME}")

# Manually set package finding hints in case of failure
if(NOT bzip2_PKGCONF_FOUND)
Copy link
Member

Choose a reason for hiding this comment

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

Why do we set the hints only in case of failure?

message(WARNING "Cannot find package config for ${bzip2_PKGCONFIG_NAME}")
if(DEFINED BZip2_ROOT)
set(bzip2_PKGCONF_INCLUDEDIR "${BZip2_ROOT}/include")
set(bzip2_PKGCONF_LIBDIR "${BZip2_ROOT}/lib")
endif()
endif()

# Set include directory
find_path(BZip2_INCLUDE_DIR ${bzip2_HEADER}
HINTS ${bzip2_PKGCONF_INCLUDEDIR}
PATH_SUFFIXES include
)

# Handle static libraries
if(BZip2_USE_STATIC_LIBS)
set(bzip2_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
endif()

# Find library
find_library(BZip2_LIBRARY
NAMES "${bzip2_LIBNAME}"
HINTS ${bzip2_PKGCONF_LIBDIR}
PATH_SUFFIXES lib
)

if(BZip2_USE_STATIC_LIBS)
FindStaticLibraryDependencies(${bzip2_LIBNAME} ${bzip2_LOCAL_PREFIX}
"${bzip2_PKGCONF_STATIC_LIBRARIES}")

# Restore original value of CMAKE_FIND_LIBRARY_SUFFIXES
set(CMAKE_FIND_LIBRARY_SUFFIXES ${bzip2_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
unset(bzip2_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES)
endif()

FindDynamicLibraryDependencies(${bzip2_LOCAL_PREFIX} "${bzip2_DYNAMIC_LIBS}")

# Set version
set(BZip2_VERSION ${bzip2_PKGCONF_VERSION})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(BZip2
REQUIRED_VARS BZip2_LIBRARY BZip2_INCLUDE_DIR
VERSION_VAR BZip2_VERSION
)

if(NOT TARGET BZip2::BZip2)
# Add library to build
if (BZip2_USE_STATIC_LIBS)
add_library(BZip2::BZip2 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(BZip2::BZip2 UNKNOWN IMPORTED)
endif()

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

# Set location of library
if(EXISTS "${BZip2_LIBRARY}")
set_target_properties(BZip2::BZip2
PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${BZip2_LIBRARY}"
)

# Add component's dependencies for linking
if(BZip2_LIBRARY_DEPENDENCIES)
set_target_properties(BZip2::BZip2
PROPERTIES
INTERFACE_LINK_LIBRARIES "${BZip2_LIBRARY_DEPENDENCIES}"
)
endif()
endif()
endif()

# Restore original value of PKG_CONFIG_PATH
if(DEFINED BZip2_ROOT)
set(ENV{PKG_CONFIG_PATH} "$ENV{bzip2_ORIG_PKG_CONFIG_PATH}")
unset(ENV{bzip2_ORIG_PKG_CONFIG_PATH})
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ set -eu
set -o pipefail

apk update && apk add --no-cache \
bzip2-dev \
bzip2-static \
curl-dev \
jq \
mariadb-connector-c-dev \
Expand Down
1 change: 1 addition & 0 deletions docs/src/dev-guide/components-core/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ The task will download, build, and install (within the build directory) the foll
|-----------------------------------------------------------------------|----------------|
| [abseil-cpp](https://github.com/abseil/abseil-cpp) | 20250512.0 |
| [ANTLR](https://www.antlr.org) | v4.13.2 |
| [BZip2](https://github.com/libarchive/bzip2) | 1ea1ac1 |
| [Catch2](https://github.com/catchorg/Catch2.git) | v2.13.7 |
| [date](https://github.com/HowardHinnant/date.git) | v3.0.1 |
| [fmt](https://github.com/fmtlib/fmt) | v10.2.1 |
Expand Down
29 changes: 29 additions & 0 deletions taskfiles/deps/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ vars:
G_DEPS_CORE_CMAKE_SETTINGS_DIR: "{{.G_DEPS_CORE_DIR}}/cmake-settings"

# Library names
G_BZIP2_LIB_NAME: "BZip2"
G_FMT_LIB_NAME: "fmt"
G_GSL_LIB_NAME: "Microsoft.GSL"

Expand Down Expand Up @@ -63,6 +64,7 @@ tasks:
- task: "absl"
- task: "antlr-jar"
- task: "antlr-runtime"
- task: "bzip2"
- task: "catch2"
- task: "date"
- task: "fmt"
Expand Down Expand Up @@ -177,6 +179,33 @@ tasks:
CHECKSUM_FILE: "{{.CHECKSUM_FILE}}"
INCLUDE_PATTERNS: ["{{.INSTALL_PREFIX}}"]

bzip2:
internal: true
vars:
EXTRACTION_DIR: "{{.G_DEPS_CORE_DIR}}/{{.G_BZIP2_LIB_NAME}}-extracted"
INSTALL_PREFIX: "{{.G_DEPS_CORE_DIR}}/{{.G_BZIP2_LIB_NAME}}-install"
run: "once"
deps:
- task: "utils:init"
cmds:
- task: "yscope-dev-utils:remote:download-and-extract-tar"
vars:
CHECKSUM_FILE: "{{.G_DEPS_CORE_CHECKSUMS_DIR}}/{{.G_BZIP2_LIB_NAME}}.md5"
FILE_SHA256: "db106b740252669664fd8f3a1c69fe7f689d5cd4b132f82ba82b9afba27627df"
OUTPUT_DIR: "{{.EXTRACTION_DIR}}"
URL: "https://github.com/libarchive/bzip2/archive/refs/tags/bzip2-1.0.8.tar.gz"
- >-
make
--directory {{.EXTRACTION_DIR}}
--jobs {{.JOBS}}
install PREFIX={{.INSTALL_PREFIX}}
- >-
echo "set({{.G_BZIP2_LIB_NAME}}_ROOT
\"{{.INSTALL_PREFIX}}\"
CACHE PATH
\"Package root for {{.G_BZIP2_LIB_NAME}}.\"
)" >> "{{.G_DEPS_CORE_CMAKE_SETTINGS_DIR}}/{{.G_BZIP2_LIB_NAME}}.cmake"

catch2:
internal: true
run: "once"
Expand Down
Loading