Skip to content

Commit f8e7d12

Browse files
authored
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
1 parent edc111a commit f8e7d12

File tree

4 files changed

+164
-48
lines changed

4 files changed

+164
-48
lines changed

.github/workflows/dev.yml

Lines changed: 122 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ on:
1111
- all
1212
- canary
1313
- dragon
14-
- greatawk
14+
- puffin
1515
- dodo
1616
- passenger
17+
- greatawk
1718
- wasp
1819
- bat
1920
- pterodactyl
@@ -97,27 +98,52 @@ jobs:
9798
ulimit -S -s 49152 # Raise stack limit; ASAN with -O0 is very stack-hungry
9899
(make check; rc=$?; for i in test-suite.log Run*Test.log pcre2*_test.log; do echo "== $i =="; cat $i; done; exit $rc)
99100
100-
greatawk:
101-
# Tests with: GCC, -O3, oldest supported Ubuntu (in non-extended support)
102-
name: GCC -O3
101+
puffin:
102+
# Tests with: GCC, -O3, very latest CMake, libedit
103+
name: GCC -O3, CMake
103104
runs-on: ubuntu-latest
104-
container: ubuntu:22.04
105-
if: github.event_name != 'workflow_dispatch' || (inputs.job_id == 'all' || inputs.job_id == 'greatawk')
105+
if: github.event_name != 'workflow_dispatch' || (inputs.job_id == 'all' || inputs.job_id == 'puffin')
106106
steps:
107107
- name: Setup
108108
run: |
109-
echo "set man-db/auto-update false" | debconf-communicate && dpkg-reconfigure man-db
110-
export DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC
111-
apt-get -qq update
112-
apt-get -qq install -y git build-essential cmake
109+
echo "set man-db/auto-update false" | sudo debconf-communicate && sudo dpkg-reconfigure man-db
110+
sudo apt-get -qq update
111+
sudo apt-get -qq install -y git build-essential cmake zlib1g-dev libbz2-dev libedit-dev
113112
114113
- name: Checkout
115114
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
116115
with:
117116
submodules: true
118117

118+
- name: Check latest CMake
119+
id: get-cmake-ver
120+
run: |
121+
CMAKE_VER=$(curl -s https://api.github.com/repos/Kitware/CMake/releases/latest | jq -r '.tag_name' | sed 's/^v//')
122+
if ! echo "$CMAKE_VER" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$' ; then
123+
echo "Extracted CMake version: '$CMAKE_VER'" >&2
124+
echo "This does not match the expected version format" >&2
125+
exit 1
126+
fi
127+
echo "CMAKE_VER=$CMAKE_VER" >> $GITHUB_OUTPUT
128+
echo "CMAKE_VER=$CMAKE_VER" >> $GITHUB_ENV
129+
echo "Latest CMake version is $CMAKE_VER"
130+
131+
- name: Cache CMake
132+
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
133+
with:
134+
key: cmake-${{ steps.get-cmake-ver.outputs.CMAKE_VER }}-linux-x86_64
135+
path: cmake-${{ steps.get-cmake-ver.outputs.CMAKE_VER }}-linux-x86_64.tar.gz
136+
137+
- name: Install CMake
138+
run: |
139+
[ -f cmake-${CMAKE_VER}-linux-x86_64.tar.gz ] || curl -L -S -O "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VER}/cmake-${CMAKE_VER}-linux-x86_64.tar.gz"
140+
tar -xz -f cmake-${CMAKE_VER}-linux-x86_64.tar.gz -C "$RUNNER_TEMP"
141+
realpath "$RUNNER_TEMP/cmake-${CMAKE_VER}-linux-x86_64/bin" >> "$GITHUB_PATH"
142+
119143
- name: Configure
120-
run: cmake $CMAKE_FLAGS -DPCRE2_SUPPORT_JIT=ON -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_GCC_STYLE" -DCMAKE_COMPILE_WARNING_AS_ERROR=ON -DCMAKE_BUILD_TYPE=Release -B build
144+
run: |
145+
cmake --version | grep "version ${CMAKE_VER}" || (echo "CMake version mismatch" && exit 1)
146+
cmake $CMAKE_FLAGS -DPCRE2_SUPPORT_JIT=ON -DPCRE2_BUILD_PCRE2_16=ON -DPCRE2_BUILD_PCRE2_32=ON -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=ON -DPCRE2_DEBUG=ON -DPCRE2_SUPPORT_LIBEDIT=ON -DPCRE2_SUPPORT_LIBREADLINE=OFF -DCMAKE_C_FLAGS="$CFLAGS_GCC_STYLE" -DCMAKE_POLICY_VERSION_MINIMUM=$CMAKE_VER -DCMAKE_COMPILE_WARNING_AS_ERROR=ON -DCMAKE_BUILD_TYPE=Release -B build
121147
122148
- name: Build
123149
run: cd build && make -j3
@@ -251,9 +277,88 @@ jobs:
251277
maint/RunManifestTest install-dir maint/manifest-makeinstall-linux
252278
maint/RunSymbolTest install-dir/usr/local/lib/ maint/
253279
280+
greatawk:
281+
# Tests with: GCC, -O2, oldest supported Ubuntu (in non-extended support)
282+
name: GCC -O2, old CMake
283+
runs-on: ubuntu-latest
284+
container: ubuntu:22.04
285+
if: github.event_name != 'workflow_dispatch' || (inputs.job_id == 'all' || inputs.job_id == 'greatawk')
286+
steps:
287+
- name: Setup
288+
run: |
289+
echo "set man-db/auto-update false" | debconf-communicate && dpkg-reconfigure man-db
290+
export DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC
291+
apt-get -qq update
292+
apt-get -qq install -y git build-essential cmake zlib1g-dev libbz2-dev libreadline-dev
293+
294+
- name: Checkout
295+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
296+
with:
297+
submodules: true
298+
299+
- name: Configure
300+
run: cmake $CMAKE_FLAGS -DPCRE2_SUPPORT_JIT=ON -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_GCC_STYLE" -DCMAKE_COMPILE_WARNING_AS_ERROR=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -B build
301+
302+
- name: Build
303+
run: cd build && make -j3
304+
305+
- name: Test
306+
run: cd build && ctest -j3 --output-on-failure && (cat ./Testing/Temporary/LastTest.log || true)
307+
308+
- name: Install
309+
run: |
310+
cd build
311+
cmake --install . --prefix install-dir
312+
../maint/RunManifestTest install-dir ../maint/manifest-cmakeinstall-linux relwithdebinfo
313+
../maint/RunSymbolTest install-dir/lib/ ../maint/
314+
315+
- name: Test CMake install interface
316+
run: |
317+
INSTALL_PREFIX=`pwd`/build/install-dir
318+
cd maint/cmake-tests/install-interface
319+
320+
for useStaticLibs in ON OFF; do
321+
echo "== Testing CMake install interface with PCRE2_USE_STATIC_LIBS=$useStaticLibs =="
322+
rm -rf build
323+
cmake $CMAKE_FLAGS -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_PREFIX_PATH="$INSTALL_PREFIX" -DPCRE2_USE_STATIC_LIBS=$useStaticLibs -B build
324+
(cd build; make)
325+
./build/test_executable
326+
ldd ./build/test_executable
327+
if [ $useStaticLibs = ON ]; then
328+
(ldd ./build/test_executable | grep -q "pcre2") && (echo "Error: PCRE2 found in ldd output" && exit 1)
329+
else
330+
# Test that the shared library is actually linked in
331+
(ldd ./build/test_executable | grep -q "$INSTALL_PREFIX/lib/libpcre2-8.so.0") || (echo "Error: Shared library not linked in" && exit 1)
332+
fi
333+
done
334+
335+
- name: Test CMake build interface
336+
run: |
337+
BUILD_DIR=`pwd`
338+
cp -rp maint/cmake-tests/build-interface ../cmake-tests-build-interface
339+
cd ../cmake-tests-build-interface
340+
ln -s "$BUILD_DIR" pcre2
341+
342+
for buildLibs in "ON;OFF" "OFF;ON"; do
343+
static=`echo $buildLibs | cut -d';' -f1`
344+
shared=`echo $buildLibs | cut -d';' -f2`
345+
echo "== Testing CMake build interface with BUILD_STATIC_LIBS=$static and BUILD_SHARED_LIBS=$shared =="
346+
rm -rf build
347+
cmake $CMAKE_FLAGS -DCMAKE_BUILD_TYPE=Debug -DBUILD_STATIC_LIBS=$static -DBUILD_SHARED_LIBS=$shared -B build
348+
(cd build; make)
349+
./build/test_executable
350+
ldd ./build/test_executable
351+
if [ $static = ON ]; then
352+
(ldd ./build/test_executable | grep -q "pcre2") && (echo "Error: PCRE2 found in ldd output" && exit 1)
353+
else
354+
# Test that the shared library is actually linked in
355+
(ldd ./build/test_executable | grep -q "`pwd`/build/pcre2/libpcre2-8.so.0") || (echo "Error: Shared library not linked in" && exit 1)
356+
fi
357+
done
358+
254359
wasp:
255360
# Tests with: French locale; oldest supported CMake; no JIT; -Os; libreadline
256-
name: GCC -Os, CMake+ninja, no JIT
361+
name: GCC -Os, very old CMake, ninja, no JIT
257362
runs-on: ubuntu-latest
258363
if: github.event_name != 'workflow_dispatch' || (inputs.job_id == 'all' || inputs.job_id == 'wasp')
259364
env:
@@ -263,7 +368,7 @@ jobs:
263368
run: |
264369
echo "set man-db/auto-update false" | sudo debconf-communicate && sudo dpkg-reconfigure man-db
265370
sudo apt-get -qq update
266-
sudo apt-get -qq install -y language-pack-fr ninja-build libreadline-dev
371+
sudo apt-get -qq install -y language-pack-fr ninja-build zlib1g-dev libbz2-dev libreadline-dev
267372
268373
- name: Checkout
269374
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
@@ -274,14 +379,13 @@ jobs:
274379
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
275380
with:
276381
key: cmake-${{ env.CMAKE_VER }}-Linux-x86_64
277-
path: ../cmake-${{ env.CMAKE_VER }}-Linux-x86_64.tar.gz
382+
path: cmake-${{ env.CMAKE_VER }}-Linux-x86_64.tar.gz
278383

279384
- name: Install CMake
280385
run: |
281-
cd ..
282386
[ -f cmake-${CMAKE_VER}-Linux-x86_64.tar.gz ] || curl -L -S -O "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VER}/cmake-${CMAKE_VER}-Linux-x86_64.tar.gz"
283-
tar -xz -f cmake-${CMAKE_VER}-Linux-x86_64.tar.gz
284-
realpath "cmake-${CMAKE_VER}-Linux-x86_64/bin" >> "$GITHUB_PATH"
387+
tar -xz -f cmake-${CMAKE_VER}-Linux-x86_64.tar.gz -C "$RUNNER_TEMP"
388+
realpath "$RUNNER_TEMP/cmake-${CMAKE_VER}-Linux-x86_64/bin" >> "$GITHUB_PATH"
285389
286390
- name: Configure
287391
run: |
@@ -511,7 +615,7 @@ jobs:
511615
install: |
512616
echo "set man-db/auto-update false" | debconf-communicate && dpkg-reconfigure man-db
513617
apt-get -qq update
514-
apt-get -qq install -y gcc cmake ninja-build zlib1g-dev libbz2-dev
618+
apt-get -qq install -y gcc cmake ninja-build zlib1g-dev libbz2-dev libreadline-dev
515619
516620
run: |
517621
set -e

CMakeLists.txt

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ endif()
146146
# setting CMAKE_MODULE_PATH on the command line.
147147
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
148148

149-
# external packages
149+
# External packages
150150
find_package(BZip2)
151151
find_package(ZLIB)
152152
find_package(Readline)
@@ -446,7 +446,7 @@ if(HAVE_VSCRIPT)
446446
endif()
447447

448448
# bzip2 lib
449-
if(BZIP2_FOUND)
449+
if(BZip2_FOUND)
450450
option(PCRE2_SUPPORT_LIBBZ2 "Enable support for linking pcre2grep with libbz2." ON)
451451
endif()
452452

@@ -456,12 +456,12 @@ if(ZLIB_FOUND)
456456
endif()
457457

458458
# editline lib
459-
if(EDITLINE_FOUND)
459+
if(Editline_FOUND)
460460
option(PCRE2_SUPPORT_LIBEDIT "Enable support for linking pcre2test with libedit." OFF)
461461
endif()
462462

463463
# readline lib
464-
if(READLINE_FOUND)
464+
if(Readline_FOUND)
465465
option(PCRE2_SUPPORT_LIBREADLINE "Enable support for linking pcre2test with libreadline." ON)
466466
endif()
467467

@@ -498,55 +498,55 @@ if(PCRE2_BUILD_PCRE2GREP AND NOT PCRE2_BUILD_PCRE2_8)
498498
endif()
499499

500500
if(PCRE2_SUPPORT_LIBBZ2)
501-
if(BZIP2_FOUND)
502-
include_directories(${BZIP2_INCLUDE_DIR})
501+
if(BZip2_FOUND)
502+
include_directories(${BZIP2_INCLUDE_DIRS})
503503
else()
504504
message(
505505
FATAL_ERROR
506-
" libbz2 not found. Set BZIP2_INCLUDE_DIR to a compatible header\n"
506+
" libbz2 not found. Set BZIP2_INCLUDE_DIRS to a compatible header\n"
507507
" or set BZip2_ROOT to a full bzip2 installed tree, as needed."
508508
)
509509
endif()
510510
endif()
511511

512512
if(PCRE2_SUPPORT_LIBZ)
513513
if(ZLIB_FOUND)
514-
include_directories(${ZLIB_INCLUDE_DIR})
514+
include_directories(${ZLIB_INCLUDE_DIRS})
515515
else()
516516
message(
517517
FATAL_ERROR
518-
" zlib not found. Set ZLIB_INCLUDE_DIR to a compatible header\n"
518+
" zlib not found. Set ZLIB_INCLUDE_DIRS to a compatible header\n"
519519
" or set ZLIB_ROOT to a full zlib installed tree, as needed."
520520
)
521521
endif()
522522
endif()
523523

524524
if(PCRE2_SUPPORT_LIBEDIT)
525-
if(EDITLINE_FOUND)
526-
include_directories(${EDITLINE_INCLUDE_DIR})
525+
if(Editline_FOUND)
526+
include_directories(${EDITLINE_INCLUDE_DIRS})
527527
else()
528528
message(
529529
FATAL_ERROR
530-
" libedit not found. Set EDITLINE_INCLUDE_DIR to a compatible header\n"
530+
" libedit not found. Set EDITLINE_INCLUDE_DIRS to a compatible header\n"
531531
" or set Editline_ROOT to a full libedit installed tree, as needed."
532532
)
533533
endif()
534534
endif()
535535

536536
if(PCRE2_SUPPORT_LIBREADLINE)
537-
if(READLINE_FOUND)
538-
include_directories(${READLINE_INCLUDE_DIR})
537+
if(Readline_FOUND)
538+
include_directories(${READLINE_INCLUDE_DIRS})
539539
else()
540540
message(
541541
FATAL_ERROR
542-
" libreadline not found. Set READLINE_INCLUDE_DIR to a compatible header\n"
542+
" libreadline not found. Set READLINE_INCLUDE_DIRS to a compatible header\n"
543543
" or set Readline_ROOT to a full libreadline installed tree, as needed."
544544
)
545545
endif()
546546
endif()
547547

548548
if(PCRE2_SUPPORT_LIBREADLINE AND PCRE2_SUPPORT_LIBEDIT)
549-
if(READLINE_FOUND)
549+
if(Readline_FOUND)
550550
message(
551551
FATAL_ERROR
552552
" Only one of the readline compatible libraries can be enabled.\n"
@@ -603,24 +603,16 @@ endif()
603603
set(PCRE2TEST_LIBS)
604604
set(PCRE2GREP_LIBS)
605605

606-
# This next one used to reference ${READLINE_LIBRARY})
607-
# but I was advised to add the NCURSES test as well, along with
608-
# some modifications to cmake/FindReadline.cmake which should
609-
# make it possible to override the default if necessary. PH
610-
611606
if(PCRE2_SUPPORT_LIBREADLINE)
612607
set(SUPPORT_LIBREADLINE 1)
613-
list(APPEND PCRE2TEST_LIBS ${READLINE_LIBRARY})
614-
if(DEFINED NCURSES_LIBRARY)
615-
list(APPEND PCRE2TEST_LIBS ${NCURSES_LIBRARY})
616-
endif()
608+
list(APPEND PCRE2TEST_LIBS ${READLINE_LIBRARIES})
617609
endif()
618610

619611
# libedit is a plug-compatible alternative to libreadline
620612

621613
if(PCRE2_SUPPORT_LIBEDIT)
622614
set(SUPPORT_LIBEDIT 1)
623-
list(APPEND PCRE2TEST_LIBS ${EDITLINE_LIBRARY})
615+
list(APPEND PCRE2TEST_LIBS ${EDITLINE_LIBRARIES})
624616
endif()
625617

626618
if(PCRE2_SUPPORT_LIBZ)
@@ -1589,17 +1581,17 @@ if(PCRE2_SHOW_REPORT)
15891581
else()
15901582
message(STATUS " Link pcre2grep with libz .......... : Library not found")
15911583
endif()
1592-
if(BZIP2_FOUND)
1584+
if(BZip2_FOUND)
15931585
message(STATUS " Link pcre2grep with libbz2 ........ : ${PCRE2_SUPPORT_LIBBZ2}")
15941586
else()
15951587
message(STATUS " Link pcre2grep with libbz2 ........ : Library not found")
15961588
endif()
1597-
if(EDITLINE_FOUND)
1589+
if(Editline_FOUND)
15981590
message(STATUS " Link pcre2test with libeditline ... : ${PCRE2_SUPPORT_LIBEDIT}")
15991591
else()
16001592
message(STATUS " Link pcre2test with libeditline ... : Library not found")
16011593
endif()
1602-
if(READLINE_FOUND)
1594+
if(Readline_FOUND)
16031595
message(STATUS " Link pcre2test with libreadline ... : ${PCRE2_SUPPORT_LIBREADLINE}")
16041596
else()
16051597
message(STATUS " Link pcre2test with libreadline ... : Library not found")

cmake/FindEditline.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@ mark_as_advanced(EDITLINE_LIBRARY)
88

99
include(FindPackageHandleStandardArgs)
1010
find_package_handle_standard_args(Editline DEFAULT_MSG EDITLINE_LIBRARY EDITLINE_INCLUDE_DIR)
11+
12+
if(Editline_FOUND)
13+
set(EDITLINE_LIBRARIES "${EDITLINE_LIBRARY}")
14+
set(EDITLINE_INCLUDE_DIRS "${EDITLINE_INCLUDE_DIR}")
15+
endif()

cmake/FindReadline.cmake

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ if(READLINE_INCLUDE_DIR AND READLINE_LIBRARY)
1616
include(CheckSymbolExists)
1717
include(CMakePushCheckState)
1818

19+
set(first_run FALSE)
20+
if(NOT DEFINED HAVE_READLINE_FUNC)
21+
set(first_run TRUE)
22+
endif()
23+
1924
cmake_push_check_state(RESET)
2025
set(CMAKE_REQUIRED_LIBRARIES "${READLINE_LIBRARY}")
2126
set(CMAKE_REQUIRED_INCLUDES "${READLINE_INCLUDE_DIR}")
@@ -36,7 +41,9 @@ if(READLINE_INCLUDE_DIR AND READLINE_LIBRARY)
3641
check_symbol_exists("readline" "stdio.h;readline/readline.h" HAVE_READLINE_FUNC_${lib})
3742

3843
if(HAVE_READLINE_FUNC_${lib})
39-
message(STATUS "Looking for readline - readline needs ${lib}")
44+
if(first_run)
45+
message(STATUS "Looking for readline - readline needs ${lib}")
46+
endif()
4047
set(NCURSES_LIBRARY "${NCURSES_LIBRARY_${lib}}" CACHE FILEPATH "Path to the ncurses library")
4148
mark_as_advanced(NCURSES_LIBRARY)
4249
break()
@@ -50,3 +57,11 @@ endif()
5057

5158
include(FindPackageHandleStandardArgs)
5259
find_package_handle_standard_args(Readline DEFAULT_MSG READLINE_LIBRARY READLINE_INCLUDE_DIR)
60+
61+
if(Readline_FOUND)
62+
set(READLINE_LIBRARIES "${READLINE_LIBRARY}")
63+
if(DEFINED NCURSES_LIBRARY)
64+
list(APPEND READLINE_LIBRARIES "${NCURSES_LIBRARY}")
65+
endif()
66+
set(READLINE_INCLUDE_DIRS "${READLINE_INCLUDE_DIR}")
67+
endif()

0 commit comments

Comments
 (0)