blob: 113c3feb55a8ef9a4f7d8a4e0548b35d46ed7f77 [file]
dnl Copyright (C) 2022 Free Software Foundation, Inc.
dnl This file is free software, distributed under the terms of the GNU
dnl General Public License. As a special exception to the GNU General
dnl Public License, this file may be distributed as part of a program
dnl that contains a configuration script generated by Autoconf, under
dnl the same distribution terms as the rest of that program.
dnl Set up and check zstd support.
dnl AC_ZSTD([FAILURE_IS_FATAL]): if FAILURE_IS_FATAL is 'no', an unusable
dnl zstd installation is nonfatal even when explicitly requested.
dnl The default is 'yes'; auto mode is always nonfatal.
AC_DEFUN([AC_ZSTD], [
m4_pushdef([zstd_FailureIsFatal], [m4_default([$1], [yes])])dnl
AC_SUBST(ZSTD_CFLAGS)
AC_SUBST(ZSTD_LIBS)
AC_ARG_WITH(zstd,
[AS_HELP_STRING([--with-zstd=VALUE],
[VALUE may be 'auto' (try pkg-config, then compiler search; default),
'yes' (require zstd), 'no' (disable it), or a PATH for the
installation prefix. When VALUE is a PATH, this is equivalent to
--with-zstd-include=PATH/include and
--with-zstd-lib=PATH/lib])],
[with_zstd=$withval], [with_zstd=auto])
AC_ARG_WITH(zstd-include,
[AS_HELP_STRING([--with-zstd-include=PATH],
[specify directory for installed zstd include files])])
AC_ARG_WITH(zstd-lib,
[AS_HELP_STRING([--with-zstd-lib=PATH],
[specify directory for the installed zstd library])])
zstd_enabled=no
zstd_pkg_config=no
zstd_use_pkg_config=no
zstd_include_dir=
zstd_library_dir=
case "x$with_zstd" in
xno)
;;
xyes|xauto)
zstd_enabled=yes
zstd_use_pkg_config=yes
;;
*)
zstd_enabled=yes
zstd_include_dir=$with_zstd/include
zstd_library_dir=$with_zstd/lib
;;
esac
if test "$zstd_use_pkg_config" = yes; then
PKG_CHECK_MODULES([ZSTD], [libzstd >= 1.4.0], [
zstd_pkg_config=yes
], [:])
fi
if test "$zstd_enabled" = yes; then
saved_CFLAGS="$CFLAGS"
save_LIBS="$LIBS"
AC_LANG_PUSH([C])
while :; do
if test "x$with_zstd_include" != x; then
if test "$zstd_pkg_config" = yes; then
ZSTD_CFLAGS="-I$with_zstd_include $ZSTD_CFLAGS"
else
zstd_include_dir=$with_zstd_include
fi
fi
if test "x$with_zstd_lib" != x; then
zstd_library_dir=$with_zstd_lib
fi
if test "$zstd_pkg_config" != yes; then
ZSTD_CFLAGS=
ZSTD_LIBS=
if test "x$zstd_include_dir" != x \
&& test "x$zstd_include_dir" != xno; then
ZSTD_CFLAGS=-I$zstd_include_dir
fi
fi
if test "x$zstd_library_dir" != x \
&& test "x$zstd_library_dir" != xno; then
ZSTD_LIBS="-L$zstd_library_dir $ZSTD_LIBS"
fi
CFLAGS="$saved_CFLAGS $ZSTD_CFLAGS"
# Check for a usable zstd library and header. Ignore cached results
# that may have been obtained with different search flags.
unset ac_cv_search_ZSTD_compress ac_cv_zstd_h
zstd_lib_usable=no
LIBS="$ZSTD_LIBS $save_LIBS"
AC_SEARCH_LIBS([ZSTD_compress], [zstd],
[zstd_lib_usable=yes],
[zstd_lib_usable=no])
if test "$zstd_lib_usable" = yes \
&& test "$ac_cv_search_ZSTD_compress" != "none required"; then
# Add the library only if AC_SEARCH_LIBS needed additional flags.
ZSTD_LIBS="$ac_cv_search_ZSTD_compress $ZSTD_LIBS"
fi
LIBS="$save_LIBS"
AC_CACHE_CHECK([for zstd.h], [ac_cv_zstd_h],
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <zstd.h>
#if ZSTD_VERSION_NUMBER < 10400
#error "need zstd 1.4.0 or better"
#endif
]], [[]])],
[ac_cv_zstd_h=yes],
[ac_cv_zstd_h=no])])
if test "$zstd_pkg_config" = yes \
&& { test "$zstd_lib_usable" != yes || test "$ac_cv_zstd_h" != yes; }; then
AC_MSG_NOTICE([pkg-config zstd is unusable; trying compiler search])
zstd_pkg_config=no
ZSTD_CFLAGS=
ZSTD_LIBS=
else
break
fi
done
AC_LANG_POP([C])
if test "$zstd_lib_usable" = yes && test "$ac_cv_zstd_h" = yes; then
AC_DEFINE(HAVE_ZSTD, 1, [Define if zstd is available.])
elif test "$with_zstd" != auto \
&& test "x[]zstd_FailureIsFatal" != xno; then
AC_MSG_ERROR([Unable to find a usable zstd library and zstd.h. See
config.log for details.])
else
AC_MSG_NOTICE([no usable external libzstd; continuing without it])
zstd_enabled=no
fi
CFLAGS="$saved_CFLAGS"
fi
if test "$zstd_enabled" != yes; then
ZSTD_CFLAGS=
ZSTD_LIBS=
fi
m4_popdef([zstd_FailureIsFatal])dnl
])