From 4a4642b1d7562b553f80da279255a9755a9e20f7 Mon Sep 17 00:00:00 2001 From: fuzzard Date: Sun, 2 Jun 2024 13:24:57 +1000 Subject: [PATCH] Introduce PCRE2 dependency create PCRE2 in tools/depends/target Create Find module for PCRE2 Upstream: https://github.com/xbmc/xbmc/commit/5c24bf262e5cd75b413fcb4c2c5c144d6971d7cc [Bernd: backported relevant parts to 21.3-Omega] Signed-off-by: Bernd Kuhls --- cmake/modules/FindPCRE2.cmake | 151 +++++++++++++++++++++++ tools/depends/target/pcre2/PCRE2-VERSION | 7 ++ 2 files changed, 158 insertions(+) create mode 100644 cmake/modules/FindPCRE2.cmake create mode 100644 tools/depends/target/pcre2/PCRE2-VERSION diff --git a/cmake/modules/FindPCRE2.cmake b/cmake/modules/FindPCRE2.cmake new file mode 100644 index 0000000000..7e50d5f2c1 --- /dev/null +++ b/cmake/modules/FindPCRE2.cmake @@ -0,0 +1,151 @@ +#.rst: +# FindPCRE2 +# -------- +# Finds the PCRE2 library +# +# This will define the following imported target:: +# +# ${APP_NAME_LC}::PCRE2 - The PCRE2 library + +if(NOT TARGET ${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME}) + + macro(buildPCRE2) + set(PCRE2_VERSION ${${MODULE}_VER}) + if(WIN32) + set(PCRE_DEBUG_POSTFIX d) + endif() + + set(patches "${CORE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/001-all-enable_docs_pc.patch" + "${CORE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/002-all-cmake-config-installdir.patch") + + generate_patchcommand("${patches}") + + set(CMAKE_ARGS -DBUILD_STATIC_LIBS=ON + -DPCRE2_BUILD_PCRE2_8=ON + -DPCRE2_BUILD_PCRE2_16=OFF + -DPCRE2_BUILD_PCRE2_32=OFF + -DPCRE2_SUPPORT_JIT=ON + -DPCRE2_SUPPORT_UNICODE=ON + -DPCRE2_BUILD_PCRE2GREP=OFF + -DPCRE2_BUILD_TESTS=OFF + -DENABLE_DOCS=OFF) + + if(CORE_SYSTEM_NAME STREQUAL darwin_embedded) + list(APPEND CMAKE_ARGS -DPCRE2_SUPPORT_JIT=OFF) + endif() + + set(${CMAKE_FIND_PACKAGE_NAME}_COMPILEDEFINITIONS PCRE2_STATIC) + + BUILD_DEP_TARGET() + endmacro() + + include(cmake/scripts/common/ModuleHelpers.cmake) + + set(MODULE_LC pcre2) + + SETUP_BUILD_VARS() + + if(KODI_DEPENDSBUILD OR (WIN32 OR WINDOWS_STORE)) + set(PCRE2_USE_STATIC_LIBS ON) + endif() + + # Check for existing PCRE2. If version >= PCRE2-VERSION file version, dont build + find_package(PCRE2 CONFIG COMPONENTS 8BIT QUIET) + + if((PCRE2_VERSION VERSION_LESS ${${MODULE}_VER} AND ENABLE_INTERNAL_PCRE2) OR + ((CORE_SYSTEM_NAME STREQUAL linux OR CORE_SYSTEM_NAME STREQUAL freebsd) AND ENABLE_INTERNAL_PCRE2)) + buildPCRE2() + else() + # if PCRE2::8BIT target exists, it meets version requirements + # we only do a pkgconfig search when a suitable cmake config returns nothing + if(TARGET PCRE2::8BIT) + get_target_property(_PCRE2_CONFIGURATIONS PCRE2::8BIT IMPORTED_CONFIGURATIONS) + if(_PCRE2_CONFIGURATIONS) + foreach(_pcre2_config IN LISTS _PCRE2_CONFIGURATIONS) + # Just set to RELEASE var so select_library_configurations can continue to work its magic + string(TOUPPER ${_pcre2_config} _pcre2_config_UPPER) + if((NOT ${_pcre2_config_UPPER} STREQUAL "RELEASE") AND + (NOT ${_pcre2_config_UPPER} STREQUAL "DEBUG")) + get_target_property(PCRE2_LIBRARY_RELEASE PCRE2::8BIT IMPORTED_LOCATION_${_pcre2_config_UPPER}) + else() + get_target_property(PCRE2_LIBRARY_${_pcre2_config_UPPER} PCRE2::8BIT IMPORTED_LOCATION_${_pcre2_config_UPPER}) + endif() + endforeach() + else() + get_target_property(PCRE2_LIBRARY_RELEASE PCRE2::8BIT IMPORTED_LOCATION) + endif() + get_target_property(PCRE2_INCLUDE_DIR PCRE2::8BIT INTERFACE_INCLUDE_DIRECTORIES) + else() + # ToDo: use pkgconfig data imported and drop manual find_path/find_library + find_package(PkgConfig) + if(PKG_CONFIG_FOUND) + pkg_check_modules(PC_PCRE2 libpcre2-8 QUIET) + endif() + + find_path(PCRE2_INCLUDE_DIR pcre2.h + HINTS ${PC_PCRE2_INCLUDEDIR}) + find_library(PCRE2_LIBRARY_RELEASE NAMES pcre2-8 + HINTS ${PC_PCRE2_LIBDIR}) + set(PCRE2_VERSION ${PC_PCRE2_VERSION}) + endif() + endif() + + include(SelectLibraryConfigurations) + select_library_configurations(PCRE2) + + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(PCRE2 + REQUIRED_VARS PCRE2_LIBRARY PCRE2_INCLUDE_DIR + VERSION_VAR PCRE2_VERSION) + + if(PCRE2_FOUND) + if(TARGET PCRE2::8BIT AND NOT TARGET pcre2) + add_library(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} ALIAS PCRE2::8BIT) + else() + add_library(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} UNKNOWN IMPORTED) + if(PCRE2_LIBRARY_RELEASE) + set_target_properties(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} PROPERTIES + IMPORTED_CONFIGURATIONS RELEASE + IMPORTED_LOCATION_RELEASE "${PCRE2_LIBRARY_RELEASE}") + endif() + if(PCRE2_LIBRARY_DEBUG) + set_target_properties(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} PROPERTIES + IMPORTED_LOCATION_DEBUG "${PCRE2_LIBRARY_DEBUG}") + set_property(TARGET ${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} APPEND PROPERTY + IMPORTED_CONFIGURATIONS DEBUG) + endif() + set_target_properties(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${PCRE2_INCLUDE_DIR}") + + # Add interface compile definitions. This will usually come from an INTERNAL build being required. + if(${CMAKE_FIND_PACKAGE_NAME}_COMPILEDEFINITIONS) + set_property(TARGET ${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} APPEND PROPERTY + INTERFACE_COMPILE_DEFINITIONS ${${CMAKE_FIND_PACKAGE_NAME}_COMPILEDEFINITIONS}) + endif() + endif() + if(TARGET pcre2) + add_dependencies(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} pcre2) + endif() + + # Add internal build target when a Multi Config Generator is used + # We cant add a dependency based off a generator expression for targeted build types, + # https://gitlab.kitware.com/cmake/cmake/-/issues/19467 + # therefore if the find heuristics only find the library, we add the internal build + # target to the project to allow user to manually trigger for any build type they need + # in case only a specific build type is actually available (eg Release found, Debug Required) + # This is mainly targeted for windows who required different runtime libs for different + # types, and they arent compatible + if(_multiconfig_generator) + if(NOT TARGET pcre2) + buildPCRE2() + set_target_properties(pcre2 PROPERTIES EXCLUDE_FROM_ALL TRUE) + endif() + add_dependencies(build_internal_depends pcre2) + endif() + + else() + if(PCRE2_FIND_REQUIRED) + message(FATAL_ERROR "PCRE2 not found. Possibly use -DENABLE_INTERNAL_PCRE2=ON to build PCRE2") + endif() + endif() +endif() diff --git a/tools/depends/target/pcre2/PCRE2-VERSION b/tools/depends/target/pcre2/PCRE2-VERSION new file mode 100644 index 0000000000..800eebf0b9 --- /dev/null +++ b/tools/depends/target/pcre2/PCRE2-VERSION @@ -0,0 +1,7 @@ +LIBNAME=pcre2 +VERSION=10.42 +ARCHIVE=$(LIBNAME)-$(VERSION).tar.bz2 +SHA512=72fbde87fecec3aa4b47225dd919ea1d55e97f2cbcf02aba26e5a0d3b1ffb58c25a80a9ef069eb99f9cf4e41ba9604ad06a7ec159870e1e875d86820e12256d3 +BYPRODUCT=libpcre2-8.a +BYPRODUCT_WIN=pcre2-8-static.lib + -- 2.47.3