]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Support POSIX regular expression support using PCRE in CMake builds.
authorAndres Mejia <amejia004@gmail.com>
Thu, 31 Jan 2013 23:39:39 +0000 (18:39 -0500)
committerAndres Mejia <amejia004@gmail.com>
Thu, 31 Jan 2013 23:39:39 +0000 (18:39 -0500)
This change is mainly meant for Windows regex support, where PCRE Windows development is much
more active than development of the regex library found in the GNUWin32 packages. I found that
the latest release of PCRE built right out of the box, unlike the GNUWin32 regex library released
6 years ago which failed to build from source for me using the mingw toolchain.

CMakeLists.txt
build/cmake/config.h.in
tar/bsdtar.c
tar/bsdtar.h
tar/subst.c
tar/util.c

index 0c8bf8122992240ec8159af81665926edfaf320f..6a77ff5139b431039e752b14317a1de21dbd2a96 100644 (file)
@@ -150,6 +150,7 @@ OPTION(ENABLE_CPIO_SHARED "Enable dynamic build of cpio" FALSE)
 OPTION(ENABLE_XATTR "Enable extended attribute support" ON)
 OPTION(ENABLE_ACL "Enable ACL support" ON)
 OPTION(ENABLE_ICONV "Enable iconv support" ON)
+OPTION(ENABLE_PCREPOSIX "Enable POSIX regular expression support using PCRE" OFF)
 OPTION(ENABLE_TEST "Enable unit and regression tests" ON)
 
 IF(ENABLE_TEST)
@@ -868,50 +869,107 @@ ELSE(LIBXML2_FOUND)
 ENDIF(LIBXML2_FOUND)
 MARK_AS_ADVANCED(CLEAR LIBXML2_INCLUDE_DIR)
 MARK_AS_ADVANCED(CLEAR LIBXML2_LIBRARIES)
+
 #
-# Find Libregex
+# POSIX Regular Expression support
 #
-FIND_PATH(REGEX_INCLUDE_DIR regex.h)
-IF(REGEX_INCLUDE_DIR)
-  CHECK_FUNCTION_EXISTS_GLIBC(regcomp HAVE_REGCOMP_LIBC)
+IF(ENABLE_PCREPOSIX)
   #
-  # If libc does not provide regex, find libregex.
+  # If requested, try finding library for PCREPOSIX
   #
-  IF(NOT HAVE_REGCOMP_LIBC)
-    CMAKE_PUSH_CHECK_STATE()   # Save the state of the variables
-    FIND_LIBRARY(REGEX_LIBRARY regex)
-    IF(REGEX_LIBRARY)
-      SET(CMAKE_REQUIRED_LIBRARIES ${REGEX_LIBRARY})
-      CHECK_FUNCTION_EXISTS_GLIBC(regcomp HAVE_REGCOMP_LIBREGEX)
-      IF(HAVE_REGCOMP_LIBREGEX)
-        LIST(APPEND ADDITIONAL_LIBS ${REGEX_LIBRARY})
-        #
-        # If regex.h is not found, retry looking for regex.h at
-        # REGEX_INCLUDE_DIR
-        #
-        IF(NOT HAVE_REGEX_H)
-          UNSET(HAVE_REGEX_H CACHE)
-          INCLUDE_DIRECTORIES(${REGEX_INCLUDE_DIR})
-          SET(CMAKE_REQUIRED_INCLUDES ${REGEX_INCLUDE_DIR})
-          LA_CHECK_INCLUDE_FILE("regex.h" HAVE_REGEX_H)
-        ENDIF(NOT HAVE_REGEX_H)
-        # Test if a macro is needed for the library.
-        TRY_MACRO_FOR_LIBRARY(
-          "${REGEX_INCLUDE_DIR}" "${REGEX_LIBRARY}"
-          COMPILES
-          "#include <stddef.h>\n#include <regex.h>\nint main() {regex_t r;return regcomp(&r, \"\", 0);}"
-          "USE_REGEX_DLL;USE_REGEX_STATIC")
-        IF(USE_REGEX_DLL)
-          ADD_DEFINITIONS(-DUSE_REGEX_DLL)
-        ELSEIF(USE_REGEX_STATIC)
-          ADD_DEFINITIONS(-DUSE_REGEX_STATIC)
-        ENDIF(USE_REGEX_DLL)
-      ENDIF(HAVE_REGCOMP_LIBREGEX)
-    ENDIF(REGEX_LIBRARY)
-    CMAKE_POP_CHECK_STATE()    # Restore the state of the variables
-  ENDIF(NOT HAVE_REGCOMP_LIBC)
-ENDIF(REGEX_INCLUDE_DIR)
+  IF (PCREPOSIX_INCLUDE_DIRS)
+    # Already in cache, be silent
+    SET(PCREPOSIX_FIND_QUIETLY TRUE)
+  ENDIF (PCREPOSIX_INCLUDE_DIRS)
+
+  FIND_PATH(PCREPOSIX_INCLUDE_DIR pcreposix.h)
+
+  SET(PCREPOSIX_NAMES pcreposix)
+  FIND_LIBRARY(PCREPOSIX_LIBRARY NAMES ${PCREPOSIX_NAMES} )
+
+  # handle the QUIETLY and REQUIRED arguments and set PCREPOSIX_FOUND to TRUE if 
+  # all listed variables are TRUE
+  INCLUDE(FindPackageHandleStandardArgs)
+  FIND_PACKAGE_HANDLE_STANDARD_ARGS(PCREPOSIX DEFAULT_MSG PCREPOSIX_LIBRARY PCREPOSIX_INCLUDE_DIR)
 
+  IF(PCREPOSIX_FOUND)
+    SET( PCREPOSIX_LIBRARIES ${PCREPOSIX_LIBRARY} )
+    SET( PCREPOSIX_INCLUDE_DIRS ${PCREPOSIX_INCLUDE_DIR} )
+
+    IF(PCREPOSIX_LIBRARY)
+      SET(CMAKE_REQUIRED_LIBRARIES ${PCREPOSIX_LIBRARY})
+       ENDIF(PCREPOSIX_LIBRARY)
+
+    IF(PCREPOSIX_INCLUDE_DIR)
+      INCLUDE_DIRECTORIES(${PCREPOSIX_INCLUDE_DIR})
+      SET(CMAKE_REQUIRED_INCLUDES ${PCREPOSIX_INCLUDE_DIR})
+    ENDIF(PCREPOSIX_INCLUDE_DIR)
+       LA_CHECK_INCLUDE_FILE("pcreposix.h" HAVE_PCREPOSIX_H)
+
+    # Test if a macro is needed for the library.
+    TRY_MACRO_FOR_LIBRARY(
+      "${PCREPOSIX_INCLUDE_DIR}" "${PCREPOSIX_LIBRARY}"
+      COMPILES
+      "#include <stddef.h>\n#include <pcreposix.h>\nint main() {regex_t r;return regcomp(&r, \"\", 0);}"
+      "PCRE_STATIC")
+    IF(PCRE_STATIC)
+         # TODO: Need to link against libpcre if static linking
+      ADD_DEFINITIONS(-DPCRE_STATIC)
+    ENDIF(PCRE_STATIC)
+  ELSE(PCREPOSIX_FOUND)
+    SET( PCREPOSIX_LIBRARIES )
+    SET( PCREPOSIX_INCLUDE_DIRS )
+  ENDIF(PCREPOSIX_FOUND)
+
+  MARK_AS_ADVANCED( PCREPOSIX_LIBRARIES PCREPOSIX_INCLUDE_DIRS )
+ENDIF(ENABLE_PCREPOSIX)
+
+IF(NOT PCREPOSIX_FOUND)
+  #
+  # If PCREPOSIX is not found or not requested, try using regex
+  # from libc or libregex
+  #
+  FIND_PATH(REGEX_INCLUDE_DIR regex.h)
+  IF(REGEX_INCLUDE_DIR)
+    CHECK_FUNCTION_EXISTS_GLIBC(regcomp HAVE_REGCOMP_LIBC)
+    #
+    # If libc does not provide regex, find libregex.
+    #
+    IF(NOT HAVE_REGCOMP_LIBC)
+      CMAKE_PUSH_CHECK_STATE() # Save the state of the variables
+      FIND_LIBRARY(REGEX_LIBRARY regex)
+      IF(REGEX_LIBRARY)
+        SET(CMAKE_REQUIRED_LIBRARIES ${REGEX_LIBRARY})
+        CHECK_FUNCTION_EXISTS_GLIBC(regcomp HAVE_REGCOMP_LIBREGEX)
+        IF(HAVE_REGCOMP_LIBREGEX)
+          LIST(APPEND ADDITIONAL_LIBS ${REGEX_LIBRARY})
+          #
+          # If regex.h is not found, retry looking for regex.h at
+          # REGEX_INCLUDE_DIR
+          #
+          IF(NOT HAVE_REGEX_H)
+            UNSET(HAVE_REGEX_H CACHE)
+            INCLUDE_DIRECTORIES(${REGEX_INCLUDE_DIR})
+            SET(CMAKE_REQUIRED_INCLUDES ${REGEX_INCLUDE_DIR})
+            LA_CHECK_INCLUDE_FILE("regex.h" HAVE_REGEX_H)
+          ENDIF(NOT HAVE_REGEX_H)
+          # Test if a macro is needed for the library.
+          TRY_MACRO_FOR_LIBRARY(
+            "${REGEX_INCLUDE_DIR}" "${REGEX_LIBRARY}"
+            COMPILES
+            "#include <stddef.h>\n#include <regex.h>\nint main() {regex_t r;return regcomp(&r, \"\", 0);}"
+            "USE_REGEX_DLL;USE_REGEX_STATIC")
+          IF(USE_REGEX_DLL)
+            ADD_DEFINITIONS(-DUSE_REGEX_DLL)
+          ELSEIF(USE_REGEX_STATIC)
+            ADD_DEFINITIONS(-DUSE_REGEX_STATIC)
+          ENDIF(USE_REGEX_DLL)
+        ENDIF(HAVE_REGCOMP_LIBREGEX)
+      ENDIF(REGEX_LIBRARY)
+      CMAKE_POP_CHECK_STATE()  # Restore the state of the variables
+    ENDIF(NOT HAVE_REGCOMP_LIBC)
+  ENDIF(REGEX_INCLUDE_DIR)
+ENDIF(NOT PCREPOSIX_FOUND)
 #
 # Check functions
 #
index ab2ef2f187dd90d097037bbcd6d606071f6bd6d3..77b8d3bd2b02f35ffdb822af6a66ec8eab1bcede 100644 (file)
@@ -706,6 +706,9 @@ typedef uint64_t uintmax_t;
 /* Define to 1 if you have the <paths.h> header file. */
 #cmakedefine HAVE_PATHS_H 1
 
+/* Define to 1 if you have the <pcreposix.h> header file. */
+#cmakedefine HAVE_PCREPOSIX_H 1
+
 /* Define to 1 if you have the `pipe' function. */
 #cmakedefine HAVE_PIPE 1
 
index 4d421dfbfadc0948f8b5fd161d6576c1f768567b..47267579f0c4d0747785cc610121b1fd7d7654b9 100644 (file)
@@ -570,7 +570,7 @@ main(int argc, char **argv)
                        bsdtar->extract_flags |= ARCHIVE_EXTRACT_SPARSE;
                        break;
                case 's': /* NetBSD pax-as-tar */
-#if HAVE_REGEX_H
+#if defined(HAVE_REGEX_H) || defined(HAVE_PCREPOSIX_H)
                        add_substitution(bsdtar, bsdtar->argument);
 #else
                        lafe_warnc(0,
@@ -806,7 +806,7 @@ main(int argc, char **argv)
        }
 
        archive_match_free(bsdtar->matching);
-#if HAVE_REGEX_H
+#if defined(HAVE_REGEX_H) || defined(HAVE_PCREPOSIX_H)
        cleanup_substitution(bsdtar);
 #endif
        cset_free(bsdtar->cset);
index a03d05ad60718e98fbebcb2c8ab1d81da01c1487..637e1b9d4feee63a51aeb9c674f3a6469aacd73c 100644 (file)
@@ -173,7 +173,7 @@ void        tar_mode_x(struct bsdtar *bsdtar);
 void   usage(void);
 int    yes(const char *fmt, ...);
 
-#if HAVE_REGEX_H
+#if defined(HAVE_REGEX_H) || defined(HAVE_PCREPOSIX_H)
 void   add_substitution(struct bsdtar *, const char *);
 int    apply_substitution(struct bsdtar *, const char *, char **, int, int);
 void   cleanup_substitution(struct bsdtar *);
index 0ef95b917d5d7119d2c33ba43d14f09d929e18c2..fd6f8e222c6a79c87f37335340650e9d8ff7e621 100644 (file)
 #include "bsdtar_platform.h"
 __FBSDID("$FreeBSD: src/usr.bin/tar/subst.c,v 1.4 2008/06/15 10:08:16 kientzle Exp $");
 
-#if HAVE_REGEX_H
+#if defined(HAVE_REGEX_H) || defined(HAVE_PCREPOSIX_H)
 #include "bsdtar.h"
 
 #include <errno.h>
+#ifdef HAVE_PCREPOSIX_H
+#include <pcreposix.h>
+#else
 #include <regex.h>
+#endif
 #include <stdlib.h>
 #include <string.h>
 
@@ -317,4 +321,4 @@ cleanup_substitution(struct bsdtar *bsdtar)
        }
        free(subst);
 }
-#endif /* HAVE_REGEX_H */
+#endif /* defined(HAVE_REGEX_H) || defined(HAVE_PCREPOSIX_H) */
index ff4cd4fc6f0f789e209ba3910f731df086790ab9..b1b9b93d0e9366122316db1d24d98b972a768fc9 100644 (file)
@@ -382,7 +382,7 @@ int
 edit_pathname(struct bsdtar *bsdtar, struct archive_entry *entry)
 {
        const char *name = archive_entry_pathname(entry);
-#if HAVE_REGEX_H
+#if defined(HAVE_REGEX_H) || defined(HAVE_PCREPOSIX_H)
        char *subst_name;
        int r;