From 28c42594c3a6e131118883ec733a233bd7fa6654 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlo=20Marcelo=20Arenas=20Bel=C3=B3n?= Date: Wed, 6 Apr 2022 22:01:18 -0700 Subject: [PATCH] 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. --- CMakeLists.txt | 19 +++++++++++++++---- cmake/FindEditline.cmake | 8 ++++---- src/pcre2test.c | 2 +- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e3a8dd..31c0a70 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -306,9 +306,15 @@ ENDIF(PCRE2_SUPPORT_LIBZ) IF(EDITLINE_FOUND) OPTION (PCRE2_SUPPORT_LIBEDIT "Enable support for linking pcre2test with libedit." OFF) ENDIF(EDITLINE_FOUND) -IF(PCRE2_SUPPORT_LIBEDIT) - INCLUDE_DIRECTORIES(${EDITLINE_INCLUDE_DIR}) -ENDIF(PCRE2_SUPPORT_LIBEDIT) +IF(EDITLINE_FOUND) + IF(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 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) 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) IF(PCRE2_SUPPORT_BSR_ANYCRLF) diff --git a/cmake/FindEditline.cmake b/cmake/FindEditline.cmake index 2d0b7cc..cbdc458 100644 --- a/cmake/FindEditline.cmake +++ b/cmake/FindEditline.cmake @@ -3,10 +3,10 @@ if(EDITLINE_INCLUDE_DIR AND EDITLINE_LIBRARY AND NCURSES_LIBRARY) set(EDITLINE_FOUND TRUE) else(EDITLINE_INCLUDE_DIR AND EDITLINE_LIBRARY AND NCURSES_LIBRARY) - FIND_PATH(EDITLINE_INCLUDE_DIR readline.h - /usr/include/editline - /usr/include/edit/readline - /usr/include/readline + FIND_PATH(EDITLINE_INCLUDE_DIR readline.h PATH_SUFFIXES + editline + edit/readline + readline ) FIND_LIBRARY(EDITLINE_LIBRARY NAMES edit) diff --git a/src/pcre2test.c b/src/pcre2test.c index 43cacdf..3de92b4 100644 --- a/src/pcre2test.c +++ b/src/pcre2test.c @@ -97,7 +97,7 @@ that first, falling back to readline/readline.h. */ #elif defined(HAVE_EDIT_READLINE_READLINE_H) #include #else -#include +#include #endif #endif #endif