dnl CF_WITH_PCRE2 version: 6 updated: 2021/08/11 20:35:34
dnl -------------
dnl Add PCRE2 (Perl-compatible regular expressions v2) to the build if it is
dnl available and the user requests it.  Assume the application will otherwise
dnl use the POSIX interface.
dnl
dnl TODO allow $withval to specify package location
AC_DEFUN([CF_WITH_PCRE2],
[
AC_REQUIRE([CF_PKG_CONFIG])

AC_MSG_CHECKING(if you want to use PCRE2 for regular-expressions)
AC_ARG_WITH(pcre2,
	[  --with-pcre2            use PCRE2 for regular-expressions])
test -z "$with_pcre2" && with_pcre2=no
AC_MSG_RESULT($with_pcre2)

if test "x$with_pcre2" != xno ; then
	cf_with_pcre2_ok=no
	for cf_with_pcre2 in libpcre2 libpcre2-posix libpcre
	do
		CF_TRY_PKG_CONFIG($cf_with_pcre2,[cf_with_pcre2_ok=yes; break])
	done
	cf_with_pcre2_ok=yes || AC_MSG_ERROR(Cannot find PCRE2 library)

	AC_DEFINE(HAVE_LIB_PCRE2,1,[Define to 1 if we can/should compile with the PCRE2 library])

	# if pkgconfig gave no results, look for the libraries directly
	case "$LIBS" in
	(*pcre2-posix*|*pcreposix*)
		;;
	(*)
		AC_CHECK_LIB(pcre2-posix,regcomp,[
			CF_ADD_LIB(pcre2-posix)],
			[AC_CHECK_LIB(pcreposix,regcomp,[
			 CF_ADD_LIB(pcreposix)
			],[AC_MSG_ERROR(Cannot find PCRE2 POSIX library)])])
		;;
	esac

	# either way, check for the library header files
	AC_CHECK_HEADERS(pcre2posix.h pcreposix.h)
	AC_CHECK_FUNCS(PCRE2regcomp)
fi
])dnl
