pcre2test: really allow using libedit when enabled (#96)

* pcre2test: use the right header for libedit in FreeBSD with autoconf

When `./configure --enable-pcre2test-libedit` is used in FreeBSD,
the resulting test will succeed but won't set the necessary flag
to distinguish between libedit and readline header files, therefore
using readline's at built time (if installed)

Consolidate all header tests into one and use instead the corresponding
autogenerated defines to check for each possibility.

* pcre2test: really allow libedit with cmake

Using cmake to configure and enable linking pcre2test with libedit,
could result in a broken build, because the header used was instead
pointing to readline.

In cases were the build will succeed (because both libraries were
available), it would likely show warnings, because several history
functions were being used without declarations, since readline
requires including "history.h" for those.

Additionally, since PCRE2_SUPPORT_READLINE is ON by default (unlike
configure), turning PCRE2_SUPPORT_LIBEDIT=ON, would require setting
that other option to OFF explicitly (even if readline wasn't available)
or the setup would abort.

Lastly, in systems with no default sysroot (ex: macOS), the use of
absolute paths for searching for libedit's readline.h could fail so
use instead relative PATH_SUFFIXES.

* pcre2test: avoid using readline headers with libedit

When asked to enable libedit in a system that ALSO has readline,
the headers of the former would be found and used by the earlier.

While that would mostly work, some functions will be missing
definitions (which is forbidden in C99), so instead abort the
configuration and let the user provide for them.
This commit is contained in:
Carlo Marcelo Arenas Belón 2022-04-08 09:07:30 -07:00 committed by GitHub
parent f11c26842d
commit 9c8abddc52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 16 deletions

View File

@ -306,9 +306,15 @@ ENDIF(PCRE2_SUPPORT_LIBZ)
IF(EDITLINE_FOUND) IF(EDITLINE_FOUND)
OPTION (PCRE2_SUPPORT_LIBEDIT "Enable support for linking pcre2test with libedit." OFF) OPTION (PCRE2_SUPPORT_LIBEDIT "Enable support for linking pcre2test with libedit." OFF)
ENDIF(EDITLINE_FOUND) ENDIF(EDITLINE_FOUND)
IF(PCRE2_SUPPORT_LIBEDIT) IF(EDITLINE_FOUND)
INCLUDE_DIRECTORIES(${EDITLINE_INCLUDE_DIR}) IF(PCRE2_SUPPORT_LIBEDIT)
ENDIF(PCRE2_SUPPORT_LIBEDIT) INCLUDE_DIRECTORIES(${EDITLINE_INCLUDE_DIR})
ENDIF(PCRE2_SUPPORT_LIBEDIT)
ELSE(EDITLINE_FOUND)
IF(PCRE2_SUPPORT_LIBEDIT)
MESSAGE(FATAL_ERROR "libedit not found, set Editline_ROOT if needed")
ENDIF(PCRE2_SUPPORT_LIBEDIT)
ENDIF(EDITLINE_FOUND)
# readline lib # readline lib
IF(READLINE_FOUND) IF(READLINE_FOUND)
@ -346,7 +352,12 @@ IF(PCRE2_BUILD_PCRE2GREP AND NOT PCRE2_BUILD_PCRE2_8)
ENDIF(PCRE2_BUILD_PCRE2GREP AND NOT PCRE2_BUILD_PCRE2_8) ENDIF(PCRE2_BUILD_PCRE2GREP AND NOT PCRE2_BUILD_PCRE2_8)
IF(PCRE2_SUPPORT_LIBREADLINE AND PCRE2_SUPPORT_LIBEDIT) IF(PCRE2_SUPPORT_LIBREADLINE AND PCRE2_SUPPORT_LIBEDIT)
MESSAGE(FATAL_ERROR "Only one of libreadline or libeditline can be specified") IF(READLINE_FOUND)
MESSAGE(FATAL_ERROR
" Only one of the readline compatible libraries can be enabled.\n"
" Disable libreadline with -DPCRE2_SUPPORT_LIBREADLINE=OFF"
)
ENDIF(READLINE_FOUND)
ENDIF(PCRE2_SUPPORT_LIBREADLINE AND PCRE2_SUPPORT_LIBEDIT) ENDIF(PCRE2_SUPPORT_LIBREADLINE AND PCRE2_SUPPORT_LIBEDIT)
IF(PCRE2_SUPPORT_BSR_ANYCRLF) IF(PCRE2_SUPPORT_BSR_ANYCRLF)

View File

@ -3,10 +3,9 @@
if(EDITLINE_INCLUDE_DIR AND EDITLINE_LIBRARY AND NCURSES_LIBRARY) if(EDITLINE_INCLUDE_DIR AND EDITLINE_LIBRARY AND NCURSES_LIBRARY)
set(EDITLINE_FOUND TRUE) set(EDITLINE_FOUND TRUE)
else(EDITLINE_INCLUDE_DIR AND EDITLINE_LIBRARY AND NCURSES_LIBRARY) else(EDITLINE_INCLUDE_DIR AND EDITLINE_LIBRARY AND NCURSES_LIBRARY)
FIND_PATH(EDITLINE_INCLUDE_DIR readline.h FIND_PATH(EDITLINE_INCLUDE_DIR readline.h PATH_SUFFIXES
/usr/include/editline editline
/usr/include/edit/readline edit/readline
/usr/include/readline
) )
FIND_LIBRARY(EDITLINE_LIBRARY NAMES edit) FIND_LIBRARY(EDITLINE_LIBRARY NAMES edit)

View File

@ -597,14 +597,14 @@ if test "$enable_pcre2test_libreadline" = "yes"; then
fi fi
fi fi
# Check for the availability of libedit. Different distributions put its # Check for the availability of libedit. Different distributions put its
# headers in different places. Try to cover the most common ones. # headers in different places. Try to cover the most common ones.
if test "$enable_pcre2test_libedit" = "yes"; then if test "$enable_pcre2test_libedit" = "yes"; then
AC_CHECK_HEADERS([editline/readline.h], [HAVE_EDITLINE_READLINE_H=1], AC_CHECK_HEADERS([editline/readline.h edit/readline/readline.h], [
[AC_CHECK_HEADERS([edit/readline/readline.h], [HAVE_READLINE_READLINE_H=1], HAVE_LIBEDIT_HEADER=1
[AC_CHECK_HEADERS([readline/readline.h], [HAVE_READLINE_READLINE_H=1])])]) break
])
AC_CHECK_LIB([edit], [readline], [LIBEDIT="-ledit"]) AC_CHECK_LIB([edit], [readline], [LIBEDIT="-ledit"])
fi fi
@ -940,10 +940,9 @@ if test "$enable_pcre2test_libedit" = "yes"; then
echo "** Cannot use both --enable-pcre2test-libedit and --enable-pcre2test-readline" echo "** Cannot use both --enable-pcre2test-libedit and --enable-pcre2test-readline"
exit 1 exit 1
fi fi
if test "$HAVE_EDITLINE_READLINE_H" != "1" -a \ if test -z "$HAVE_LIBEDIT_HEADER"; then
"$HAVE_READLINE_READLINE_H" != "1"; then
echo "** Cannot --enable-pcre2test-libedit because neither editline/readline.h" echo "** Cannot --enable-pcre2test-libedit because neither editline/readline.h"
echo "** nor readline/readline.h was found." echo "** nor edit/readline/readline.h was found."
exit 1 exit 1
fi fi
if test -z "$LIBEDIT"; then if test -z "$LIBEDIT"; then

View File

@ -94,8 +94,10 @@ that first, falling back to readline/readline.h. */
#else #else
#if defined(HAVE_EDITLINE_READLINE_H) #if defined(HAVE_EDITLINE_READLINE_H)
#include <editline/readline.h> #include <editline/readline.h>
#elif defined(HAVE_EDIT_READLINE_READLINE_H)
#include <edit/readline/readline.h>
#else #else
#include <readline/readline.h> #include <readline.h>
#endif #endif
#endif #endif
#endif #endif