Skip to content

Commit 5c1df9f

Browse files
authored
Modernise FindReadline.cmake, and fix on Solaris
1 parent c24eb7f commit 5c1df9f

File tree

6 files changed

+94
-59
lines changed

6 files changed

+94
-59
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ jobs:
420420
echo "== CMake, 64-bit =="
421421
cd ../build-cmake-64
422422
423-
CC="cc -m64" cmake $CMAKE_FLAGS -DNCURSES_LIBRARY=termcap -DPCRE2_BUILD_PCRE2_16=ON -DPCRE2_BUILD_PCRE2_32=ON -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=ON -DPCRE2_DEBUG=ON -DCMAKE_C_FLAGS="$CFLAGS_SOLARIS_CC" -DCMAKE_COMPILE_WARNING_AS_ERROR=ON -DCMAKE_BUILD_TYPE=Release -B build
423+
CC="cc -m64" cmake $CMAKE_FLAGS -DPCRE2_BUILD_PCRE2_16=ON -DPCRE2_BUILD_PCRE2_32=ON -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=ON -DPCRE2_DEBUG=ON -DCMAKE_C_FLAGS="$CFLAGS_SOLARIS_CC" -DCMAKE_COMPILE_WARNING_AS_ERROR=ON -DCMAKE_BUILD_TYPE=Release -B build
424424
cd build
425425
make
426426
ctest -j3 --output-on-failure

CMakeLists.txt

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ include(CheckSymbolExists)
161161
include(CheckIncludeFile)
162162
include(CheckTypeSize)
163163
include(CMakePackageConfigHelpers)
164+
include(CMakePushCheckState)
164165
include(GNUInstallDirs) # for CMAKE_INSTALL_LIBDIR
165166
include(PCRE2CheckLinkerFlag)
166167
include(PCRE2UseSystemExtensions)
@@ -172,6 +173,10 @@ check_include_file(sys/types.h HAVE_SYS_TYPES_H)
172173
check_include_file(unistd.h HAVE_UNISTD_H)
173174
check_include_file(windows.h HAVE_WINDOWS_H)
174175

176+
# Check whether any system-wide extensions need to be enabled, in order for
177+
# OS functionality to be exposed.
178+
pcre2_use_system_extensions()
179+
175180
check_symbol_exists(memfd_create "sys/mman.h" HAVE_MEMFD_CREATE)
176181
check_symbol_exists(secure_getenv "stdlib.h" HAVE_SECURE_GETENV)
177182

@@ -184,10 +189,10 @@ check_c_source_compiles(
184189
HAVE_REALPATH
185190
)
186191

192+
cmake_push_check_state()
187193
if(NOT DEFINED CMAKE_REQUIRED_FLAGS)
188194
set(CMAKE_REQUIRED_FLAGS "")
189195
endif()
190-
set(ORIG_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
191196
if(NOT MSVC AND NOT CMAKE_C_COMPILER_ID STREQUAL "XL" AND NOT CMAKE_C_COMPILER_ID STREQUAL "SunPro")
192197
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror")
193198
endif()
@@ -197,6 +202,7 @@ check_c_source_compiles(
197202
HAVE_ATTRIBUTE_UNINITIALIZED
198203
)
199204

205+
# TODO Consider switching to modern "GenerateExportHeader"
200206
check_c_source_compiles(
201207
[=[
202208
extern __attribute__ ((visibility ("default"))) int f(void);
@@ -206,14 +212,14 @@ check_c_source_compiles(
206212
HAVE_VISIBILITY
207213
)
208214

215+
cmake_pop_check_state()
216+
209217
if(HAVE_VISIBILITY)
210218
set(PCRE2_EXPORT [=[__attribute__ ((visibility ("default")))]=])
211219
else()
212220
set(PCRE2_EXPORT)
213221
endif()
214222

215-
set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
216-
217223
check_c_source_compiles("int main(void) { __assume(1); return 0; }" HAVE_BUILTIN_ASSUME)
218224

219225
check_c_source_compiles(
@@ -271,11 +277,6 @@ if(INTEL_CET_ENABLED)
271277
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mshstk")
272278
endif()
273279

274-
# Check whether any system-wide extensions need to be enabled, in order for
275-
# OS functionality to be exposed.
276-
277-
pcre2_use_system_extensions()
278-
279280
# User-configurable options
280281
#
281282
# Note: CMakeSetup displays these in alphabetical order, regardless of
@@ -537,19 +538,7 @@ if(PCRE2_SUPPORT_JIT)
537538
endif()
538539

539540
if(PCRE2_SUPPORT_JIT_SEALLOC)
540-
set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
541-
check_symbol_exists(mkostemp stdlib.h REQUIRED)
542-
unset(CMAKE_REQUIRED_DEFINITIONS)
543-
if(${REQUIRED})
544-
if(${CMAKE_SYSTEM_NAME} MATCHES Linux|NetBSD)
545-
add_compile_definitions(_GNU_SOURCE)
546-
set(SLJIT_PROT_EXECUTABLE_ALLOCATOR 1)
547-
else()
548-
message(FATAL_ERROR "Your configuration is not supported")
549-
endif()
550-
else()
551-
set(PCRE2_SUPPORT_JIT_SEALLOC OFF)
552-
endif()
541+
set(SLJIT_PROT_EXECUTABLE_ALLOCATOR 1)
553542
endif()
554543

555544
if(PCRE2GREP_SUPPORT_JIT)

cmake/FindEditline.cmake

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
# Modified from FindReadline.cmake (PH Feb 2012)
22

3-
if(EDITLINE_INCLUDE_DIR AND EDITLINE_LIBRARY)
4-
set(EDITLINE_FOUND TRUE)
5-
else()
6-
find_path(EDITLINE_INCLUDE_DIR readline.h PATH_SUFFIXES editline edit/readline)
3+
find_path(EDITLINE_INCLUDE_DIR readline.h PATH_SUFFIXES editline edit/readline)
4+
mark_as_advanced(EDITLINE_INCLUDE_DIR)
75

8-
find_library(EDITLINE_LIBRARY NAMES edit)
9-
include(FindPackageHandleStandardArgs)
10-
find_package_handle_standard_args(Editline DEFAULT_MSG EDITLINE_INCLUDE_DIR EDITLINE_LIBRARY)
6+
find_library(EDITLINE_LIBRARY NAMES edit)
7+
mark_as_advanced(EDITLINE_LIBRARY)
118

12-
mark_as_advanced(EDITLINE_INCLUDE_DIR EDITLINE_LIBRARY)
13-
endif()
9+
include(FindPackageHandleStandardArgs)
10+
find_package_handle_standard_args(Editline DEFAULT_MSG EDITLINE_LIBRARY EDITLINE_INCLUDE_DIR)

cmake/FindReadline.cmake

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,53 @@
33
# --> BSD licensed
44
#
55
# GNU Readline library finder
6-
if(READLINE_INCLUDE_DIR AND READLINE_LIBRARY AND NCURSES_LIBRARY)
7-
set(READLINE_FOUND TRUE)
8-
else()
9-
find_path(READLINE_INCLUDE_DIR readline/readline.h /usr/include/readline)
10-
11-
# 2008-04-22 The next clause used to read like this:
12-
#
13-
# FIND_LIBRARY(READLINE_LIBRARY NAMES readline)
14-
# FIND_LIBRARY(NCURSES_LIBRARY NAMES ncurses )
15-
# include(FindPackageHandleStandardArgs)
16-
# FIND_PACKAGE_HANDLE_STANDARD_ARGS(Readline DEFAULT_MSG NCURSES_LIBRARY READLINE_INCLUDE_DIR READLINE_LIBRARY )
17-
#
18-
# I was advised to modify it such that it will find an ncurses library if
19-
# required, but not if one was explicitly given, that is, it allows the
20-
# default to be overridden. PH
21-
22-
find_library(READLINE_LIBRARY NAMES readline)
23-
include(FindPackageHandleStandardArgs)
24-
find_package_handle_standard_args(Readline DEFAULT_MSG READLINE_INCLUDE_DIR READLINE_LIBRARY)
25-
26-
mark_as_advanced(READLINE_INCLUDE_DIR READLINE_LIBRARY)
6+
7+
find_path(READLINE_INCLUDE_DIR readline/readline.h PATH_SUFFIXES include)
8+
mark_as_advanced(READLINE_INCLUDE_DIR)
9+
10+
find_library(READLINE_LIBRARY NAMES readline)
11+
mark_as_advanced(READLINE_LIBRARY)
12+
13+
if(READLINE_INCLUDE_DIR AND READLINE_LIBRARY)
14+
# Check if we need to link to ncurses as well
15+
16+
include(CheckSymbolExists)
17+
include(CMakePushCheckState)
18+
19+
cmake_push_check_state(RESET)
20+
set(CMAKE_REQUIRED_LIBRARIES "${READLINE_LIBRARY}")
21+
set(CMAKE_REQUIRED_INCLUDES "${READLINE_INCLUDE_DIR}")
22+
check_symbol_exists("readline" "stdio.h;readline/readline.h" HAVE_READLINE_FUNC)
23+
24+
if(NOT HAVE_READLINE_FUNC)
25+
foreach(
26+
lib IN ITEMS
27+
tinfo
28+
curses
29+
ncurses
30+
ncursesw
31+
termcap
32+
)
33+
find_library(NCURSES_LIBRARY_${lib} NAMES ${lib})
34+
mark_as_advanced(NCURSES_LIBRARY_${lib})
35+
if(NCURSES_LIBRARY_${lib})
36+
cmake_reset_check_state()
37+
set(CMAKE_REQUIRED_LIBRARIES "${READLINE_LIBRARY}" "${NCURSES_LIBRARY_${lib}}")
38+
set(CMAKE_REQUIRED_INCLUDES "${READLINE_INCLUDE_DIR}")
39+
check_symbol_exists("readline" "stdio.h;readline/readline.h" HAVE_READLINE_FUNC_${lib})
40+
41+
if(HAVE_READLINE_FUNC_${lib})
42+
message(STATUS "Looking for readline - readline needs ${lib}")
43+
set(NCURSES_LIBRARY "${NCURSES_LIBRARY_${lib}}" CACHE FILEPATH "Path to the ncurses library")
44+
mark_as_advanced(NCURSES_LIBRARY)
45+
break()
46+
endif()
47+
endif()
48+
endforeach()
49+
endif()
50+
51+
cmake_pop_check_state()
2752
endif()
53+
54+
include(FindPackageHandleStandardArgs)
55+
find_package_handle_standard_args(Readline DEFAULT_MSG READLINE_LIBRARY READLINE_INCLUDE_DIR)

cmake/PCRE2UseSystemExtensions.cmake

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,23 @@
1010
# So far, we know that we require:
1111
# - _ALL_SOURCE on IBM systems (z/OS, probably AIX) in order to call
1212
# getrlimit() in pcre2test.
13+
# - _GNU_SOURCE on Linux in order to call mkostemp() in some (non-default)
14+
# configurations of the JIT.
1315
#
1416
# Autoconf enables this unconditionally. However, our CMake script potentially
1517
# supports *more* platforms than Autoconf, so we use a feature check.
1618

1719
function(pcre2_use_system_extensions)
18-
if (WIN32)
20+
if(WIN32)
1921
return()
2022
endif()
2123

2224
include(CheckCSourceCompiles)
25+
include(CMakePushCheckState)
2326

24-
set(_pcre2_test_src "
27+
set(
28+
_pcre2_test_src
29+
"
2530
#include <sys/time.h>
2631
#include <sys/resource.h>
2732
@@ -30,18 +35,34 @@ int main(void) {
3035
getrlimit(RLIMIT_STACK, &rlim);
3136
return 0;
3237
}
33-
")
38+
"
39+
)
3440

3541
check_c_source_compiles("${_pcre2_test_src}" HAVE_GETRLIMIT)
3642

37-
if (NOT HAVE_GETRLIMIT)
43+
if(NOT HAVE_GETRLIMIT)
3844
# Try again with _ALL_SOURCE
45+
cmake_push_check_state(RESET)
3946
set(CMAKE_REQUIRED_DEFINITIONS "-D_ALL_SOURCE")
4047
check_c_source_compiles("${_pcre2_test_src}" HAVE_GETRLIMIT_ALLSOURCE)
41-
unset(CMAKE_REQUIRED_DEFINITIONS)
48+
cmake_pop_check_state()
4249

43-
if (HAVE_GETRLIMIT_ALLSOURCE)
50+
if(HAVE_GETRLIMIT_ALLSOURCE)
4451
add_compile_definitions(_ALL_SOURCE)
4552
endif()
4653
endif()
54+
55+
check_symbol_exists(mkostemp stdlib.h HAVE_MKOSTEMP)
56+
57+
if(NOT HAVE_MKOSTEMP)
58+
# Try again with _GNU_SOURCE
59+
cmake_push_check_state(RESET)
60+
set(CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE")
61+
check_symbol_exists(mkostemp stdlib.h HAVE_MKOSTEMP_GNUSOURCE)
62+
cmake_pop_check_state()
63+
64+
if(HAVE_MKOSTEMP_GNUSOURCE)
65+
add_compile_definitions(_GNU_SOURCE)
66+
endif()
67+
endif()
4768
endfunction()

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM([[
677677
AC_MSG_RESULT([no]))
678678
LIBS="$OLD_LIBS"
679679

680-
# Check for the availabiity of libreadline
680+
# Check for the availability of libreadline
681681

682682
if test "$enable_pcre2test_libreadline" = "yes"; then
683683
AC_CHECK_HEADERS([readline/readline.h], [HAVE_READLINE_H=1])

0 commit comments

Comments
 (0)