aboutsummaryrefslogtreecommitdiffstats
path: root/cmake/modules
diff options
context:
space:
mode:
authorJoão Valverde <j@v6e.pt>2021-10-15 18:34:33 +0100
committerJoão Valverde <j@v6e.pt>2021-11-14 21:00:59 +0000
commited8a02af172200c037a3ddf3d63eea9c2f587957 (patch)
treebf54b5e8115f7f4892165952a639981d3a0beb45 /cmake/modules
parent6630fd52608ca31350798567f9fafcb24532adc8 (diff)
dfilter: Add support for PCRE2
PCRE2 is the future of PCRE. The only advantage of GRegex is that it comes bundled with GLib, which is not an advantage at all. PCRE2 is widely available, the GRegex abstractions layer are not a good fit and abstract things that don't need abstracting or that we could handle better ourselves, there are open bugs (#12997) and maintenance is spotty at best. GRegex comes with many of the problems of bundled code, aggravated by the fact that it completely falls outside of our control.
Diffstat (limited to 'cmake/modules')
-rw-r--r--cmake/modules/FindPCRE2.cmake70
1 files changed, 70 insertions, 0 deletions
diff --git a/cmake/modules/FindPCRE2.cmake b/cmake/modules/FindPCRE2.cmake
new file mode 100644
index 0000000000..17c7b00c02
--- /dev/null
+++ b/cmake/modules/FindPCRE2.cmake
@@ -0,0 +1,70 @@
+#
+# - Find PCRE2 libraries
+#
+# PCRE2_INCLUDE_DIRS - where to find PCRE2 headers.
+# PCRE2_LIBRARIES - List of libraries when using PCRE2.
+# PCRE2_FOUND - True if PCRE2 is found.
+# PCRE2_DLL_DIR - (Windows) Path to the PCRE2 DLL
+# PCRE2_DLL - (Windows) Name of the PCRE2 DLL
+
+# Note that the "8" in "libpcre2-8" refers to "PCRE library version 2 with
+# support for 8-bit code units".
+
+include( FindWSWinLibs )
+FindWSWinLibs( "pcre2-.*" "PCRE2_HINTS" )
+
+if( NOT WIN32)
+ find_package(PkgConfig QUIET)
+ pkg_search_module(PC_PCRE2 QUIET "libpcre2-8")
+endif()
+
+find_path(PCRE2_INCLUDE_DIR
+ NAMES
+ pcre2.h
+ HINTS
+ ${PC_PCRE2_INCLUDE_DIRS}
+ ${PCRE2_HINTS}/include
+)
+
+find_library(PCRE2_LIBRARY
+ NAMES
+ "pcre2-8"
+ HINTS
+ ${PC_PCRE2_LIBRARY_DIRS}
+ ${PCRE2_HINTS}/lib
+)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(PCRE2
+ REQUIRED_VARS PCRE2_LIBRARY PCRE2_INCLUDE_DIR
+ VERSION_VAR PC_PCRE2_VERSION
+)
+
+if(PCRE2_FOUND)
+ set(PCRE2_LIBRARIES ${PCRE2_LIBRARY})
+ set(PCRE2_INCLUDE_DIRS ${PCRE2_INCLUDE_DIR})
+ if (WIN32)
+ set (PCRE2_DLL_DIR "${PCRE2_HINTS}/bin"
+ CACHE PATH "Path to PCRE2 DLL"
+ )
+ file(GLOB _pcre2_dll RELATIVE "${PCRE2_DLL_DIR}"
+ "${PCRE2_DLL_DIR}/pcre2-8*.dll"
+ )
+ set (PCRE2_DLL ${_pcre2_dll}
+ # We're storing filenames only. Should we use STRING instead?
+ CACHE FILEPATH "PCRE2 DLL file name"
+ )
+ file(GLOB _pcre2_pdb RELATIVE "${PCRE2_DLL_DIR}"
+ "${PCRE2_DLL_DIR}/pcre2-8*.pdb"
+ )
+ set (PCRE2_PDB ${_pcre2_pdb}
+ CACHE FILEPATH "PCRE2 PDB file name"
+ )
+ mark_as_advanced(PCRE2_DLL_DIR PCRE2_DLL PCRE2_PDB)
+ endif()
+ else()
+ set(PCRE2_LIBRARIES)
+ set(PCRE2_INCLUDE_DIRS)
+endif()
+
+mark_as_advanced(PCRE2_LIBRARIES PCRE2_INCLUDE_DIRS)