Simplified building and using PCRE2 in a cmake context
  • CMake 82.2%
  • C++ 17.8%
Find a file
2025-09-03 13:08:58 +02:00
test Windows 2025-09-03 11:37:46 +02:00
.clang-format First check in 2025-09-03 10:46:07 +02:00
.gitignore First check in 2025-09-03 10:46:07 +02:00
CMakeLists.txt Added some original tests 2025-09-03 13:08:58 +02:00
pcre2s-config.cmake.in More cmake config files 2025-09-03 11:00:56 +02:00
README.md First check in 2025-09-03 10:46:07 +02:00

PCRE2 for cmake users

This CMakeLists.txt file contains all you need to embed pcre2 into your own cmake based project.

The original code of pcre2 comes with cmake files, but they do not work as expected, at least not for me. I tried many options to work around this but in the end, this is what works for me.

Usage

The regular steps for installing cmake based libraries:

git clone https://forge.hekkelman.net/maarten/pcre2s
cd pcre2s
cmake -B build
cmake --build build
sudo cmake --install build

Then, use it like this

find_package(pcre2s REQUIRED)
add_executable(use-pcre2s ${CMAKE_CURRENT_SOURCE_DIR}/use-pcre2s.c)
target_link_libraries(use-pcre2s PRIVATE pcre2s::pcre2)

Of course, using CPM makes life even easier.