Skip to content

Commit 42c9edd

Browse files
danmardmcppcheckclaudepfultz2
authored
Fix #10610 (Support for PCRE2) (#9003)
Replace the discontinued PCRE library with PCRE2 for rules PCRE (8.x) is end of life and is being removed from Linux distributions. - lib/regex.cpp: use the PCRE2 API (with JIT when available) - fix endless loop when a rule pattern matches an empty string - CMake, Makefile, dmake and Visual Studio project use PCRE2 - CI installs/builds PCRE2 instead of PCRE - update documentation Rule files and the "pcre" engine name are unchanged. --------- Co-authored-by: Daniel Marjamäki <daniel.marjamaki@cppcheck.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Paul Fultz II <paul.fultz@amd.com>
1 parent 530e59f commit 42c9edd

23 files changed

Lines changed: 176 additions & 308 deletions

‎.github/workflows/CI-unixish-docker.yml‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
if: contains(matrix.image, 'ubuntu')
5252
run: |
5353
apt-get update
54-
apt-get install -y cmake g++ make libxml2-utils libpcre3-dev
54+
apt-get install -y cmake g++ make libxml2-utils libpcre2-dev
5555
5656
- name: Install missing software (gui) on latest ubuntu
5757
if: contains(matrix.image, 'ubuntu')
@@ -61,7 +61,7 @@ jobs:
6161
- name: Install missing software on Alpine
6262
if: contains(matrix.image, 'alpine')
6363
run: |
64-
apk add cmake make g++ pcre-dev
64+
apk add cmake make g++ pcre2-dev
6565
6666
# needs to be called after the package installation since
6767
# - it doesn't call "apt-get update"
@@ -104,12 +104,12 @@ jobs:
104104
if: contains(matrix.image, 'ubuntu')
105105
run: |
106106
apt-get update
107-
apt-get install -y g++ make python3 libxml2-utils libpcre3-dev
107+
apt-get install -y g++ make python3 libxml2-utils libpcre2-dev
108108
109109
- name: Install missing software on Alpine
110110
if: contains(matrix.image, 'alpine')
111111
run: |
112-
apk add make g++ pcre-dev bash python3 libxml2-utils
112+
apk add make g++ pcre2-dev bash python3 libxml2-utils
113113
114114
# needs to be called after the package installation since
115115
# - it doesn't call "apt-get update"

‎.github/workflows/CI-unixish.yml‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ jobs:
5252
- name: Install missing software on macos
5353
if: contains(matrix.os, 'macos')
5454
run: |
55-
# pcre was removed from runner images in November 2022
56-
brew install coreutils qt@6 tinyxml2 pcre
55+
brew install coreutils qt@6 tinyxml2 pcre2
5756
5857
- name: CMake build on ubuntu (with GUI / system tinyxml2)
5958
if: contains(matrix.os, 'ubuntu')
@@ -121,8 +120,7 @@ jobs:
121120
- name: Install missing software on macos
122121
if: contains(matrix.os, 'macos')
123122
run: |
124-
# pcre was removed from runner images in November 2022
125-
brew install coreutils qt@6 pcre
123+
brew install coreutils qt@6 pcre2
126124
127125
- name: Run CMake on ubuntu (with GUI)
128126
if: contains(matrix.os, 'ubuntu')
@@ -238,8 +236,7 @@ jobs:
238236
- name: Install missing software on macos
239237
if: contains(matrix.os, 'macos')
240238
run: |
241-
# pcre was removed from runner images in November 2022
242-
brew install coreutils qt@6 pcre
239+
brew install coreutils qt@6 pcre2
243240
244241
- name: Run CMake on ubuntu (with GUI)
245242
if: contains(matrix.os, 'ubuntu')
@@ -486,8 +483,7 @@ jobs:
486483
- name: Install missing software on macos
487484
if: contains(matrix.os, 'macos')
488485
run: |
489-
# pcre was removed from runner images in November 2022
490-
brew install coreutils pcre gnu-sed
486+
brew install coreutils pcre2 gnu-sed
491487
492488
- name: Install missing Python packages on ubuntu
493489
if: contains(matrix.os, 'ubuntu')

‎.github/workflows/CI-windows.yml‎

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,8 @@ jobs:
150150
runs-on: ${{ matrix.os }}
151151

152152
env:
153-
# see https://www.pcre.org/original/changelog.txt
154-
PCRE_VERSION: 8.45
155-
153+
# see https://github.com/PCRE2Project/pcre2/blob/master/ChangeLog
154+
PCRE2_VERSION: 10.49
156155
steps:
157156
- uses: actions/checkout@v6
158157
with:
@@ -170,32 +169,31 @@ jobs:
170169
with:
171170
arch: x64
172171

173-
- name: Cache PCRE
174-
id: cache-pcre
172+
- name: Cache PCRE2
173+
id: cache-pcre2
175174
uses: actions/cache@v5
176175
with:
177176
path: |
178-
externals\pcre.h
179-
externals\pcre.lib
180-
externals\pcre64.lib
181-
key: pcre-${{ env.PCRE_VERSION }}-x64-bin-win
177+
externals\pcre2.h
178+
externals\pcre2-8.lib
179+
key: pcre2-${{ env.PCRE2_VERSION }}-x64-bin-win
182180

183-
- name: Download PCRE
184-
if: steps.cache-pcre.outputs.cache-hit != 'true'
181+
- name: Download PCRE2
182+
if: steps.cache-pcre2.outputs.cache-hit != 'true'
185183
run: |
186-
curl -fsSL https://github.com/pfultz2/pcre/archive/refs/tags/%PCRE_VERSION%.zip -o pcre-%PCRE_VERSION%.zip || exit /b !errorlevel!
184+
curl -fsSL https://github.com/PCRE2Project/pcre2/releases/download/pcre2-%PCRE2_VERSION%/pcre2-%PCRE2_VERSION%.zip -o pcre2-%PCRE2_VERSION%.zip || exit /b !errorlevel!
187185
188-
- name: Install PCRE
189-
if: steps.cache-pcre.outputs.cache-hit != 'true'
186+
- name: Install PCRE2
187+
if: steps.cache-pcre2.outputs.cache-hit != 'true'
190188
run: |
191189
@echo on
192-
7z x pcre-%PCRE_VERSION%.zip || exit /b !errorlevel!
193-
cd pcre-%PCRE_VERSION% || exit /b !errorlevel!
194-
git apply --ignore-space-change ..\externals\pcre.patch || exit /b !errorlevel!
195-
cmake . -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DPCRE_BUILD_PCRECPP=Off -DPCRE_BUILD_TESTS=Off -DPCRE_BUILD_PCREGREP=Off -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DCMAKE_COMPILE_WARNING_AS_ERROR=On || exit /b !errorlevel!
196-
nmake || exit /b !errorlevel!
197-
copy pcre.h ..\externals || exit /b !errorlevel!
198-
copy pcre.lib ..\externals\pcre64.lib || exit /b !errorlevel!
190+
7z x pcre2-%PCRE2_VERSION%.zip || exit /b !errorlevel!
191+
cd pcre2-%PCRE2_VERSION% || exit /b !errorlevel!
192+
cmake -S . -B build -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=Off -DBUILD_STATIC_LIBS=On -DPCRE2_SUPPORT_JIT=On -DPCRE2_BUILD_PCRE2GREP=Off -DPCRE2_BUILD_TESTS=Off || exit /b !errorlevel!
193+
cmake --build build || exit /b !errorlevel!
194+
cmake --install build --prefix pcre2-dist || exit /b !errorlevel!
195+
copy pcre2-dist\include\pcre2.h ..\externals || exit /b !errorlevel!
196+
copy pcre2-dist\lib\pcre2-8-static.lib ..\externals\pcre2-8.lib || exit /b !errorlevel!
199197
env:
200198
CL: /MP
201199

‎.github/workflows/clang-tidy.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
run: |
3636
sudo apt-get update
3737
sudo apt-get install -y cmake make
38-
sudo apt-get install -y libpcre3-dev
38+
sudo apt-get install -y libpcre2-dev
3939
sudo apt-get install -y libgl-dev # fixes missing dependency for Qt in CMake
4040
4141
- name: Install clang

‎.github/workflows/iwyu.yml‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
if: contains(matrix.image, 'debian')
4848
run: |
4949
apt-get update
50-
apt-get install -y cmake clang make libpcre3-dev
50+
apt-get install -y cmake clang make libpcre2-dev
5151
apt-get install -y libgl-dev # fixes missing dependency for Qt in CMake
5252
apt-get install -y iwyu
5353
@@ -56,7 +56,7 @@ jobs:
5656
run: |
5757
set -x
5858
pacman -Sy
59-
pacman -S cmake make clang pcre --noconfirm
59+
pacman -S cmake make clang pcre2 --noconfirm
6060
pacman -S libglvnd --noconfirm # fixes missing dependency for Qt in CMake
6161
pacman-key --init
6262
pacman-key --recv-key 3056513887B78AEB --keyserver keyserver.ubuntu.com
@@ -88,15 +88,15 @@ jobs:
8888
- name: Install missing software on OpenSUSE
8989
if: contains(matrix.image, 'opensuse')
9090
run: |
91-
zypper install -y cmake clang pcre-devel
91+
zypper install -y cmake clang pcre2-devel
9292
zypper install -y include-what-you-use-tools
9393
ln -s iwyu_tool.py /usr/bin/iwyu_tool
9494
9595
# coreutils contains "nproc"
9696
- name: Install missing software on macOS
9797
if: contains(matrix.os, 'macos')
9898
run: |
99-
brew install include-what-you-use pcre coreutils
99+
brew install include-what-you-use pcre2 coreutils
100100
# on Apple Silicon files are symlinked under /opt/homebrew/bin
101101
ln -s /opt/homebrew/bin/iwyu_tool.py /usr/local/bin/iwyu_tool
102102
@@ -206,7 +206,7 @@ jobs:
206206
- name: Install missing software
207207
run: |
208208
sudo apt-get update
209-
sudo apt-get install -y cmake make libpcre3-dev
209+
sudo apt-get install -y cmake make libpcre2-dev
210210
sudo apt-get install -y libgl-dev # missing dependency for using Qt in CMake
211211
212212
- name: Install clang

‎.github/workflows/release-windows.yml‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ jobs:
2626

2727
env:
2828
PYTHON_VERSION: 3.14
29-
# see https://www.pcre.org/original/changelog.txt
30-
PCRE_VERSION: 8.45
29+
# see https://github.com/PCRE2Project/pcre2/blob/master/ChangeLog
30+
PCRE2_VERSION: 10.49
3131
QT_VERSION: 6.10.0
3232
BOOST_MINOR_VERSION: 89
3333

@@ -45,20 +45,20 @@ jobs:
4545
- name: Set up Visual Studio environment
4646
uses: ilammy/msvc-dev-cmd@v1
4747

48-
- name: Download PCRE
48+
- name: Download PCRE2
4949
run: |
50-
curl -fsSL https://github.com/pfultz2/pcre/archive/refs/tags/%PCRE_VERSION%.zip -o pcre-%PCRE_VERSION%.zip || exit /b !errorlevel!
50+
curl -fsSL https://github.com/PCRE2Project/pcre2/releases/download/pcre2-%PCRE2_VERSION%/pcre2-%PCRE2_VERSION%.zip -o pcre2-%PCRE2_VERSION%.zip || exit /b !errorlevel!
5151
52-
- name: Install PCRE
52+
- name: Install PCRE2
5353
run: |
5454
@echo on
55-
7z x pcre-%PCRE_VERSION%.zip || exit /b !errorlevel!
56-
cd pcre-%PCRE_VERSION% || exit /b !errorlevel!
57-
git apply --ignore-space-change ..\externals\pcre.patch || exit /b !errorlevel!
58-
cmake . -A x64 -DPCRE_BUILD_PCRECPP=OFF -DPCRE_BUILD_PCREGREP=OFF -DPCRE_BUILD_TESTS=OFF -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DCMAKE_COMPILE_WARNING_AS_ERROR=On || exit /b !errorlevel!
59-
msbuild -m PCRE.slnx -p:Configuration=Release -p:Platform=x64 || exit /b !errorlevel!
60-
copy pcre.h ..\externals || exit /b !errorlevel!
61-
copy Release\pcre.lib ..\externals\pcre64.lib || exit /b !errorlevel!
55+
7z x pcre2-%PCRE2_VERSION%.zip || exit /b !errorlevel!
56+
cd pcre2-%PCRE2_VERSION% || exit /b !errorlevel!
57+
cmake -S . -B build -A x64 -DBUILD_SHARED_LIBS=OFF -DBUILD_STATIC_LIBS=ON -DPCRE2_SUPPORT_JIT=ON -DPCRE2_BUILD_PCRE2GREP=OFF -DPCRE2_BUILD_TESTS=OFF || exit /b !errorlevel!
58+
cmake --build build --config Release || exit /b !errorlevel!
59+
cmake --install build --config Release --prefix pcre2-dist || exit /b !errorlevel!
60+
copy pcre2-dist\include\pcre2.h ..\externals || exit /b !errorlevel!
61+
copy pcre2-dist\lib\pcre2-8-static.lib ..\externals\pcre2-8.lib || exit /b !errorlevel!
6262
6363
- name: Download Boost
6464
run: |

‎.github/workflows/sanitizers.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868
- name: Install missing software on ubuntu
6969
run: |
7070
sudo apt-get update
71-
sudo apt-get install -y cmake make libpcre3-dev libboost-container-dev libxml2-utils
71+
sudo apt-get install -y cmake make libpcre2-dev libboost-container-dev libxml2-utils
7272
sudo apt-get install -y libcups2-dev # required for Qt6PrintSupport in CMake since Qt 6.7.3
7373
7474
- name: Install clang

‎.gitignore‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,6 @@ stage
126126
# ccache folder in CI
127127
/.ccache
128128

129-
# PCRE Windows files
130-
/externals/pcre.h
131-
/externals/pcre64.lib
129+
# PCRE2 Windows files
130+
/externals/pcre2.h
131+
/externals/pcre2-8.lib

‎Makefile‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,16 @@ ifeq (g++, $(findstring g++,$(CXX)))
140140
endif
141141
override CXXFLAGS += -std=c++11
142142
ifeq ($(HAVE_RULES),yes)
143-
PCRE_CONFIG = $(shell which pcre-config)
143+
PCRE_CONFIG = $(shell which pcre2-config)
144144
ifeq ($(PCRE_CONFIG),)
145-
$(error Did not find pcre-config)
145+
$(error Did not find pcre2-config)
146146
endif
147147
override CXXFLAGS += $(shell $(PCRE_CONFIG) --cflags)
148148
override CPPFLAGS += -DHAVE_RULES
149149
ifdef LIBS
150-
LIBS += $(shell $(PCRE_CONFIG) --libs)
150+
LIBS += $(shell $(PCRE_CONFIG) --libs8)
151151
else
152-
LIBS=$(shell $(PCRE_CONFIG) --libs)
152+
LIBS=$(shell $(PCRE_CONFIG) --libs8)
153153
endif
154154
else ifneq ($(HAVE_RULES),)
155155
$(error invalid HAVE_RULES value '$(HAVE_RULES)')

‎build-pcre.txt‎

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
PCRE is a library that is used by the optional "rules" feature for the command
2-
line version of cppcheck. It is readily available on Linux and Mac OS X, but
1+
PCRE2 is a library that is used by the optional "rules" feature for the command
2+
line version of cppcheck. It is readily available on Linux and macOS, but
33
must be obtained separately for Windows.
44

55
Build instructions
@@ -10,54 +10,37 @@ Windows
1010

1111
Visual Studio
1212

13-
To build PCRE, download the source code from www.pcre.org and
14-
CMake (https://cmake.org/download/). We assume you use Visual Studio 2015 -
15-
otherwise adapt the commands for your version.
13+
Download the PCRE2 source code from https://github.com/PCRE2Project/pcre2/releases
14+
and CMake (https://cmake.org/download/). Then build a static library from a
15+
Visual Studio developer command prompt:
1616

17-
VS Solution file
18-
cmake . -G "Visual Studio 14 2015"
19-
Open PCRE.sln with VS IDE or via cmd:
20-
call "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat" x86
21-
MSBuild PCRE.sln /target:Build /property:Configuration="Release"
17+
cmake -S . -B build -A x64 -DBUILD_SHARED_LIBS=OFF -DBUILD_STATIC_LIBS=ON -DPCRE2_SUPPORT_JIT=ON -DPCRE2_BUILD_PCRE2GREP=OFF -DPCRE2_BUILD_TESTS=OFF
18+
cmake --build build --config Release
19+
cmake --install build --config Release --prefix pcre2-dist
2220

23-
For 64-bit target: cmake . -G "Visual Studio 14 2015 Win64"
24-
25-
or using NMake
26-
call "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat" x86
27-
cmake . -G "NMake Makefiles"
28-
nmake
29-
30-
or using MSYS
31-
cmake . -G "MSYS Makefiles"
32-
make
21+
Copy pcre2-dist\include\pcre2.h and pcre2-dist\lib\pcre2-8-static.lib (renamed to
22+
pcre2-8.lib) into the /externals directory and select the "Release-PCRE" or
23+
"Debug-PCRE" configuration in cppcheck.sln.
3324

3425

3526
Linux
3627
-----
3728

3829
The normal Makefile should work.
3930

40-
Install PCRE on Ubuntu might be needed:
41-
sudo apt-get install libpcre3 libpcre3-dev
31+
Install PCRE2 on Debian/Ubuntu might be needed:
32+
sudo apt-get install libpcre2-dev
4233

4334

4435
Mac OSX
4536
-------
4637

47-
Install PCRE:
48-
49-
homebre
50-
brew install pcre
51-
52-
or macport
53-
sudo port install pcre
54-
55-
Ensure /path/to/pcre.h is in CXXFLAGS, e.g:
38+
Install PCRE2:
5639

57-
for homebrew
58-
export CXXFLAGS=${CXXFLAGS}:/usr/local/include
40+
homebrew
41+
brew install pcre2
5942

60-
or macport
61-
export CXXFLAGS=${CXXFLAGS}:/opt/local/include
43+
or macports
44+
sudo port install pcre2
6245

63-
Or for MSVC copy pcre.lib and pcre.h in /externals directory.
46+
The Makefile uses pcre2-config to find the include and library paths.

0 commit comments

Comments
 (0)