dnl CF_WITH_PCRE version: 12 updated: 2017/07/29 22:57:34
dnl ------------
dnl Add PCRE (Perl-compatible regular expressions) 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_PCRE],
[
AC_REQUIRE([CF_PKG_CONFIG])

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

if test "$with_pcre" != no ; then
	CF_TRY_PKG_CONFIG(libpcre,,[
		AC_CHECK_LIB(pcre,pcre_compile,,
			AC_MSG_ERROR(Cannot find PCRE library))])

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

	case $LIBS in
	(*pcreposix*)
		;;
	(*)
		AC_CHECK_LIB(pcreposix,pcreposix_regcomp,
			[AC_DEFINE(HAVE_PCREPOSIX_H,1,[Define to 1 if we should include pcreposix.h])
				CF_ADD_LIB(pcreposix)],
			[AC_CHECK_LIB(pcreposix,regcomp,[
				AC_DEFINE(HAVE_PCREPOSIX_H,1,[Define to 1 if we should include pcreposix.h])
				CF_ADD_LIB(pcreposix)],
				AC_MSG_ERROR(Cannot find PCRE POSIX library)]))
		;;
	esac
fi
])dnl
