From 4279abbd7d45aca5be5cf43058016a26b54023d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlo=20Marcelo=20Arenas=20Bel=C3=B3n?= Date: Thu, 14 Apr 2022 08:51:51 -0700 Subject: [PATCH] pcre2test: allow using readline headers for libedit (#99) At least in OpenBSD, there is a libedit library in base, but without public headers. Public headers for readline are available but since 15db5d36 (pcre2test: avoid using readline headers with libedit, 2022-04-07) won't be picked up automatically. Allow pointing cmake to those headers by doing (for example): $ cmake -DEDITLINE_INCLUDE_DIR=/usr/include/readline Or using custom CPPFLAGS with configure (for example): $ CPPFLAGS=-I/usr/include/readline ./configure --enable-pcre2test-libedit Since the headers from readline.h would be otherwise incomplete, detect that case and pull the extra headers that are required automagically and while at it, cleanup the NCURSES dependency that was unnecessarily copied from readline. --- CMakeLists.txt | 11 ++++++++++- cmake/FindEditline.cmake | 8 ++++---- configure.ac | 6 +++--- maint/ucptest.c | 3 +++ src/pcre2test.c | 11 ++++++----- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 31c0a70..065a612 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -110,6 +110,11 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.0.0) # GET_TARGET_PROPERTY. This should no longer be required. # CMAKE_POLICY(SET CMP0026 OLD) +# With a recent cmake, you can provide a rootdir to look for non +# standard installed library dependencies, but to do so, the policy +# needs to be set to new (by uncommenting the following) +# CMAKE_POLICY(SET CMP0074 NEW) + # For FindReadline.cmake. This was changed to allow setting CMAKE_MODULE_PATH # on the command line. # SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) @@ -312,7 +317,11 @@ IF(EDITLINE_FOUND) ENDIF(PCRE2_SUPPORT_LIBEDIT) ELSE(EDITLINE_FOUND) IF(PCRE2_SUPPORT_LIBEDIT) - MESSAGE(FATAL_ERROR "libedit not found, set Editline_ROOT if needed") + MESSAGE(FATAL_ERROR + " libedit not found, set EDITLINE_INCLUDE_DIR to a compatible header\n" + " or set Editline_ROOT to a full libedit installed tree, as needed\n" + " Might need to enable policy CMP0074 in CMakeLists.txt" + ) ENDIF(PCRE2_SUPPORT_LIBEDIT) ENDIF(EDITLINE_FOUND) diff --git a/cmake/FindEditline.cmake b/cmake/FindEditline.cmake index 37eeb3e..1f0c951 100644 --- a/cmake/FindEditline.cmake +++ b/cmake/FindEditline.cmake @@ -1,8 +1,8 @@ # Modified from FindReadline.cmake (PH Feb 2012) -if(EDITLINE_INCLUDE_DIR AND EDITLINE_LIBRARY AND NCURSES_LIBRARY) +if(EDITLINE_INCLUDE_DIR AND EDITLINE_LIBRARY) set(EDITLINE_FOUND TRUE) -else(EDITLINE_INCLUDE_DIR AND EDITLINE_LIBRARY AND NCURSES_LIBRARY) +else(EDITLINE_INCLUDE_DIR AND EDITLINE_LIBRARY) FIND_PATH(EDITLINE_INCLUDE_DIR readline.h PATH_SUFFIXES editline edit/readline @@ -10,7 +10,7 @@ else(EDITLINE_INCLUDE_DIR AND EDITLINE_LIBRARY AND NCURSES_LIBRARY) FIND_LIBRARY(EDITLINE_LIBRARY NAMES edit) include(FindPackageHandleStandardArgs) - FIND_PACKAGE_HANDLE_STANDARD_ARGS(Editline DEFAULT_MSG EDITLINE_INCLUDE_DIR EDITLINE_LIBRARY ) + FIND_PACKAGE_HANDLE_STANDARD_ARGS(Editline DEFAULT_MSG EDITLINE_INCLUDE_DIR EDITLINE_LIBRARY) MARK_AS_ADVANCED(EDITLINE_INCLUDE_DIR EDITLINE_LIBRARY) -endif(EDITLINE_INCLUDE_DIR AND EDITLINE_LIBRARY AND NCURSES_LIBRARY) +endif(EDITLINE_INCLUDE_DIR AND EDITLINE_LIBRARY) diff --git a/configure.ac b/configure.ac index 7f22640..3cbd7ee 100644 --- a/configure.ac +++ b/configure.ac @@ -601,7 +601,7 @@ fi # headers in different places. Try to cover the most common ones. if test "$enable_pcre2test_libedit" = "yes"; then - AC_CHECK_HEADERS([editline/readline.h edit/readline/readline.h], [ + AC_CHECK_HEADERS([editline/readline.h edit/readline/readline.h readline.h], [ HAVE_LIBEDIT_HEADER=1 break ]) @@ -941,8 +941,8 @@ if test "$enable_pcre2test_libedit" = "yes"; then exit 1 fi if test -z "$HAVE_LIBEDIT_HEADER"; then - echo "** Cannot --enable-pcre2test-libedit because neither editline/readline.h" - echo "** nor edit/readline/readline.h was found." + echo "** Cannot --enable-pcre2test-libedit because neither editline/readline.h," + echo "** edit/readline/readline.h nor a compatible header was found." exit 1 fi if test -z "$LIBEDIT"; then diff --git a/maint/ucptest.c b/maint/ucptest.c index 638f6af..48475bb 100644 --- a/maint/ucptest.c +++ b/maint/ucptest.c @@ -110,6 +110,9 @@ type, gbreak or bidi. The defined values for that property are listed. */ #include #else #include +#ifdef RL_VERSION_MAJOR +#include +#endif #endif #endif #endif diff --git a/src/pcre2test.c b/src/pcre2test.c index 3de92b4..ee35c3b 100644 --- a/src/pcre2test.c +++ b/src/pcre2test.c @@ -82,11 +82,7 @@ from www.cbttape.org. */ /* #define DEBUG_SHOW_MALLOC_ADDRESSES */ -/* Both libreadline and libedit are optionally supported. The user-supplied -original patch uses readline/readline.h for libedit, but in at least one system -it is installed as editline/readline.h, so the configuration code now looks for -that first, falling back to readline/readline.h. */ - +/* Both libreadline and libedit are optionally supported */ #if defined(SUPPORT_LIBREADLINE) || defined(SUPPORT_LIBEDIT) #if defined(SUPPORT_LIBREADLINE) #include @@ -98,6 +94,11 @@ that first, falling back to readline/readline.h. */ #include #else #include +/* GNU readline defines this macro but libedit doesn't, if that ever changes +this needs to be updated or the build could break */ +#ifdef RL_VERSION_MAJOR +#include +#endif #endif #endif #endif