4 # Finds the PCRE2 library
6 # This will define the following imported target::
8 # ${APP_NAME_LC}::PCRE2 - The PCRE2 library
10 if(NOT TARGET ${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME})
13 set(PCRE2_VERSION ${${MODULE}_VER})
15 set(PCRE2_DEBUG_POSTFIX d)
18 set(patches "${CORE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/001-all-enable_docs_pc.patch"
19 "${CORE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/002-all-cmake-config-installdir.patch")
21 generate_patchcommand("${patches}")
23 if(CORE_SYSTEM_NAME STREQUAL darwin_embedded OR WINDOWS_STORE)
24 set(EXTRA_ARGS -DPCRE2_SUPPORT_JIT=OFF)
26 set(EXTRA_ARGS -DPCRE2_SUPPORT_JIT=ON)
29 set(CMAKE_ARGS -DBUILD_STATIC_LIBS=ON
31 -DPCRE2_BUILD_PCRE2_8=ON
32 -DPCRE2_BUILD_PCRE2_16=OFF
33 -DPCRE2_BUILD_PCRE2_32=OFF
34 -DPCRE_NEWLINE=ANYCRLF
35 -DPCRE2_SUPPORT_UNICODE=ON
36 -DPCRE2_BUILD_PCRE2GREP=OFF
37 -DPCRE2_BUILD_TESTS=OFF
41 set(${CMAKE_FIND_PACKAGE_NAME}_COMPILEDEFINITIONS PCRE2_STATIC)
46 include(cmake/scripts/common/ModuleHelpers.cmake)
52 if(KODI_DEPENDSBUILD OR (WIN32 OR WINDOWS_STORE))
53 set(PCRE2_USE_STATIC_LIBS ON)
56 # Check for existing PCRE2. If version >= PCRE2-VERSION file version, dont build
57 find_package(PCRE2 CONFIG COMPONENTS 8BIT QUIET)
59 if((PCRE2_VERSION VERSION_LESS ${${MODULE}_VER} AND ENABLE_INTERNAL_PCRE2) OR
60 ((CORE_SYSTEM_NAME STREQUAL linux OR CORE_SYSTEM_NAME STREQUAL freebsd) AND ENABLE_INTERNAL_PCRE2))
63 # if PCRE2::8BIT target exists, it meets version requirements
64 # we only do a pkgconfig search when a suitable cmake config returns nothing
65 if(TARGET PCRE2::8BIT)
66 get_target_property(_PCRE2_CONFIGURATIONS PCRE2::8BIT IMPORTED_CONFIGURATIONS)
67 if(_PCRE2_CONFIGURATIONS)
68 foreach(_pcre2_config IN LISTS _PCRE2_CONFIGURATIONS)
69 # Just set to RELEASE var so select_library_configurations can continue to work its magic
70 string(TOUPPER ${_pcre2_config} _pcre2_config_UPPER)
71 if((NOT ${_pcre2_config_UPPER} STREQUAL "RELEASE") AND
72 (NOT ${_pcre2_config_UPPER} STREQUAL "DEBUG"))
73 get_target_property(PCRE2_LIBRARY_RELEASE PCRE2::8BIT IMPORTED_LOCATION_${_pcre2_config_UPPER})
75 get_target_property(PCRE2_LIBRARY_${_pcre2_config_UPPER} PCRE2::8BIT IMPORTED_LOCATION_${_pcre2_config_UPPER})
79 get_target_property(PCRE2_LIBRARY_RELEASE PCRE2::8BIT IMPORTED_LOCATION)
81 get_target_property(PCRE2_INCLUDE_DIR PCRE2::8BIT INTERFACE_INCLUDE_DIRECTORIES)
83 # ToDo: use pkgconfig data imported and drop manual find_path/find_library
84 find_package(PkgConfig)
86 pkg_check_modules(PC_PCRE2 libpcre2-8 QUIET)
89 find_path(PCRE2_INCLUDE_DIR pcre2.h
90 HINTS ${PC_PCRE2_INCLUDEDIR})
91 find_library(PCRE2_LIBRARY_RELEASE NAMES pcre2-8
92 HINTS ${PC_PCRE2_LIBDIR})
93 set(PCRE2_VERSION ${PC_PCRE2_VERSION})
97 include(SelectLibraryConfigurations)
98 select_library_configurations(PCRE2)
100 include(FindPackageHandleStandardArgs)
101 find_package_handle_standard_args(PCRE2
102 REQUIRED_VARS PCRE2_LIBRARY PCRE2_INCLUDE_DIR
103 VERSION_VAR PCRE2_VERSION)
106 if(TARGET PCRE2::8BIT AND NOT TARGET pcre2)
107 add_library(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} ALIAS PCRE2::8BIT)
109 add_library(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} UNKNOWN IMPORTED)
110 if(PCRE2_LIBRARY_RELEASE)
111 set_target_properties(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} PROPERTIES
112 IMPORTED_CONFIGURATIONS RELEASE
113 IMPORTED_LOCATION_RELEASE "${PCRE2_LIBRARY_RELEASE}")
115 if(PCRE2_LIBRARY_DEBUG)
116 set_target_properties(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} PROPERTIES
117 IMPORTED_LOCATION_DEBUG "${PCRE2_LIBRARY_DEBUG}")
118 set_property(TARGET ${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} APPEND PROPERTY
119 IMPORTED_CONFIGURATIONS DEBUG)
121 set_target_properties(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} PROPERTIES
122 INTERFACE_INCLUDE_DIRECTORIES "${PCRE2_INCLUDE_DIR}")
124 # Add interface compile definitions. This will usually come from an INTERNAL build being required.
125 if(${CMAKE_FIND_PACKAGE_NAME}_COMPILEDEFINITIONS)
126 set_property(TARGET ${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} APPEND PROPERTY
127 INTERFACE_COMPILE_DEFINITIONS ${${CMAKE_FIND_PACKAGE_NAME}_COMPILEDEFINITIONS})
131 add_dependencies(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} pcre2)
134 # Add internal build target when a Multi Config Generator is used
135 # We cant add a dependency based off a generator expression for targeted build types,
136 # https://gitlab.kitware.com/cmake/cmake/-/issues/19467
137 # therefore if the find heuristics only find the library, we add the internal build
138 # target to the project to allow user to manually trigger for any build type they need
139 # in case only a specific build type is actually available (eg Release found, Debug Required)
140 # This is mainly targeted for windows who required different runtime libs for different
141 # types, and they arent compatible
142 if(_multiconfig_generator)
145 set_target_properties(pcre2 PROPERTIES EXCLUDE_FROM_ALL TRUE)
147 add_dependencies(build_internal_depends pcre2)
151 if(PCRE2_FIND_REQUIRED)
152 message(FATAL_ERROR "PCRE2 not found. Possibly use -DENABLE_INTERNAL_PCRE2=ON to build PCRE2")