2019-12-18 17:51:01 +01:00
|
|
|
INCLUDE (ExternalProject)
|
MDEV-13412 main.func_regexp_pcre fails in buildbot on ppc64le
Caused by 2fcd8c12522. It used the documented pcre API
-pcre_exec(NULL, NULL, NULL, -999, -999, 0, NULL, 0)
to calculate the pcre stack frame size. Unfortunately, modern compilers
broke it by cloning and inlining pcre match() function. 2fcd8c12522
tried to workaround it by setting the stack frame size to at least 500.
It didn't work, 500 is not a universal constant.
Now we fix our copy of pcre to not inline or clone match() - so that
stack frame detection would work again - and detect at cmake time
whether system pcre is broken or usable.
Also use stack, not (much slower) malloc in bundled pcre, unless on Windows
2017-10-05 15:01:38 +02:00
|
|
|
|
2014-03-04 01:22:53 +01:00
|
|
|
SET(WITH_PCRE "auto" CACHE STRING
|
|
|
|
"Which pcre to use (possible values are 'bundled', 'system', or 'auto')")
|
|
|
|
|
2019-12-18 17:51:01 +01:00
|
|
|
MACRO(BUNDLE_PCRE2)
|
2024-01-26 14:43:05 +01:00
|
|
|
SET(WITH_PCRE "bundled" CACHE STRING
|
|
|
|
"Which pcre to use (possible values are 'bundled', 'system', or 'auto')")
|
|
|
|
|
2019-12-18 17:51:01 +01:00
|
|
|
SET(dir "${CMAKE_BINARY_DIR}/extra/pcre2")
|
2024-01-12 16:57:37 +01:00
|
|
|
SET(PCRE_INCLUDE_DIRS ${dir}/src/pcre2-build ${dir}/src/pcre2/src)
|
|
|
|
MESSAGE(STATUS "Will download and bundle pcre2")
|
2019-12-18 17:51:01 +01:00
|
|
|
SET(byproducts)
|
|
|
|
FOREACH(lib pcre2-posix pcre2-8)
|
|
|
|
ADD_LIBRARY(${lib} STATIC IMPORTED GLOBAL)
|
|
|
|
ADD_DEPENDENCIES(${lib} pcre2)
|
2021-10-06 11:31:08 +03:00
|
|
|
|
|
|
|
GET_PROPERTY(MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
|
|
|
|
IF(MULTICONFIG)
|
|
|
|
SET(intdir "${CMAKE_CFG_INTDIR}/")
|
|
|
|
ELSE()
|
|
|
|
SET(intdir)
|
|
|
|
ENDIF()
|
|
|
|
|
2022-01-26 11:23:20 +01:00
|
|
|
# PCRE names static libraries differently depending on platform.
|
|
|
|
# On Windows, but not elsewhere, it adds "-static" to the library name,
|
|
|
|
# or "-staticd".
|
|
|
|
IF(WIN32)
|
|
|
|
SET(PCRE_STATIC "-static")
|
|
|
|
ELSE()
|
|
|
|
SET(PCRE_STATIC "")
|
|
|
|
ENDIF()
|
|
|
|
|
|
|
|
SET(file ${dir}/src/pcre2-build/${intdir}${CMAKE_STATIC_LIBRARY_PREFIX}${lib}${PCRE_STATIC}${CMAKE_STATIC_LIBRARY_SUFFIX})
|
2021-10-06 11:31:08 +03:00
|
|
|
|
2019-12-25 15:09:51 +00:00
|
|
|
IF(WIN32)
|
|
|
|
# Debug libary name.
|
|
|
|
# Same condition as in pcre2 CMakeLists.txt that adds "d"
|
2022-01-26 11:23:20 +01:00
|
|
|
SET(file_d ${dir}/src/pcre2-build/${intdir}${CMAKE_STATIC_LIBRARY_PREFIX}${lib}${PCRE_STATIC}d${CMAKE_STATIC_LIBRARY_SUFFIX})
|
2019-12-25 15:09:51 +00:00
|
|
|
SET_TARGET_PROPERTIES(${lib} PROPERTIES IMPORTED_LOCATION_DEBUG ${file_d})
|
2019-12-18 17:51:01 +01:00
|
|
|
ELSE()
|
2019-12-25 15:09:51 +00:00
|
|
|
SET(file_d)
|
2019-12-18 17:51:01 +01:00
|
|
|
ENDIF()
|
2020-03-09 16:59:12 +01:00
|
|
|
SET(byproducts ${byproducts} BUILD_BYPRODUCTS ${file} ${file_d})
|
2019-12-18 17:51:01 +01:00
|
|
|
SET_TARGET_PROPERTIES(${lib} PROPERTIES IMPORTED_LOCATION ${file})
|
|
|
|
ENDFOREACH()
|
2024-05-02 21:41:13 +02:00
|
|
|
|
2020-05-18 11:00:28 +00:00
|
|
|
FOREACH(v "" "_DEBUG" "_RELWITHDEBINFO" "_RELEASE" "_MINSIZEREL")
|
2024-05-02 21:41:13 +02:00
|
|
|
SET(pcre2_flags${v} "${CMAKE_C_FLAGS${v}}")
|
2019-12-25 15:09:51 +00:00
|
|
|
IF(MSVC)
|
2024-05-02 21:41:13 +02:00
|
|
|
STRING(REPLACE "/WX" "" pcre2_flags${v} "${pcre2_flags${v}}")
|
2019-12-25 15:09:51 +00:00
|
|
|
# Suppress a warning
|
2024-04-26 14:44:38 +02:00
|
|
|
STRING(APPEND pcre2_flags${v} " /wd4244 /wd4267 " )
|
2019-12-25 15:09:51 +00:00
|
|
|
ENDIF()
|
2019-12-18 17:51:01 +01:00
|
|
|
ENDFOREACH()
|
2024-05-02 21:41:13 +02:00
|
|
|
|
2019-12-18 17:51:01 +01:00
|
|
|
ExternalProject_Add(
|
|
|
|
pcre2
|
|
|
|
PREFIX "${dir}"
|
2024-07-17 09:02:58 +02:00
|
|
|
URL "https://github.com/PCRE2Project/pcre2/releases/download/pcre2-10.44/pcre2-10.44.zip"
|
|
|
|
URL_MD5 dfab8313154b3377a6959c3b6377841e
|
2019-12-18 17:51:01 +01:00
|
|
|
INSTALL_COMMAND ""
|
|
|
|
CMAKE_ARGS
|
2022-01-09 23:52:24 +01:00
|
|
|
"-DCMAKE_WARN_DEPRECATED=FALSE"
|
2019-12-18 17:51:01 +01:00
|
|
|
"-DPCRE2_BUILD_TESTS=OFF"
|
|
|
|
"-DPCRE2_BUILD_PCRE2GREP=OFF"
|
|
|
|
"-DBUILD_SHARED_LIBS=OFF"
|
|
|
|
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
|
|
|
|
"-DCMAKE_C_FLAGS=${pcre2_flags} ${PIC_FLAG}"
|
|
|
|
"-DCMAKE_C_FLAGS_DEBUG=${pcre2_flags_DEBUG}"
|
|
|
|
"-DCMAKE_C_FLAGS_RELWITHDEBINFO=${pcre2_flags_RELWITHDEBINFO}"
|
|
|
|
"-DCMAKE_C_FLAGS_RELEASE=${pcre2_flags_RELEASE}"
|
|
|
|
"-DCMAKE_C_FLAGS_MINSIZEREL=${pcre2_flags_MINSIZEREL}"
|
|
|
|
"-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
|
2020-05-18 11:00:28 +00:00
|
|
|
${stdlibs}
|
2019-12-18 17:51:01 +01:00
|
|
|
${byproducts}
|
|
|
|
)
|
|
|
|
SET_TARGET_PROPERTIES(pcre2 PROPERTIES EXCLUDE_FROM_ALL TRUE)
|
|
|
|
ENDMACRO()
|
|
|
|
|
2014-03-04 01:22:53 +01:00
|
|
|
MACRO (CHECK_PCRE)
|
2024-01-12 16:57:37 +01:00
|
|
|
IF (NOT TARGET pcre2 AND NOT PCRE_FOUND)
|
|
|
|
IF(WITH_PCRE STREQUAL "system" OR WITH_PCRE STREQUAL "auto")
|
|
|
|
FIND_PACKAGE(PkgConfig QUIET)
|
|
|
|
PKG_CHECK_MODULES(PCRE libpcre2-8)
|
|
|
|
# in case pkg-config or libpcre2-8.pc is not installed:
|
2024-02-01 11:26:36 +01:00
|
|
|
CHECK_LIBRARY_EXISTS(pcre2-8 pcre2_match_8 "${PCRE_LIBRARY_DIRS}" HAVE_PCRE2_MATCH_8)
|
2014-03-04 01:22:53 +01:00
|
|
|
ENDIF()
|
2024-02-01 11:26:36 +01:00
|
|
|
IF(NOT HAVE_PCRE2_MATCH_8 OR WITH_PCRE STREQUAL "bundled")
|
2024-01-12 16:57:37 +01:00
|
|
|
IF (WITH_PCRE STREQUAL "system")
|
|
|
|
MESSAGE(FATAL_ERROR "system pcre2-8 library is not found or unusable")
|
|
|
|
ENDIF()
|
|
|
|
BUNDLE_PCRE2()
|
|
|
|
ELSE()
|
2024-02-01 11:26:36 +01:00
|
|
|
CHECK_LIBRARY_EXISTS(pcre2-posix PCRE2regcomp "${PCRE_LIBRARY_DIRS}" NEEDS_PCRE2_DEBIAN_HACK)
|
2024-01-12 16:57:37 +01:00
|
|
|
IF(NEEDS_PCRE2_DEBIAN_HACK)
|
|
|
|
SET(PCRE2_DEBIAN_HACK "-Dregcomp=PCRE2regcomp -Dregexec=PCRE2regexec -Dregerror=PCRE2regerror -Dregfree=PCRE2regfree")
|
|
|
|
ENDIF()
|
2020-01-13 13:08:55 +01:00
|
|
|
ENDIF()
|
2014-03-04 01:22:53 +01:00
|
|
|
ENDIF()
|
|
|
|
ENDMACRO()
|
|
|
|
|