1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
From f8e7d124500e869ffc5643228c34d3745d64a3d7 Mon Sep 17 00:00:00 2001
From: Nicholas Wilson <nicholas@nicholaswilson.me.uk>
Date: Sat, 25 Oct 2025 12:28:05 +0100
Subject: [PATCH] Use correctly-cased CMake variables for better compatibility
(#825)
* Use the correct casing for <PackageName>_FOUND
* Add a CI test with CMake very latest (currently 4.1.2). This job also sets DCMAKE_POLICY_VERSION_MINIMUM to verify that we don't break any future policies, greater than our minimum version 3.15.
* Tidy the ncurses support for libreadline to use READLINE_LIBRARIES
---
.github/workflows/dev.yml | 140 +++++++++++++++++++++++++++++++++-----
CMakeLists.txt | 50 ++++++--------
cmake/FindEditline.cmake | 5 ++
cmake/FindReadline.cmake | 17 ++++-
4 files changed, 164 insertions(+), 48 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c97099601..ac3f8d001 100644
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -146,7 +146,7 @@ endif()
# setting CMAKE_MODULE_PATH on the command line.
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
-# external packages
+# External packages
find_package(BZip2)
find_package(ZLIB)
find_package(Readline)
@@ -446,7 +446,7 @@ if(HAVE_VSCRIPT)
endif()
# bzip2 lib
-if(BZIP2_FOUND)
+if(BZip2_FOUND)
option(PCRE2_SUPPORT_LIBBZ2 "Enable support for linking pcre2grep with libbz2." ON)
endif()
@@ -456,12 +456,12 @@ if(ZLIB_FOUND)
endif()
# editline lib
-if(EDITLINE_FOUND)
+if(Editline_FOUND)
option(PCRE2_SUPPORT_LIBEDIT "Enable support for linking pcre2test with libedit." OFF)
endif()
# readline lib
-if(READLINE_FOUND)
+if(Readline_FOUND)
option(PCRE2_SUPPORT_LIBREADLINE "Enable support for linking pcre2test with libreadline." ON)
endif()
@@ -498,12 +498,12 @@ if(PCRE2_BUILD_PCRE2GREP AND NOT PCRE2_BUILD_PCRE2_8)
endif()
if(PCRE2_SUPPORT_LIBBZ2)
- if(BZIP2_FOUND)
- include_directories(${BZIP2_INCLUDE_DIR})
+ if(BZip2_FOUND)
+ include_directories(${BZIP2_INCLUDE_DIRS})
else()
message(
FATAL_ERROR
- " libbz2 not found. Set BZIP2_INCLUDE_DIR to a compatible header\n"
+ " libbz2 not found. Set BZIP2_INCLUDE_DIRS to a compatible header\n"
" or set BZip2_ROOT to a full bzip2 installed tree, as needed."
)
endif()
@@ -511,42 +511,42 @@ endif()
if(PCRE2_SUPPORT_LIBZ)
if(ZLIB_FOUND)
- include_directories(${ZLIB_INCLUDE_DIR})
+ include_directories(${ZLIB_INCLUDE_DIRS})
else()
message(
FATAL_ERROR
- " zlib not found. Set ZLIB_INCLUDE_DIR to a compatible header\n"
+ " zlib not found. Set ZLIB_INCLUDE_DIRS to a compatible header\n"
" or set ZLIB_ROOT to a full zlib installed tree, as needed."
)
endif()
endif()
if(PCRE2_SUPPORT_LIBEDIT)
- if(EDITLINE_FOUND)
- include_directories(${EDITLINE_INCLUDE_DIR})
+ if(Editline_FOUND)
+ include_directories(${EDITLINE_INCLUDE_DIRS})
else()
message(
FATAL_ERROR
- " libedit not found. Set EDITLINE_INCLUDE_DIR to a compatible header\n"
+ " libedit not found. Set EDITLINE_INCLUDE_DIRS to a compatible header\n"
" or set Editline_ROOT to a full libedit installed tree, as needed."
)
endif()
endif()
if(PCRE2_SUPPORT_LIBREADLINE)
- if(READLINE_FOUND)
- include_directories(${READLINE_INCLUDE_DIR})
+ if(Readline_FOUND)
+ include_directories(${READLINE_INCLUDE_DIRS})
else()
message(
FATAL_ERROR
- " libreadline not found. Set READLINE_INCLUDE_DIR to a compatible header\n"
+ " libreadline not found. Set READLINE_INCLUDE_DIRS to a compatible header\n"
" or set Readline_ROOT to a full libreadline installed tree, as needed."
)
endif()
endif()
if(PCRE2_SUPPORT_LIBREADLINE AND PCRE2_SUPPORT_LIBEDIT)
- if(READLINE_FOUND)
+ if(Readline_FOUND)
message(
FATAL_ERROR
" Only one of the readline compatible libraries can be enabled.\n"
@@ -603,24 +603,16 @@ endif()
set(PCRE2TEST_LIBS)
set(PCRE2GREP_LIBS)
-# This next one used to reference ${READLINE_LIBRARY})
-# but I was advised to add the NCURSES test as well, along with
-# some modifications to cmake/FindReadline.cmake which should
-# make it possible to override the default if necessary. PH
-
if(PCRE2_SUPPORT_LIBREADLINE)
set(SUPPORT_LIBREADLINE 1)
- list(APPEND PCRE2TEST_LIBS ${READLINE_LIBRARY})
- if(DEFINED NCURSES_LIBRARY)
- list(APPEND PCRE2TEST_LIBS ${NCURSES_LIBRARY})
- endif()
+ list(APPEND PCRE2TEST_LIBS ${READLINE_LIBRARIES})
endif()
# libedit is a plug-compatible alternative to libreadline
if(PCRE2_SUPPORT_LIBEDIT)
set(SUPPORT_LIBEDIT 1)
- list(APPEND PCRE2TEST_LIBS ${EDITLINE_LIBRARY})
+ list(APPEND PCRE2TEST_LIBS ${EDITLINE_LIBRARIES})
endif()
if(PCRE2_SUPPORT_LIBZ)
@@ -1589,17 +1581,17 @@ if(PCRE2_SHOW_REPORT)
else()
message(STATUS " Link pcre2grep with libz .......... : Library not found")
endif()
- if(BZIP2_FOUND)
+ if(BZip2_FOUND)
message(STATUS " Link pcre2grep with libbz2 ........ : ${PCRE2_SUPPORT_LIBBZ2}")
else()
message(STATUS " Link pcre2grep with libbz2 ........ : Library not found")
endif()
- if(EDITLINE_FOUND)
+ if(Editline_FOUND)
message(STATUS " Link pcre2test with libeditline ... : ${PCRE2_SUPPORT_LIBEDIT}")
else()
message(STATUS " Link pcre2test with libeditline ... : Library not found")
endif()
- if(READLINE_FOUND)
+ if(Readline_FOUND)
message(STATUS " Link pcre2test with libreadline ... : ${PCRE2_SUPPORT_LIBREADLINE}")
else()
message(STATUS " Link pcre2test with libreadline ... : Library not found")
diff --git a/cmake/FindEditline.cmake b/cmake/FindEditline.cmake
index c973c7b64..4784e052c 100644
--- cmake/FindEditline.cmake
+++ cmake/FindEditline.cmake
@@ -8,3 +8,8 @@ mark_as_advanced(EDITLINE_LIBRARY)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Editline DEFAULT_MSG EDITLINE_LIBRARY EDITLINE_INCLUDE_DIR)
+
+if(Editline_FOUND)
+ set(EDITLINE_LIBRARIES "${EDITLINE_LIBRARY}")
+ set(EDITLINE_INCLUDE_DIRS "${EDITLINE_INCLUDE_DIR}")
+endif()
diff --git a/cmake/FindReadline.cmake b/cmake/FindReadline.cmake
index 399096c37..e55fbcf22 100644
--- cmake/FindReadline.cmake
+++ cmake/FindReadline.cmake
@@ -16,6 +16,11 @@ if(READLINE_INCLUDE_DIR AND READLINE_LIBRARY)
include(CheckSymbolExists)
include(CMakePushCheckState)
+ set(first_run FALSE)
+ if(NOT DEFINED HAVE_READLINE_FUNC)
+ set(first_run TRUE)
+ endif()
+
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_LIBRARIES "${READLINE_LIBRARY}")
set(CMAKE_REQUIRED_INCLUDES "${READLINE_INCLUDE_DIR}")
@@ -36,7 +41,9 @@ if(READLINE_INCLUDE_DIR AND READLINE_LIBRARY)
check_symbol_exists("readline" "stdio.h;readline/readline.h" HAVE_READLINE_FUNC_${lib})
if(HAVE_READLINE_FUNC_${lib})
- message(STATUS "Looking for readline - readline needs ${lib}")
+ if(first_run)
+ message(STATUS "Looking for readline - readline needs ${lib}")
+ endif()
set(NCURSES_LIBRARY "${NCURSES_LIBRARY_${lib}}" CACHE FILEPATH "Path to the ncurses library")
mark_as_advanced(NCURSES_LIBRARY)
break()
@@ -50,3 +57,11 @@ endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Readline DEFAULT_MSG READLINE_LIBRARY READLINE_INCLUDE_DIR)
+
+if(Readline_FOUND)
+ set(READLINE_LIBRARIES "${READLINE_LIBRARY}")
+ if(DEFINED NCURSES_LIBRARY)
+ list(APPEND READLINE_LIBRARIES "${NCURSES_LIBRARY}")
+ endif()
+ set(READLINE_INCLUDE_DIRS "${READLINE_INCLUDE_DIR}")
+endif()
|