Skip to content

Commit 3b0ac08

Browse files
committed
Add Bzip2 installation
1 parent 0bfaf5c commit 3b0ac08

File tree

3 files changed

+124
-0
lines changed

3 files changed

+124
-0
lines changed

components/core/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ if(CLP_NEED_BOOST)
155155
endif()
156156
endif()
157157

158+
if(CLP_USE_STATIC_LIBS)
159+
set(BZip2_USE_STATIC_LIBS ON)
160+
endif()
161+
find_package(BZip2 1.1.0 REQUIRED)
162+
message(STATUS "Found BZip2 ${BZip2_VERSION}")
163+
158164
if(CLP_NEED_CATCH2)
159165
find_package(Catch2 REQUIRED)
160166
if (Catch2_FOUND)
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
include(cmake/Modules/FindLibraryDependencies.cmake)
2+
3+
set(bzip2_LIBNAME "bz2")
4+
set(bzip2_PKGCONFIG_DIR "${BZip2_ROOT}/lib/pkgconfig")
5+
set(bzip2_PKGCONFIG_NAME "bzip2")
6+
set(bzip2_LOCAL_PREFIX "bzip2")
7+
8+
# Run pkg-config
9+
find_package(PkgConfig)
10+
set(ENV{bzip2_ORIG_PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}")
11+
set(ENV{PKG_CONFIG_PATH} "${bzip2_PKGCONFIG_DIR};$ENV{PKG_CONFIG_PATH}")
12+
pkg_check_modules(bzip2_PKGCONF QUIET "${bzip2_PKGCONFIG_NAME}")
13+
14+
# Set include directory
15+
find_path(BZip2_INCLUDE_DIR bzlib.h
16+
HINTS ${bzip2_PKGCONF_INCLUDEDIR}
17+
PATH_SUFFIXES include
18+
)
19+
20+
# Handle static libraries
21+
if(BZip2_USE_STATIC_LIBS)
22+
set(bzip2_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
23+
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
24+
endif()
25+
26+
# Find library
27+
find_library(BZip2_LIBRARY
28+
NAMES "${bzip2_LIBNAME}" "${bzip2_LIBNAME}_static"
29+
HINTS ${bzip2_PKGCONF_LIBDIR}
30+
PATH_SUFFIXES lib
31+
)
32+
33+
if(BZip2_LIBRARY)
34+
set(BZip2_FOUND ON)
35+
endif()
36+
37+
if(BZip2_USE_STATIC_LIBS)
38+
FindStaticLibraryDependencies(${bzip2_LIBNAME} ${bzip2_LOCAL_PREFIX}
39+
"${bzip2_PKGCONF_STATIC_LIBRARIES}")
40+
41+
# Restore original value of CMAKE_FIND_LIBRARY_SUFFIXES
42+
set(CMAKE_FIND_LIBRARY_SUFFIXES ${bzip2_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
43+
unset(bzip2_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES)
44+
else()
45+
list(APPEND bzip2_DYNAMIC_LIBS ${bzip2_PKGCONF_STATIC_LIBRARIES})
46+
endif()
47+
48+
FindDynamicLibraryDependencies(${bzip2_LOCAL_PREFIX} "${bzip2_DYNAMIC_LIBS}")
49+
50+
# Set version
51+
set(BZip2_VERSION ${bzip2_PKGCONF_VERSION})
52+
53+
include(FindPackageHandleStandardArgs)
54+
find_package_handle_standard_args(BZip2
55+
REQUIRED_VARS BZip2_FOUND BZip2_INCLUDE_DIR
56+
VERSION_VAR BZip2_VERSION
57+
)
58+
59+
if(NOT TARGET BZip2::BZip2)
60+
# Add library to build
61+
if (BZip2_FOUND)
62+
if (BZip2_USE_STATIC_LIBS)
63+
add_library(BZip2::BZip2 STATIC IMPORTED)
64+
else()
65+
# NOTE: We use UNKNOWN so that if the user doesn't have the SHARED
66+
# libraries installed, we can still use the STATIC libraries
67+
add_library(BZip2::BZip2 UNKNOWN IMPORTED)
68+
endif()
69+
endif()
70+
71+
# Set include directories for library
72+
if(BZip2_INCLUDE_DIR)
73+
set_target_properties(BZip2::BZip2
74+
PROPERTIES
75+
INTERFACE_INCLUDE_DIRECTORIES "${BZip2_INCLUDE_DIR}"
76+
)
77+
endif()
78+
79+
# Set location of library
80+
if(EXISTS "${BZip2_LIBRARY}")
81+
set_target_properties(BZip2::BZip2
82+
PROPERTIES
83+
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
84+
IMPORTED_LOCATION "${BZip2_LIBRARY}"
85+
)
86+
87+
# Add component's dependencies for linking
88+
if(BZip2_LIBRARY_DEPENDENCIES)
89+
set_target_properties(BZip2::BZip2
90+
PROPERTIES
91+
INTERFACE_LINK_LIBRARIES "${BZip2_LIBRARY_DEPENDENCIES}"
92+
)
93+
endif()
94+
endif()
95+
endif()
96+
97+
# Restore original value of PKG_CONFIG_PATH
98+
set(ENV{PKG_CONFIG_PATH} "ENV{bzip2_ORIG_PKG_CONFIG_PATH}")
99+
unset(ENV{bzip2_ORIG_PKG_CONFIG_PATH})

taskfiles/deps/main.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ vars:
1818
G_DEPS_CORE_CMAKE_SETTINGS_DIR: "{{.G_DEPS_CORE_DIR}}/cmake-settings"
1919

2020
# Library names
21+
G_BZIP2_LIB_NAME: "BZip2"
2122
G_FMT_LIB_NAME: "fmt"
2223

2324
# Antlr
@@ -62,6 +63,7 @@ tasks:
6263
- task: "absl"
6364
- task: "antlr-jar"
6465
- task: "antlr-runtime"
66+
- task: "bzip2"
6567
- task: "catch2"
6668
- task: "date"
6769
- task: "fmt"
@@ -175,6 +177,23 @@ tasks:
175177
CHECKSUM_FILE: "{{.CHECKSUM_FILE}}"
176178
INCLUDE_PATTERNS: ["{{.INSTALL_PREFIX}}"]
177179

180+
bzip2:
181+
internal: true
182+
run: "once"
183+
cmds:
184+
- task: "utils:install-remote-cmake-lib"
185+
vars:
186+
CMAKE_GEN_ARGS:
187+
- "-DCMAKE_BUILD_TYPE=Release"
188+
- "-DCMAKE_INSTALL_MESSAGE=LAZY"
189+
- "-DCMAKE_INSTALL_PREFIX={{.G_DEPS_CORE_DIR}}/{{.G_BZIP2_LIB_NAME}}-install"
190+
- "-DENABLE_LIB_ONLY=ON"
191+
- "-DENABLE_SHARED_LIB=ON"
192+
- "-DENABLE_STATIC_LIB=ON"
193+
LIB_NAME: "{{.G_BZIP2_LIB_NAME}}"
194+
TARBALL_SHA256: "72f86f175ebeb5972c2824987ec4ae00c62a96e14768954e189efdc4aac24294"
195+
TARBALL_URL: "https://github.com/libarchive/bzip2/archive/1ea1ac1.tar.gz"
196+
178197
catch2:
179198
internal: true
180199
run: "once"

0 commit comments

Comments
 (0)