summaryrefslogtreecommitdiff
path: root/src/CMakeLists.txt
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2019-02-17 21:51:34 +0000
committerEdward Thomson <ethomson@edwardthomson.com>2019-05-19 11:12:13 +0100
commitc6e48fef4382ed9fc8113733fb6e2b960506728d (patch)
tree6be36351fd5a53553966e755886d0f3d5d2df2ae /src/CMakeLists.txt
parent099029853b4ffdd3bdafe4fae82a621665ada248 (diff)
downloadlibgit2-c6e48fef4382ed9fc8113733fb6e2b960506728d.tar.gz
regex: allow regex selection in cmake
Users can now select which regex implementation they want to use: one of the system `regcomp_l`, the system PCRE, the builtin PCRE or the system's `regcomp`. By default the system `regcomp_l` will be used if it exists, otherwise the system PCRE will be used. If neither of those exist, then the builtin PCRE implementation will be used. The system's `regcomp` is not used by default due to problems with locales.
Diffstat (limited to 'src/CMakeLists.txt')
-rw-r--r--src/CMakeLists.txt49
1 files changed, 28 insertions, 21 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4cdfe23dc..637949512 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,14 +289,38 @@ ELSE()
MESSAGE(FATAL_ERROR "Asked for unknown SHA1 backend ${SHA1_BACKEND}")
ENDIF()
-# Include PCRE and its POSIX regex compatibility layer when it is required
-IF (HAVE_REGCOMP_L)
+# Specify regular expression implementation
+IF(REGEX STREQUAL "")
+ CHECK_SYMBOL_EXISTS(regcomp_l "regex.h;xlocale.h" HAVE_REGCOMP_L)
+ CHECK_SYMBOL_EXISTS(pcre_regcomp "pcreposix.h" HAVE_PCRE)
+
+ IF(HAVE_REGCOMP_L)
+ SET(REGEX "regcomp_l")
+ ELSEIF(HAVE_PCRE)
+ SET(REGEX "pcre")
+ ELSE()
+ SET(REGEX "builtin")
+ ENDIF()
+ENDIF()
+
+IF(REGEX STREQUAL "regcomp_l")
ADD_FEATURE_INFO(regex ON "using system regcomp_l")
-ELSE()
+ SET(GIT_REGEX_REGCOMP_L 1)
+ELSEIF(REGEX STREQUAL "pcre")
+ ADD_FEATURE_INFO(regex ON "using system PCRE")
+ SET(GIT_REGEX_PCRE 1)
+ELSEIF(REGEX STREQUAL "regcomp")
+ ADD_FEATURE_INFO(regex ON "using system regcomp")
+ SET(GIT_REGEX_REGCOMP 1)
+ELSEIF(REGEX STREQUAL "builtin")
+ ADD_FEATURE_INFO(regex ON "using bundled PCRE")
+ SET(GIT_REGEX_PCRE 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>)
- ADD_FEATURE_INFO(regex ON "using bundled PCRE")
+ELSE()
+ MESSAGE(FATAL_ERROR "The REGEX option provided is not supported")
ENDIF()
# Optional external dependency: http-parser