aboutsummaryrefslogtreecommitdiffstats
path: root/cmake/modules/FindPCRE2.cmake
blob: fb9b827d2486856cddecef3e451bab6a3020cbe1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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 USE_REPOSITORY)
	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)