Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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 @@ -155,6 +155,12 @@ if(CLP_NEED_BOOST)
endif()
endif()

if(CLP_USE_STATIC_LIBS)
set(BZip2_USE_STATIC_LIBS ON)
endif()
find_package(BZip2 1.1.0 REQUIRED)
message(STATUS "Found BZip2 ${BZip2_VERSION}")

if(CLP_NEED_CATCH2)
find_package(Catch2 REQUIRED)
if (Catch2_FOUND)
Expand Down
115 changes: 115 additions & 0 deletions components/core/cmake/Modules/FindBZip2.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# 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 BZip2 was found on the system
# BZip2_INCLUDE_DIR - The BZip2 include directories
# BZip2_VERSION - The version of BZip2 installed on the system
#
# 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_LIBNAME "bz2")
set(bzip2_LOCAL_PREFIX "bzip2")
set(bzip2_PKGCONFIG_NAME "bzip2")

if(DEFINED BZip2_ROOT)
set(bzip2_PKGCONFIG_DIR "${BZip2_ROOT}/lib/pkgconfig")
endif()

# Run pkg-config
find_package(PkgConfig)
set(ENV{bzip2_ORIG_PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}")
set(ENV{PKG_CONFIG_PATH} "${bzip2_PKGCONFIG_DIR};$ENV{PKG_CONFIG_PATH}")
pkg_check_modules(bzip2_PKGCONF QUIET "${bzip2_PKGCONFIG_NAME}")

# Set include directory
find_path(BZip2_INCLUDE_DIR bzlib.h
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}" "${bzip2_LIBNAME}_static"
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)
else()
list(APPEND bzip2_DYNAMIC_LIBS ${bzip2_PKGCONF_STATIC_LIBRARIES})
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
)

set(BZip2_FOUND ON)

if(NOT TARGET BZip2::BZip2)
# Add library to build
if (BZip2_FOUND)
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()
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
set(ENV{PKG_CONFIG_PATH} "$ENV{bzip2_ORIG_PKG_CONFIG_PATH}")
unset(ENV{bzip2_ORIG_PKG_CONFIG_PATH})
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
19 changes: 19 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"

# Antlr
Expand Down Expand Up @@ -62,6 +63,7 @@ tasks:
- task: "absl"
- task: "antlr-jar"
- task: "antlr-runtime"
- task: "bzip2"
- task: "catch2"
- task: "date"
- task: "fmt"
Expand Down Expand Up @@ -175,6 +177,23 @@ tasks:
CHECKSUM_FILE: "{{.CHECKSUM_FILE}}"
INCLUDE_PATTERNS: ["{{.INSTALL_PREFIX}}"]

bzip2:
internal: true
run: "once"
cmds:
- task: "utils:install-remote-cmake-lib"
vars:
CMAKE_GEN_ARGS:
- "-DCMAKE_BUILD_TYPE=Release"
- "-DCMAKE_INSTALL_MESSAGE=LAZY"
- "-DCMAKE_INSTALL_PREFIX={{.G_DEPS_CORE_DIR}}/{{.G_BZIP2_LIB_NAME}}-install"
- "-DENABLE_LIB_ONLY=ON"
- "-DENABLE_SHARED_LIB=ON"
- "-DENABLE_STATIC_LIB=ON"
LIB_NAME: "{{.G_BZIP2_LIB_NAME}}"
TARBALL_SHA256: "72f86f175ebeb5972c2824987ec4ae00c62a96e14768954e189efdc4aac24294"
TARBALL_URL: "https://github.com/libarchive/bzip2/archive/1ea1ac1.tar.gz"

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