5
5
#
6
6
# Static vs. shared
7
7
# -----------------
8
- # To make use of the static library instead of the shared one, one needs
8
+ # To force using the static library instead of the shared one, one needs
9
9
# to set the variable PCRE2_USE_STATIC_LIBS to ON before calling find_package.
10
+ # If the variable is not set, the static library will be used if only that has
11
+ # been built, otherwise the shared library will be used.
12
+ #
13
+ # The following components are supported: 8BIT, 16BIT, 32BIT and POSIX.
14
+ # They used to be required but not anymore; all available targets will
15
+ # be defined regardless of the requested components.
10
16
# Example:
11
17
# set(PCRE2_USE_STATIC_LIBS ON)
12
- # find_package(PCRE2 CONFIG COMPONENTS 8BIT )
18
+ # find_package(PCRE2 CONFIG)
13
19
#
14
20
# This will define the following variables:
15
21
#
23
29
# PCRE2::32BIT - The 32 bit PCRE2 library.
24
30
# PCRE2::POSIX - The POSIX PCRE2 library.
25
31
26
- set (PCRE2_NON_STANDARD_LIB_PREFIX @NON_STANDARD_LIB_PREFIX@)
27
- set (PCRE2_NON_STANDARD_LIB_SUFFIX @NON_STANDARD_LIB_SUFFIX@)
28
- set (PCRE2_8BIT_NAME pcre2-8)
29
- set (PCRE2_16BIT_NAME pcre2-16)
30
- set (PCRE2_32BIT_NAME pcre2-32)
31
- set (PCRE2_POSIX_NAME pcre2-posix)
32
- find_path (PCRE2_INCLUDE_DIR NAMES pcre2.h DOC "PCRE2 include directory" )
33
- if (PCRE2_USE_STATIC_LIBS)
34
- if (MSVC )
35
- set (PCRE2_8BIT_NAME pcre2-8-static )
36
- set (PCRE2_16BIT_NAME pcre2-16-static )
37
- set (PCRE2_32BIT_NAME pcre2-32-static )
38
- set (PCRE2_POSIX_NAME pcre2-posix-static )
39
- endif ()
40
-
41
- set (PCRE2_PREFIX ${CMAKE_STATIC_LIBRARY_PREFIX} )
42
- set (PCRE2_SUFFIX ${CMAKE_STATIC_LIBRARY_SUFFIX} )
43
- else ()
44
- set (PCRE2_PREFIX ${CMAKE_SHARED_LIBRARY_PREFIX} )
45
- if (MINGW AND PCRE2_NON_STANDARD_LIB_PREFIX)
46
- set (PCRE2_PREFIX "" )
47
- endif ()
32
+ @PACKAGE_INIT@
48
33
49
- set (PCRE2_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX} )
50
- if (MINGW AND PCRE2_NON_STANDARD_LIB_SUFFIX)
51
- set (PCRE2_SUFFIX "-0.dll" )
52
- elseif (MSVC )
53
- set (PCRE2_SUFFIX ${CMAKE_STATIC_LIBRARY_SUFFIX} )
54
- endif ()
34
+ include (CMakeFindDependencyMacro)
35
+ if ("@REQUIRE_PTHREAD@" ) # REQUIRE_PTHREAD
36
+ find_dependency(Threads)
55
37
endif ()
56
- find_library (
57
- PCRE2_8BIT_LIBRARY
58
- NAMES ${PCRE2_PREFIX}${PCRE2_8BIT_NAME}${PCRE2_SUFFIX} ${PCRE2_PREFIX}${PCRE2_8BIT_NAME} d${PCRE2_SUFFIX}
59
- DOC "8 bit PCRE2 library"
60
- )
61
- find_library (
62
- PCRE2_16BIT_LIBRARY
63
- NAMES ${PCRE2_PREFIX}${PCRE2_16BIT_NAME}${PCRE2_SUFFIX} ${PCRE2_PREFIX}${PCRE2_16BIT_NAME} d${PCRE2_SUFFIX}
64
- DOC "16 bit PCRE2 library"
65
- )
66
- find_library (
67
- PCRE2_32BIT_LIBRARY
68
- NAMES ${PCRE2_PREFIX}${PCRE2_32BIT_NAME}${PCRE2_SUFFIX} ${PCRE2_PREFIX}${PCRE2_32BIT_NAME} d${PCRE2_SUFFIX}
69
- DOC "32 bit PCRE2 library"
70
- )
71
- find_library (
72
- PCRE2_POSIX_LIBRARY
73
- NAMES ${PCRE2_PREFIX}${PCRE2_POSIX_NAME}${PCRE2_SUFFIX} ${PCRE2_PREFIX}${PCRE2_POSIX_NAME} d${PCRE2_SUFFIX}
74
- DOC "8 bit POSIX PCRE2 library"
75
- )
76
- unset (PCRE2_NON_STANDARD_LIB_PREFIX)
77
- unset (PCRE2_NON_STANDARD_LIB_SUFFIX)
78
- unset (PCRE2_8BIT_NAME)
79
- unset (PCRE2_16BIT_NAME)
80
- unset (PCRE2_32BIT_NAME)
81
- unset (PCRE2_POSIX_NAME)
82
38
83
- # Set version
84
- if (PCRE2_INCLUDE_DIR)
85
- set (PCRE2_VERSION
"@PCRE2_MAJOR@.@[email protected] " )
86
- endif ()
39
+ include ("${CMAKE_CURRENT_LIST_DIR} /pcre2-targets.cmake" )
87
40
88
- # Which components have been found.
89
- if (PCRE2_8BIT_LIBRARY)
90
- set (PCRE2_8BIT_FOUND TRUE )
91
- endif ()
92
- if (PCRE2_16BIT_LIBRARY)
93
- set (PCRE2_16BIT_FOUND TRUE )
94
- endif ()
95
- if (PCRE2_32BIT_LIBRARY)
96
- set (PCRE2_32BIT_FOUND TRUE )
97
- endif ()
98
- if (PCRE2_POSIX_LIBRARY)
99
- set (PCRE2_POSIX_FOUND TRUE )
100
- endif ()
41
+ # Set version
42
+ set (PCRE2_VERSION
"@PCRE2_MAJOR@.@[email protected] " )
101
43
102
- # Check if at least one component has been specified.
103
- list (LENGTH PCRE2_FIND_COMPONENTS PCRE2_NCOMPONENTS)
104
- if (PCRE2_NCOMPONENTS LESS 1)
105
- message (FATAL_ERROR "No components have been specified. This is not allowed. Please, specify at least one component." )
106
- endif ()
107
- unset (PCRE2_NCOMPONENTS)
44
+ # Chooses the linkage of the library to expose in the
45
+ # unsuffixed edition of the target.
46
+ macro (_pcre2_add_component_target component target )
47
+ # If the static library exists and either PCRE2_USE_STATIC_LIBS
48
+ # is defined, or the dynamic library does not exist, use the static library.
49
+ if (NOT TARGET PCRE2::${component} )
50
+ if (TARGET pcre2::pcre2-${target} -static AND (PCRE2_USE_STATIC_LIBS OR NOT TARGET pcre2::pcre2-${target} -shared))
51
+ add_library (PCRE2::${component} ALIAS pcre2::pcre2-${target} -static )
52
+ set (PCRE2_${component} _FOUND TRUE )
53
+ # Otherwise use the dynamic library if it exists.
54
+ elseif (TARGET pcre2::pcre2-${target} -shared AND NOT PCRE2_USE_STATIC_LIBS)
55
+ add_library (PCRE2::${component} ALIAS pcre2::pcre2-${target} -shared)
56
+ set (PCRE2_${component} _FOUND TRUE )
57
+ endif ()
58
+ if (PCRE2_${component} _FOUND)
59
+ get_target_property (PCRE2_${component} _LIBRARY PCRE2::${component} IMPORTED_LOCATION )
60
+ set (PCRE2_LIBRARIES ${PCRE2_LIBRARIES} ${PCRE2_${component} _LIBRARY})
61
+ endif ()
62
+ endif ()
63
+ endmacro ()
64
+ _pcre2_add_component_target(8BIT 8)
65
+ _pcre2_add_component_target(16BIT 16)
66
+ _pcre2_add_component_target(32BIT 32)
67
+ _pcre2_add_component_target(POSIX posix)
108
68
109
69
# When POSIX component has been specified make sure that also 8BIT component is specified.
110
70
set (PCRE2_8BIT_COMPONENT FALSE )
@@ -126,43 +86,5 @@ endif()
126
86
unset (PCRE2_8BIT_COMPONENT)
127
87
unset (PCRE2_POSIX_COMPONENT)
128
88
129
- include (FindPackageHandleStandardArgs)
130
- set (${CMAKE_FIND_PACKAGE_NAME} _CONFIG "${CMAKE_CURRENT_LIST_FILE} " )
131
- find_package_handle_standard_args(
132
- PCRE2
133
- FOUND_VAR PCRE2_FOUND
134
- REQUIRED_VARS PCRE2_INCLUDE_DIR
135
- HANDLE_COMPONENTS
136
- VERSION_VAR PCRE2_VERSION
137
- CONFIG_MODE
138
- )
139
-
140
- set (PCRE2_LIBRARIES)
141
- if (PCRE2_FOUND)
142
- foreach (component ${PCRE2_FIND_COMPONENTS} )
143
- if (PCRE2_USE_STATIC_LIBS)
144
- add_library (PCRE2::${component} STATIC IMPORTED )
145
- target_compile_definitions (PCRE2::${component} INTERFACE PCRE2_STATIC)
146
- else ()
147
- add_library (PCRE2::${component} SHARED IMPORTED )
148
- endif ()
149
- set_target_properties (
150
- PCRE2::${component}
151
- PROPERTIES
152
- IMPORTED_LOCATION "${PCRE2_${component} _LIBRARY}"
153
- IMPORTED_IMPLIB "${PCRE2_${component} _LIBRARY}"
154
- INTERFACE_INCLUDE_DIRECTORIES "${PCRE2_INCLUDE_DIR} "
155
- )
156
- if (component STREQUAL "POSIX" )
157
- set_target_properties (
158
- PCRE2::${component}
159
- PROPERTIES INTERFACE_LINK_LIBRARIES "PCRE2::8BIT" LINK_LIBRARIES "PCRE2::8BIT"
160
- )
161
- endif ()
162
-
163
- set (PCRE2_LIBRARIES ${PCRE2_LIBRARIES} ${PCRE2_${component} _LIBRARY})
164
- mark_as_advanced (PCRE2_${component} _LIBRARY)
165
- endforeach ()
166
- endif ()
167
-
168
- mark_as_advanced (PCRE2_INCLUDE_DIR)
89
+ # Check for required components.
90
+ check_required_components("PCRE2" )
0 commit comments