From 6df5cb464b1e3814f8615e3d794b51e694ff8ced Mon Sep 17 00:00:00 2001 From: Mostyn Bramley-Moore Date: Thu, 12 Sep 2024 23:56:34 +0200 Subject: [PATCH] cmake: look for zlib >= 1.2.1 (#2318) zlib 1.2.0 added this improvement for inflate: "Raw inflate no longer needs an extra dummy byte at end" libarchive does not feed zlib extra data beyond end of stream, so it does not work with zlib < 1.2.0. --- CMakeLists.txt | 5 ++++- configure.ac | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7bfaf4cfa..70d0db43e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -443,7 +443,10 @@ SET(ADDITIONAL_LIBS "") # Find ZLIB # IF(ENABLE_ZLIB) - FIND_PACKAGE(ZLIB) + # Require zlib >= 1.2.1, see: https://github.com/libarchive/libarchive/issues/615 + # zlib 1.2.0 should also work, but it is difficult to test for. Let's require + # zlib >= 1.2.1 for consistency with the autoconf build. + FIND_PACKAGE(ZLIB 1.2.1 REQUIRED) ELSE() SET(ZLIB_FOUND FALSE) # Override cached value ENDIF() diff --git a/configure.ac b/configure.ac index 75c71d5c4..a76aaab20 100644 --- a/configure.ac +++ b/configure.ac @@ -380,8 +380,23 @@ AC_ARG_WITH([zlib], AS_HELP_STRING([--without-zlib], [Don't build support for gzip through zlib])) if test "x$with_zlib" != "xno"; then - AC_CHECK_HEADERS([zlib.h]) - AC_CHECK_LIB(z,inflate) + old_LIBS="$LIBS" + LIBS="$LIBS -lz" + AC_LINK_IFELSE([AC_LANG_SOURCE([[ + #include + #if !defined(ZLIB_VERNUM) + // zlib 1.2.0 should work too, but it's difficult to test for. + // zlib 1.2.1 onwards have ZLIB_VERNUM, which is easy to check. + #error zlib >= 1.2.1 is required. + #endif + // Check that there's an inflate function. + int main(int argc, char **argv) { inflate(NULL, 0); return 0; } + ]])], + [AC_DEFINE([HAVE_ZLIB_H], [1], [Define to 1 if you have zlib >= 1.2.1]) + AC_MSG_RESULT([found a suitable version of zlib (>= 1.2.1)]) + ], + [AC_MSG_RESULT([could not find a suitable version of zlib (>= 1.2.1)]) + LIBS="$old_LIBS"]) fi AC_ARG_WITH([bz2lib], -- 2.47.2