Skip to content

Commit ce6d624

Browse files
committed
regex: optionally use PCRE2
Use PCRE2 and its POSIX compatibility layer if requested by the user. Although PCRE2 is adequate for our needs, the PCRE2 POSIX layer as installed on Debian and Ubuntu systems is broken, so we do not opt-in to it by default to avoid breaking users on those platforms.
1 parent 69ecdad commit ce6d624

File tree

5 files changed

+55
-2
lines changed

5 files changed

+55
-2
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ OPTION(DEBUG_POOL "Enable debug pool allocator" OFF)
6565
OPTION(ENABLE_WERROR "Enable compilation with -Werror" OFF)
6666
OPTION(USE_BUNDLED_ZLIB "Use the bundled version of zlib" OFF)
6767
OPTION(DEPRECATE_HARD "Do not include deprecated functions in the library" OFF)
68-
SET(REGEX "" CACHE STRING "Regular expression implementation. One of regcomp_l, pcre, regcomp, or builtin.")
68+
SET(REGEX "" CACHE STRING "Regular expression implementation. One of regcomp_l, pcre2, pcre, regcomp, or builtin.")
6969

7070
IF (UNIX AND NOT APPLE)
7171
OPTION(ENABLE_REPRODUCIBLE_BUILDS "Enable reproducible builds" OFF)

cmake/Modules/FindPCRE2.cmake

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright (C) 2007-2009 LuaDist.
2+
# Created by Peter Kapec <kapecp@gmail.com>
3+
# Redistribution and use of this file is allowed according to the terms of the MIT license.
4+
# For details see the COPYRIGHT file distributed with LuaDist.
5+
# Note:
6+
# Searching headers and libraries is very simple and is NOT as powerful as scripts
7+
# distributed with CMake, because LuaDist defines directories to search for.
8+
# Everyone is encouraged to contact the author with improvements. Maybe this file
9+
# becomes part of CMake distribution sometimes.
10+
11+
# - Find pcre
12+
# Find the native PCRE2 headers and libraries.
13+
#
14+
# PCRE2_INCLUDE_DIRS - where to find pcre.h, etc.
15+
# PCRE2_LIBRARIES - List of libraries when using pcre.
16+
# PCRE2_FOUND - True if pcre found.
17+
18+
# Look for the header file.
19+
FIND_PATH(PCRE2_INCLUDE_DIR NAMES pcre2posix.h)
20+
21+
# Look for the library.
22+
FIND_LIBRARY(PCRE2_LIBRARY NAMES pcre2-8)
23+
FIND_LIBRARY(PCRE2_POSIX_LIBRARY NAMES pcre2-posix)
24+
25+
# Handle the QUIETLY and REQUIRED arguments and set PCRE2_FOUND to TRUE if all listed variables are TRUE.
26+
INCLUDE(FindPackageHandleStandardArgs)
27+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(PCRE2 DEFAULT_MSG PCRE2_LIBRARY PCRE2_POSIX_LIBRARY PCRE2_INCLUDE_DIR)
28+
29+
# Copy the results to the output variables.
30+
IF(PCRE2_FOUND)
31+
SET(PCRE2_LIBRARIES ${PCRE2_LIBRARY} ${PCRE2_POSIX_LIBRARY})
32+
SET(PCRE2_INCLUDE_DIRS ${PCRE2_INCLUDE_DIR})
33+
ELSE(PCRE2_FOUND)
34+
SET(PCRE2_LIBRARIES)
35+
SET(PCRE2_INCLUDE_DIRS)
36+
ENDIF(PCRE2_FOUND)
37+
38+
MARK_AS_ADVANCED(PCRE2_INCLUDE_DIRS PCRE2_LIBRARIES)

src/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,18 @@ ENDIF()
307307
IF(REGEX STREQUAL "regcomp_l")
308308
ADD_FEATURE_INFO(regex ON "using system regcomp_l")
309309
SET(GIT_REGEX_REGCOMP_L 1)
310+
ELSEIF(REGEX STREQUAL "pcre2")
311+
FIND_PACKAGE(PCRE2)
312+
313+
IF(NOT PCRE2_FOUND)
314+
MESSAGE(FATAL_ERROR "PCRE2 support was requested but not found")
315+
ENDIF()
316+
317+
ADD_FEATURE_INFO(regex ON "using system PCRE2")
318+
SET(GIT_REGEX_PCRE2 1)
319+
320+
LIST(APPEND LIBGIT2_SYSTEM_INCLUDES ${PCRE2_INCLUDE_DIRS})
321+
LIST(APPEND LIBGIT2_LIBS ${PCRE2_LIBRARIES})
310322
ELSEIF(REGEX STREQUAL "pcre")
311323
ADD_FEATURE_INFO(regex ON "using system PCRE")
312324
SET(GIT_REGEX_PCRE 1)

src/features.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#cmakedefine GIT_REGEX_REGCOMP_L
2020
#cmakedefine GIT_REGEX_REGCOMP
2121
#cmakedefine GIT_REGEX_PCRE
22+
#cmakedefine GIT_REGEX_PCRE2
2223
#cmakedefine GIT_REGEX_BUILTIN 1
2324

2425
#cmakedefine GIT_SSH 1

src/posix_regex.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737

3838
#else
3939

40-
# ifdef GIT_REGEX_PCRE
40+
# if defined(GIT_REGEX_PCRE2)
41+
# include <pcre2posix.h>
42+
# elif defined(GIT_REGEX_PCRE)
4143
# include <pcreposix.h>
4244
# else
4345
# include <regex.h>

0 commit comments

Comments
 (0)