]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
cmake: look for zlib >= 1.2.1 (#2318)
authorMostyn Bramley-Moore <mostyn@antipode.se>
Thu, 12 Sep 2024 21:56:34 +0000 (23:56 +0200)
committerGitHub <noreply@github.com>
Thu, 12 Sep 2024 21:56:34 +0000 (23:56 +0200)
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
configure.ac

index 7bfaf4cfa7497c0d2a1d6490f69e0334eea215d0..70d0db43e375db2fa7c315313bcbc78281120921 100644 (file)
@@ -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()
index 75c71d5c423c729d0b9fb31155f6d63032fcb3d0..a76aaab200f07753913055de4d9c45ad6461c712 100644 (file)
@@ -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 <zlib.h>
+      #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],