summaryrefslogtreecommitdiff
path: root/src/CMakeLists.txt
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2019-05-21 14:59:55 +0200
committerGitHub <noreply@github.com>2019-05-21 14:59:55 +0200
commit3d9e82fdd5619985b56ca25fb1f89de3dfabc029 (patch)
tree689c3f2a148574fdaeb48f8d04648707c61230ed /src/CMakeLists.txt
parent954f5357282233ecdfea226c819f3f3884949cdb (diff)
parentafb04a95af939295d9baebac5bea72c070001d9e (diff)
downloadlibgit2-3d9e82fdd5619985b56ca25fb1f89de3dfabc029.tar.gz
Merge pull request #4935 from libgit2/ethomson/pcre
Use PCRE for our fallback regex engine when regcomp_l is unavailable
Diffstat (limited to 'src/CMakeLists.txt')
-rw-r--r--src/CMakeLists.txt67
1 files changed, 50 insertions, 17 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 00021b828..bf51c45bd 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -48,23 +48,6 @@ IF (ENABLE_TRACE STREQUAL "ON")
ENDIF()
ADD_FEATURE_INFO(tracing GIT_TRACE "tracing support")
-# Use `regcomp_l` if available
-CHECK_SYMBOL_EXISTS(regcomp_l "regex.h;xlocale.h" HAVE_REGCOMP_L)
-IF (HAVE_REGCOMP_L)
- SET(GIT_USE_REGCOMP_L 1)
-ENDIF ()
-
-# Otherwise, we either want to use system's `regcomp` or our
-# bundled regcomp code, if system doesn't provide `regcomp`.
-IF(NOT HAVE_REGCOMP_L)
- CHECK_FUNCTION_EXISTS(regcomp HAVE_REGCOMP)
- IF(NOT HAVE_REGCOMP)
- ADD_SUBDIRECTORY("${libgit2_SOURCE_DIR}/deps/regex" "${libgit2_BINARY_DIR}/deps/regex")
- LIST(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/regex")
- LIST(APPEND LIBGIT2_OBJECTS $<TARGET_OBJECTS:regex>)
- ENDIF()
-ENDIF()
-
CHECK_FUNCTION_EXISTS(futimens HAVE_FUTIMENS)
IF (HAVE_FUTIMENS)
SET(GIT_USE_FUTIMENS 1)
@@ -306,6 +289,56 @@ ELSE()
MESSAGE(FATAL_ERROR "Asked for unknown SHA1 backend ${SHA1_BACKEND}")
ENDIF()
+# Specify regular expression implementation
+FIND_PACKAGE(PCRE)
+
+IF(REGEX_BACKEND STREQUAL "")
+ CHECK_SYMBOL_EXISTS(regcomp_l "regex.h;xlocale.h" HAVE_REGCOMP_L)
+
+ IF(HAVE_REGCOMP_L)
+ SET(REGEX_BACKEND "regcomp_l")
+ ELSEIF(PCRE_FOUND)
+ SET(REGEX_BACKEND "pcre")
+ ELSE()
+ SET(REGEX_BACKEND "builtin")
+ ENDIF()
+ENDIF()
+
+IF(REGEX_BACKEND STREQUAL "regcomp_l")
+ ADD_FEATURE_INFO(regex ON "using system regcomp_l")
+ SET(GIT_REGEX_REGCOMP_L 1)
+ELSEIF(REGEX_BACKEND STREQUAL "pcre2")
+ FIND_PACKAGE(PCRE2)
+
+ IF(NOT PCRE2_FOUND)
+ MESSAGE(FATAL_ERROR "PCRE2 support was requested but not found")
+ ENDIF()
+
+ ADD_FEATURE_INFO(regex ON "using system PCRE2")
+ SET(GIT_REGEX_PCRE2 1)
+
+ LIST(APPEND LIBGIT2_SYSTEM_INCLUDES ${PCRE2_INCLUDE_DIRS})
+ LIST(APPEND LIBGIT2_LIBS ${PCRE2_LIBRARIES})
+ELSEIF(REGEX_BACKEND STREQUAL "pcre")
+ ADD_FEATURE_INFO(regex ON "using system PCRE")
+ SET(GIT_REGEX_PCRE 1)
+
+ LIST(APPEND LIBGIT2_SYSTEM_INCLUDES ${PCRE_INCLUDE_DIRS})
+ LIST(APPEND LIBGIT2_LIBS ${PCRE_LIBRARIES})
+ELSEIF(REGEX_BACKEND STREQUAL "regcomp")
+ ADD_FEATURE_INFO(regex ON "using system regcomp")
+ SET(GIT_REGEX_REGCOMP 1)
+ELSEIF(REGEX_BACKEND STREQUAL "builtin")
+ ADD_FEATURE_INFO(regex ON "using bundled PCRE")
+ SET(GIT_REGEX_BUILTIN 1)
+
+ ADD_SUBDIRECTORY("${libgit2_SOURCE_DIR}/deps/pcre" "${libgit2_BINARY_DIR}/deps/pcre")
+ LIST(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/pcre")
+ LIST(APPEND LIBGIT2_OBJECTS $<TARGET_OBJECTS:pcre>)
+ELSE()
+ MESSAGE(FATAL_ERROR "The REGEX_BACKEND option provided is not supported")
+ENDIF()
+
# Optional external dependency: http-parser
FIND_PACKAGE(HTTP_Parser)
IF (USE_EXT_HTTP_PARSER AND HTTP_PARSER_FOUND AND HTTP_PARSER_VERSION_MAJOR EQUAL 2)