Skip to content

Commit 97fd53f

Browse files
committed
Use pkg-config to find libarchive so static linking works
1 parent bd1ba16 commit 97fd53f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,14 @@ if (USE_LIBARCHIVE)
215215
if (NOT USE_STANDARD_FILESYSTEM)
216216
message(FATAL_ERROR "Unable to use USE_LIBARCHIVE without USE_STANDARD_FILESYSTEM.")
217217
endif ()
218-
use_package(TARGET_NAME LibArchive::LibArchive PACKAGE_NAME LibArchive)
218+
# use either the CMake find module or the pkg-config file to find libarchive; the latter is preferred as the CMake find
219+
# module does not take transitive dependencies into account and thus breaks static linking
220+
option(USE_LIBARCHIVE_VIA_FIND_MODULE "uses the CMake find module to find libarchive" OFF)
221+
if (USE_LIBARCHIVE_VIA_FIND_MODULE)
222+
use_package(TARGET_NAME LibArchive::LibArchive PACKAGE_NAME LibArchive)
223+
else ()
224+
use_pkg_config_module(PKG_CONFIG_MODULES "libarchive" TARGET_NAME LibArchive::LibArchive VISIBILITY PRIVATE)
225+
endif ()
219226
list(APPEND HEADER_FILES io/archive.h)
220227
list(APPEND SRC_FILES io/archive.cpp)
221228
list(APPEND META_PUBLIC_COMPILE_DEFINITIONS ${META_PROJECT_VARNAME}_USE_LIBARCHIVE)

0 commit comments

Comments
 (0)