1# CMakeLists.txt 2# 3# This file enables PCRE2 to be built with the CMake configuration and build 4# tool. Download CMake in source or binary form from http://www.cmake.org/ 5# Converted to support PCRE2 from the original PCRE file, August 2014. 6# 7# Original listfile by Christian Ehrlicher <Ch.Ehrlicher@gmx.de> 8# Refined and expanded by Daniel Richard G. <skunk@iSKUNK.ORG> 9# 2007-09-14 mod by Sheri so 7.4 supported configuration options can be entered 10# 2007-09-19 Adjusted by PH to retain previous default settings 11# 2007-12-26 (a) On UNIX, use names libpcre instead of just pcre 12# (b) Ensure pcretest and pcregrep link with the local library, 13# not a previously-installed one. 14# (c) Add PCRE_SUPPORT_LIBREADLINE, PCRE_SUPPORT_LIBZ, and 15# PCRE_SUPPORT_LIBBZ2. 16# 2008-01-20 Brought up to date to include several new features by Christian 17# Ehrlicher. 18# 2008-01-22 Sheri added options for backward compatibility of library names 19# when building with minGW: 20# if "ON", NON_STANDARD_LIB_PREFIX causes shared libraries to 21# be built without "lib" as prefix. (The libraries will be named 22# pcre.dll, pcreposix.dll and pcrecpp.dll). 23# if "ON", NON_STANDARD_LIB_SUFFIX causes shared libraries to 24# be built with suffix of "-0.dll". (The libraries will be named 25# libpcre-0.dll, libpcreposix-0.dll and libpcrecpp-0.dll - same names 26# built by default with Configure and Make. 27# 2008-01-23 PH removed the automatic build of pcredemo. 28# 2008-04-22 PH modified READLINE support so it finds NCURSES when needed. 29# 2008-07-03 PH updated for revised UCP property support (change of files) 30# 2009-03-23 PH applied Steven Van Ingelgem's patch to change the name 31# CMAKE_BINARY_DIR to PROJECT_BINARY_DIR so that it works when PCRE 32# is included within another project. 33# 2009-03-23 PH applied a modified version of Steven Van Ingelgem's patches to 34# add options to stop the building of pcregrep and the tests, and 35# to disable the final configuration report. 36# 2009-04-11 PH applied Christian Ehrlicher's patch to show compiler flags that 37# are set by specifying a release type. 38# 2010-01-02 PH added test for stdint.h 39# 2010-03-02 PH added test for inttypes.h 40# 2011-08-01 PH added PCREGREP_BUFSIZE 41# 2011-08-22 PH added PCRE_SUPPORT_JIT 42# 2011-09-06 PH modified WIN32 ADD_TEST line as suggested by Sergey Cherepanov 43# 2011-09-06 PH added PCRE_SUPPORT_PCREGREP_JIT 44# 2011-10-04 Sheri added support for including coff data in windows shared libraries 45# compiled with MINGW if pcre.rc and/or pcreposix.rc are placed in 46# the source dir by the user prior to building 47# 2011-10-04 Sheri changed various add_test's to use exes' location built instead 48# of DEBUG location only (likely only matters in MSVC) 49# 2011-10-04 Sheri added scripts to provide needed variables to RunTest and 50# RunGrepTest (used for UNIX and Msys) 51# 2011-10-04 Sheri added scripts to provide needed variables and to execute 52# RunTest.bat in Win32 (for effortless testing with "make test") 53# 2011-10-04 Sheri Increased minimum required cmake version 54# 2012-01-06 PH removed pcre_info.c and added pcre_string_utils.c 55# 2012-01-10 Zoltan Herczeg added libpcre16 support 56# 2012-01-13 Stephen Kelly added out of source build support 57# 2012-01-17 PH applied Stephen Kelly's patch to parse the version data out 58# of the configure.ac file 59# 2012-02-26 PH added support for libedit 60# 2012-09-06 PH added support for PCRE_EBCDIC_NL25 61# 2012-09-08 ChPe added PCRE32 support 62# 2012-10-23 PH added support for VALGRIND and GCOV 63# 2012-12-08 PH added patch from Daniel Richard G to quash some MSVC warnings 64# 2013-07-01 PH realized that the "support" for GCOV was a total nonsense and 65# so it has been removed. 66# 2013-10-08 PH got rid of the "source" command, which is a bash-ism (use ".") 67# 2013-11-05 PH added support for PARENS_NEST_LIMIT 68# 2014-08-29 PH converted the file for PCRE2 (which has no C++). 69# 2015-04-24 PH added support for PCRE2_DEBUG 70# 2015-07-16 PH updated for new pcre2_find_bracket source module 71# 2015-08-24 PH correct C_FLAGS setting (patch from Roy Ivy III) 72# 2015-10=16 PH added support for never-backslash-C 73# 2016-03-01 PH applied Chris Wilson's patch for MSVC static 74# 2016-06-24 PH applied Chris Wilson's second patch, putting the first under 75# a new option instead of being unconditional. 76# 2016-10-05 PH fixed a typo (PCRE should be PCRE2) in above patch 77# fix by David Gaussmann 78# 2016-10-07 PH added PCREGREP_MAX_BUFSIZE 79# 2017-03-11 PH turned HEAP_MATCH_RECURSE into a NO-OP for 10.30 80# 2017-04-08 PH added HEAP_LIMIT 81# 2017-06-15 ZH added SUPPORT_JIT_SEALLOC support 82# 2018-06-19 PH added checks for stdint.h and inttypes.h (later removed) 83# 2018-06-27 PH added Daniel's patch to increase the stack for MSVC 84# 2018-11-14 PH removed unnecessary checks for stdint.h and inttypes.h 85# 2018-11-16 PH added PCRE2GREP_SUPPORT_CALLOUT_FORK support and tidied 86# 2019-02-16 PH hacked to avoid CMP0026 policy issue (see comments below) 87# 2020-03-16 PH renamed dftables as pcre2_dftables (as elsewhere) 88# 2020-03-24 PH changed CMAKE_MODULE_PATH definition to add, not replace 89# 2020-04-08 Carlo added function check for secure_getenv, fixed strerror 90# 2020-04-16 enh added check for __attribute__((uninitialized)) 91# 2020-04-25 PH applied patches from Uwe Korn to support pkg-config and 92# library versioning. 93# 2020-04-25 Carlo added function check for mkostemp used in ProtExecAllocator 94# 2020-04-28 PH added function check for memfd_create based on Carlo's patch 95# 2020-05-25 PH added a check for Intel CET 96# 2020-12-03 PH altered the definition of pcre2test as suggested by Daniel 97# 2021-06-29 JWSB added the option to build static library with PIC. 98# 2021-07-05 JWSB modified such both the static and shared library can be 99# build in one go. 100# 2021-08-28 PH increased minimum version 101# 2021-08-28 PH added test for realpath() 102 103PROJECT(PCRE2 C) 104 105# Increased minimum to 2.8.5 to support GNUInstallDirs. 106# Increased minimum to 3.0.0 because older than 2.8.12 is deprecated. 107CMAKE_MINIMUM_REQUIRED(VERSION 3.0.0) 108 109# Set policy CMP0026 to avoid warnings for the use of LOCATION in 110# GET_TARGET_PROPERTY. This should no longer be required. 111# CMAKE_POLICY(SET CMP0026 OLD) 112 113# For FindReadline.cmake. This was changed to allow setting CMAKE_MODULE_PATH 114# on the command line. 115# SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) 116 117LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) 118 119INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src) 120 121# external packages 122FIND_PACKAGE( BZip2 ) 123FIND_PACKAGE( ZLIB ) 124FIND_PACKAGE( Readline ) 125FIND_PACKAGE( Editline ) 126 127# Configuration checks 128 129INCLUDE(CheckCSourceCompiles) 130INCLUDE(CheckFunctionExists) 131INCLUDE(CheckSymbolExists) 132INCLUDE(CheckIncludeFile) 133INCLUDE(CheckTypeSize) 134INCLUDE(GNUInstallDirs) # for CMAKE_INSTALL_LIBDIR 135 136CHECK_INCLUDE_FILE(dirent.h HAVE_DIRENT_H) 137CHECK_INCLUDE_FILE(sys/stat.h HAVE_SYS_STAT_H) 138CHECK_INCLUDE_FILE(sys/types.h HAVE_SYS_TYPES_H) 139CHECK_INCLUDE_FILE(unistd.h HAVE_UNISTD_H) 140CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H) 141 142CHECK_SYMBOL_EXISTS(bcopy "strings.h" HAVE_BCOPY) 143CHECK_SYMBOL_EXISTS(memfd_create "sys/mman.h" HAVE_MEMFD_CREATE) 144CHECK_SYMBOL_EXISTS(memmove "string.h" HAVE_MEMMOVE) 145CHECK_SYMBOL_EXISTS(realpath "stdlib.h" HAVE_REALPATH) 146CHECK_SYMBOL_EXISTS(secure_getenv "stdlib.h" HAVE_SECURE_GETENV) 147CHECK_SYMBOL_EXISTS(strerror "string.h" HAVE_STRERROR) 148 149set(ORIG_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) 150set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror") 151CHECK_C_SOURCE_COMPILES( 152 "int main() { char buf[128] __attribute__((uninitialized)); (void)buf; return 0; }" 153 HAVE_ATTRIBUTE_UNINITIALIZED 154) 155set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS}) 156 157# Check whether Intel CET is enabled, and if so, adjust compiler flags. This 158# code was written by PH, trying to imitate the logic from the autotools 159# configuration. 160 161CHECK_C_SOURCE_COMPILES( 162 "#ifndef __CET__ 163 #error CET is not enabled 164 #endif 165 int main() { return 0; }" 166 INTEL_CET_ENABLED 167) 168 169IF (INTEL_CET_ENABLED) 170 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mshstk") 171ENDIF(INTEL_CET_ENABLED) 172 173 174 175# User-configurable options 176# 177# Note: CMakeSetup displays these in alphabetical order, regardless of 178# the order we use here. 179 180SET(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries.") 181 182OPTION(BUILD_STATIC_LIBS "Build static libraries." ON) 183 184OPTION(PCRE2_BUILD_PCRE2_8 "Build 8 bit PCRE2 library" ON) 185 186OPTION(PCRE2_BUILD_PCRE2_16 "Build 16 bit PCRE2 library" OFF) 187 188OPTION(PCRE2_BUILD_PCRE2_32 "Build 32 bit PCRE2 library" OFF) 189 190OPTION(PCRE2_STATIC_PIC "Build the static library with the option position independent code enabled." OFF) 191 192OPTION(PCRE2_DEBUG "Include debugging code" OFF) 193 194OPTION(PCRE2_DISABLE_PERCENT_ZT "Disable the use of %zu and %td (rarely needed)" OFF) 195 196SET(PCRE2_EBCDIC OFF CACHE BOOL 197 "Use EBCDIC coding instead of ASCII. (This is rarely used outside of mainframe systems.)") 198 199SET(PCRE2_EBCDIC_NL25 OFF CACHE BOOL 200 "Use 0x25 as EBCDIC NL character instead of 0x15; implies EBCDIC.") 201 202SET(PCRE2_LINK_SIZE "2" CACHE STRING 203 "Internal link size (2, 3 or 4 allowed). See LINK_SIZE in config.h.in for details.") 204 205SET(PCRE2_PARENS_NEST_LIMIT "250" CACHE STRING 206 "Default nested parentheses limit. See PARENS_NEST_LIMIT in config.h.in for details.") 207 208SET(PCRE2_HEAP_LIMIT "20000000" CACHE STRING 209 "Default limit on heap memory (kibibytes). See HEAP_LIMIT in config.h.in for details.") 210 211SET(PCRE2_MATCH_LIMIT "10000000" CACHE STRING 212 "Default limit on internal looping. See MATCH_LIMIT in config.h.in for details.") 213 214SET(PCRE2_MATCH_LIMIT_DEPTH "MATCH_LIMIT" CACHE STRING 215 "Default limit on internal depth of search. See MATCH_LIMIT_DEPTH in config.h.in for details.") 216 217SET(PCRE2GREP_BUFSIZE "20480" CACHE STRING 218 "Buffer starting size parameter for pcre2grep. See PCRE2GREP_BUFSIZE in config.h.in for details.") 219 220SET(PCRE2GREP_MAX_BUFSIZE "1048576" CACHE STRING 221 "Buffer maximum size parameter for pcre2grep. See PCRE2GREP_MAX_BUFSIZE in config.h.in for details.") 222 223SET(PCRE2_NEWLINE "LF" CACHE STRING 224 "What to recognize as a newline (one of CR, LF, CRLF, ANY, ANYCRLF, NUL).") 225 226SET(PCRE2_HEAP_MATCH_RECURSE OFF CACHE BOOL 227 "Obsolete option: do not use") 228 229SET(PCRE2_SUPPORT_JIT OFF CACHE BOOL 230 "Enable support for Just-in-time compiling.") 231 232IF(${CMAKE_SYSTEM_NAME} MATCHES Linux|NetBSD) 233 SET(PCRE2_SUPPORT_JIT_SEALLOC OFF CACHE BOOL 234 "Enable SELinux compatible execmem allocator in JIT (experimental).") 235ELSE(${CMAKE_SYSTEM_NAME} MATCHES Linux|NetBSD) 236 SET(PCRE2_SUPPORT_JIT_SEALLOC IGNORE) 237ENDIF(${CMAKE_SYSTEM_NAME} MATCHES Linux|NetBSD) 238 239SET(PCRE2GREP_SUPPORT_JIT ON CACHE BOOL 240 "Enable use of Just-in-time compiling in pcre2grep.") 241 242SET(PCRE2GREP_SUPPORT_CALLOUT ON CACHE BOOL 243 "Enable callout string support in pcre2grep.") 244 245SET(PCRE2GREP_SUPPORT_CALLOUT_FORK ON CACHE BOOL 246 "Enable callout string fork support in pcre2grep.") 247 248SET(PCRE2_SUPPORT_UNICODE ON CACHE BOOL 249 "Enable support for Unicode and UTF-8/UTF-16/UTF-32 encoding.") 250 251SET(PCRE2_SUPPORT_BSR_ANYCRLF OFF CACHE BOOL 252 "ON=Backslash-R matches only LF CR and CRLF, OFF=Backslash-R matches all Unicode Linebreaks") 253 254SET(PCRE2_NEVER_BACKSLASH_C OFF CACHE BOOL 255 "If ON, backslash-C (upper case C) is locked out.") 256 257SET(PCRE2_SUPPORT_VALGRIND OFF CACHE BOOL 258 "Enable Valgrind support.") 259 260OPTION(PCRE2_SHOW_REPORT "Show the final configuration report" ON) 261OPTION(PCRE2_BUILD_PCRE2GREP "Build pcre2grep" ON) 262OPTION(PCRE2_BUILD_TESTS "Build the tests" ON) 263 264IF (MINGW) 265 OPTION(NON_STANDARD_LIB_PREFIX 266 "ON=Shared libraries built in mingw will be named pcre2.dll, etc., instead of libpcre2.dll, etc." 267 OFF) 268 269 OPTION(NON_STANDARD_LIB_SUFFIX 270 "ON=Shared libraries built in mingw will be named libpcre2-0.dll, etc., instead of libpcre2.dll, etc." 271 OFF) 272ENDIF(MINGW) 273 274IF(MSVC) 275 OPTION(PCRE2_STATIC_RUNTIME 276 "ON=Compile against the static runtime (/MT)." 277 OFF) 278 OPTION(INSTALL_MSVC_PDB 279 "ON=Install .pdb files built by MSVC, if generated" 280 OFF) 281ENDIF(MSVC) 282 283# bzip2 lib 284IF(BZIP2_FOUND) 285 OPTION (PCRE2_SUPPORT_LIBBZ2 "Enable support for linking pcre2grep with libbz2." ON) 286ENDIF(BZIP2_FOUND) 287IF(PCRE2_SUPPORT_LIBBZ2) 288 INCLUDE_DIRECTORIES(${BZIP2_INCLUDE_DIR}) 289ENDIF(PCRE2_SUPPORT_LIBBZ2) 290 291# zlib 292IF(ZLIB_FOUND) 293 OPTION (PCRE2_SUPPORT_LIBZ "Enable support for linking pcre2grep with libz." ON) 294ENDIF(ZLIB_FOUND) 295IF(PCRE2_SUPPORT_LIBZ) 296 INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR}) 297ENDIF(PCRE2_SUPPORT_LIBZ) 298 299# editline lib 300IF(EDITLINE_FOUND) 301 OPTION (PCRE2_SUPPORT_LIBEDIT "Enable support for linking pcre2test with libedit." OFF) 302ENDIF(EDITLINE_FOUND) 303IF(PCRE2_SUPPORT_LIBEDIT) 304 INCLUDE_DIRECTORIES(${EDITLINE_INCLUDE_DIR}) 305ENDIF(PCRE2_SUPPORT_LIBEDIT) 306 307# readline lib 308IF(READLINE_FOUND) 309 OPTION (PCRE2_SUPPORT_LIBREADLINE "Enable support for linking pcre2test with libreadline." ON) 310ENDIF(READLINE_FOUND) 311IF(PCRE2_SUPPORT_LIBREADLINE) 312 INCLUDE_DIRECTORIES(${READLINE_INCLUDE_DIR}) 313ENDIF(PCRE2_SUPPORT_LIBREADLINE) 314 315# Prepare build configuration 316 317IF(NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_LIBS) 318 MESSAGE(FATAL_ERROR "At least one of BUILD_SHARED_LIBS or BUILD_STATIC_LIBS must be enabled.") 319ENDIF(NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_LIBS) 320 321IF(NOT PCRE2_BUILD_PCRE2_8 AND NOT PCRE2_BUILD_PCRE2_16 AND NOT PCRE2_BUILD_PCRE2_32) 322 MESSAGE(FATAL_ERROR "At least one of PCRE2_BUILD_PCRE2_8, PCRE2_BUILD_PCRE2_16 or PCRE2_BUILD_PCRE2_32 must be enabled") 323ENDIF(NOT PCRE2_BUILD_PCRE2_8 AND NOT PCRE2_BUILD_PCRE2_16 AND NOT PCRE2_BUILD_PCRE2_32) 324 325IF(PCRE2_BUILD_PCRE2_8) 326 SET(SUPPORT_PCRE2_8 1) 327ENDIF(PCRE2_BUILD_PCRE2_8) 328 329IF(PCRE2_BUILD_PCRE2_16) 330 SET(SUPPORT_PCRE2_16 1) 331ENDIF(PCRE2_BUILD_PCRE2_16) 332 333IF(PCRE2_BUILD_PCRE2_32) 334 SET(SUPPORT_PCRE2_32 1) 335ENDIF(PCRE2_BUILD_PCRE2_32) 336 337IF(PCRE2_BUILD_PCRE2GREP AND NOT PCRE2_BUILD_PCRE2_8) 338 MESSAGE(STATUS "** PCRE2_BUILD_PCRE2_8 must be enabled for the pcre2grep program") 339 SET(PCRE2_BUILD_PCRE2GREP OFF) 340ENDIF(PCRE2_BUILD_PCRE2GREP AND NOT PCRE2_BUILD_PCRE2_8) 341 342IF(PCRE2_SUPPORT_LIBREADLINE AND PCRE2_SUPPORT_LIBEDIT) 343 MESSAGE(FATAL_ERROR "Only one of libreadline or libeditline can be specified") 344ENDIF(PCRE2_SUPPORT_LIBREADLINE AND PCRE2_SUPPORT_LIBEDIT) 345 346IF(PCRE2_SUPPORT_BSR_ANYCRLF) 347 SET(BSR_ANYCRLF 1) 348ENDIF(PCRE2_SUPPORT_BSR_ANYCRLF) 349 350IF(PCRE2_NEVER_BACKSLASH_C) 351 SET(NEVER_BACKSLASH_C 1) 352ENDIF(PCRE2_NEVER_BACKSLASH_C) 353 354IF(PCRE2_SUPPORT_UNICODE) 355 SET(SUPPORT_UNICODE 1) 356ENDIF(PCRE2_SUPPORT_UNICODE) 357 358IF(PCRE2_SUPPORT_JIT) 359 SET(SUPPORT_JIT 1) 360ENDIF(PCRE2_SUPPORT_JIT) 361 362IF(PCRE2_SUPPORT_JIT_SEALLOC) 363 SET(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) 364 CHECK_SYMBOL_EXISTS(mkostemp stdlib.h REQUIRED) 365 UNSET(CMAKE_REQUIRED_DEFINITIONS) 366 IF(${REQUIRED}) 367 IF(${CMAKE_SYSTEM_NAME} MATCHES Linux|NetBSD) 368 ADD_DEFINITIONS(-D_GNU_SOURCE) 369 SET(SLJIT_PROT_EXECUTABLE_ALLOCATOR 1) 370 ELSE(${CMAKE_SYSTEM_NAME} MATCHES Linux|NetBSD) 371 MESSAGE(FATAL_ERROR "Your configuration is not supported") 372 ENDIF(${CMAKE_SYSTEM_NAME} MATCHES Linux|NetBSD) 373 ELSE(${REQUIRED}) 374 SET(PCRE2_SUPPORT_JIT_SEALLOC OFF) 375 ENDIF(${REQUIRED}) 376ENDIF(PCRE2_SUPPORT_JIT_SEALLOC) 377 378IF(PCRE2GREP_SUPPORT_JIT) 379 SET(SUPPORT_PCRE2GREP_JIT 1) 380ENDIF(PCRE2GREP_SUPPORT_JIT) 381 382IF(PCRE2GREP_SUPPORT_CALLOUT) 383 SET(SUPPORT_PCRE2GREP_CALLOUT 1) 384 IF(PCRE2GREP_SUPPORT_CALLOUT_FORK) 385 SET(SUPPORT_PCRE2GREP_CALLOUT_FORK 1) 386 ENDIF(PCRE2GREP_SUPPORT_CALLOUT_FORK) 387ENDIF(PCRE2GREP_SUPPORT_CALLOUT) 388 389IF(PCRE2_SUPPORT_VALGRIND) 390 SET(SUPPORT_VALGRIND 1) 391ENDIF(PCRE2_SUPPORT_VALGRIND) 392 393IF(PCRE2_DISABLE_PERCENT_ZT) 394 SET(DISABLE_PERCENT_ZT 1) 395ENDIF(PCRE2_DISABLE_PERCENT_ZT) 396 397# This next one used to reference ${READLINE_LIBRARY}) 398# but I was advised to add the NCURSES test as well, along with 399# some modifications to cmake/FindReadline.cmake which should 400# make it possible to override the default if necessary. PH 401 402IF(PCRE2_SUPPORT_LIBREADLINE) 403 SET(SUPPORT_LIBREADLINE 1) 404 SET(PCRE2TEST_LIBS ${READLINE_LIBRARY} ${NCURSES_LIBRARY}) 405ENDIF(PCRE2_SUPPORT_LIBREADLINE) 406 407# libedit is a plug-compatible alternative to libreadline 408 409IF(PCRE2_SUPPORT_LIBEDIT) 410 SET(SUPPORT_LIBEDIT 1) 411 SET(PCRE2TEST_LIBS ${EDITLINE_LIBRARY} ${NCURSES_LIBRARY}) 412ENDIF(PCRE2_SUPPORT_LIBEDIT) 413 414IF(PCRE2_SUPPORT_LIBZ) 415 SET(SUPPORT_LIBZ 1) 416 SET(PCRE2GREP_LIBS ${PCRE2GREP_LIBS} ${ZLIB_LIBRARIES}) 417ENDIF(PCRE2_SUPPORT_LIBZ) 418 419IF(PCRE2_SUPPORT_LIBBZ2) 420 SET(SUPPORT_LIBBZ2 1) 421 SET(PCRE2GREP_LIBS ${PCRE2GREP_LIBS} ${BZIP2_LIBRARIES}) 422ENDIF(PCRE2_SUPPORT_LIBBZ2) 423 424SET(NEWLINE_DEFAULT "") 425 426IF(PCRE2_NEWLINE STREQUAL "CR") 427 SET(NEWLINE_DEFAULT "1") 428ENDIF(PCRE2_NEWLINE STREQUAL "CR") 429IF(PCRE2_NEWLINE STREQUAL "LF") 430 SET(NEWLINE_DEFAULT "2") 431ENDIF(PCRE2_NEWLINE STREQUAL "LF") 432IF(PCRE2_NEWLINE STREQUAL "CRLF") 433 SET(NEWLINE_DEFAULT "3") 434ENDIF(PCRE2_NEWLINE STREQUAL "CRLF") 435IF(PCRE2_NEWLINE STREQUAL "ANY") 436 SET(NEWLINE_DEFAULT "4") 437ENDIF(PCRE2_NEWLINE STREQUAL "ANY") 438IF(PCRE2_NEWLINE STREQUAL "ANYCRLF") 439 SET(NEWLINE_DEFAULT "5") 440ENDIF(PCRE2_NEWLINE STREQUAL "ANYCRLF") 441IF(PCRE2_NEWLINE STREQUAL "NUL") 442 SET(NEWLINE_DEFAULT "6") 443ENDIF(PCRE2_NEWLINE STREQUAL "NUL") 444 445IF(NEWLINE_DEFAULT STREQUAL "") 446 MESSAGE(FATAL_ERROR "The PCRE2_NEWLINE variable must be set to one of the following values: \"LF\", \"CR\", \"CRLF\", \"ANY\", \"ANYCRLF\".") 447ENDIF(NEWLINE_DEFAULT STREQUAL "") 448 449IF(PCRE2_EBCDIC) 450 SET(EBCDIC 1) 451ENDIF(PCRE2_EBCDIC) 452 453IF(PCRE2_EBCDIC_NL25) 454 SET(EBCDIC 1) 455 SET(EBCDIC_NL25 1) 456ENDIF(PCRE2_EBCDIC_NL25) 457 458# Output files 459 460CONFIGURE_FILE(config-cmake.h.in 461 ${PROJECT_BINARY_DIR}/config.h 462 @ONLY) 463 464# Parse version numbers and date out of configure.ac 465 466file(STRINGS ${PROJECT_SOURCE_DIR}/configure.ac 467 configure_lines 468 LIMIT_COUNT 50 # Read only the first 50 lines of the file 469) 470 471set(SEARCHED_VARIABLES "pcre2_major" "pcre2_minor" "pcre2_prerelease" "pcre2_date" 472 "libpcre2_posix_version" "libpcre2_8_version" "libpcre2_16_version" "libpcre2_32_version") 473foreach(configure_line ${configure_lines}) 474 foreach(_substitution_variable ${SEARCHED_VARIABLES}) 475 string(TOUPPER ${_substitution_variable} _substitution_variable_upper) 476 if (NOT ${_substitution_variable_upper}) 477 string(REGEX MATCH "m4_define\\(${_substitution_variable}, *\\[(.*)\\]" MATCHED_STRING ${configure_line}) 478 if (CMAKE_MATCH_1) 479 set(${_substitution_variable_upper} ${CMAKE_MATCH_1}) 480 endif() 481 endif() 482 endforeach() 483endforeach() 484 485macro(PARSE_LIB_VERSION VARIABLE_PREFIX) 486 string(REPLACE ":" ";" ${VARIABLE_PREFIX}_VERSION_LIST ${${VARIABLE_PREFIX}_VERSION}) 487 list(GET ${VARIABLE_PREFIX}_VERSION_LIST 0 ${VARIABLE_PREFIX}_VERSION_CURRENT) 488 list(GET ${VARIABLE_PREFIX}_VERSION_LIST 1 ${VARIABLE_PREFIX}_VERSION_REVISION) 489 list(GET ${VARIABLE_PREFIX}_VERSION_LIST 2 ${VARIABLE_PREFIX}_VERSION_AGE) 490 491 math(EXPR ${VARIABLE_PREFIX}_SOVERSION "${${VARIABLE_PREFIX}_VERSION_CURRENT} - ${${VARIABLE_PREFIX}_VERSION_AGE}") 492 math(EXPR ${VARIABLE_PREFIX}_MACHO_COMPATIBILITY_VERSION "${${VARIABLE_PREFIX}_VERSION_CURRENT} + 1") 493 math(EXPR ${VARIABLE_PREFIX}_MACHO_CURRENT_VERSION "${${VARIABLE_PREFIX}_VERSION_CURRENT} + 1") 494 set(${VARIABLE_PREFIX}_MACHO_CURRENT_VERSION "${${VARIABLE_PREFIX}_MACHO_CURRENT_VERSION}.${${VARIABLE_PREFIX}_VERSION_REVISION}}") 495 set(${VARIABLE_PREFIX}_VERSION "${${VARIABLE_PREFIX}_SOVERSION}.${${VARIABLE_PREFIX}_VERSION_AGE}.${${VARIABLE_PREFIX}_VERSION_REVISION}") 496endmacro() 497 498PARSE_LIB_VERSION(LIBPCRE2_POSIX) 499PARSE_LIB_VERSION(LIBPCRE2_8) 500PARSE_LIB_VERSION(LIBPCRE2_16) 501PARSE_LIB_VERSION(LIBPCRE2_32) 502 503CONFIGURE_FILE(src/pcre2.h.in 504 ${PROJECT_BINARY_DIR}/pcre2.h 505 @ONLY) 506 507# Make sure to not link debug libs 508# against release libs and vice versa 509IF(WIN32) 510 SET(CMAKE_DEBUG_POSTFIX "d") 511ENDIF(WIN32) 512 513# Generate pkg-config files 514 515SET(PACKAGE_VERSION "${PCRE2_MAJOR}.${PCRE2_MINOR}") 516SET(prefix ${CMAKE_INSTALL_PREFIX}) 517 518SET(exec_prefix "\${prefix}") 519SET(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}") 520SET(includedir "\${prefix}/include") 521IF(WIN32 AND (CMAKE_BUILD_TYPE MATCHES Debug)) 522 SET(LIB_POSTFIX ${CMAKE_DEBUG_POSTFIX}) 523ENDIF() 524CONFIGURE_FILE(libpcre2-posix.pc.in libpcre2-posix.pc @ONLY) 525SET(pkg_config_files ${pkg_config_files} "${CMAKE_CURRENT_BINARY_DIR}/libpcre2-posix.pc") 526 527IF(PCRE2_BUILD_PCRE2_8) 528 CONFIGURE_FILE(libpcre2-8.pc.in libpcre2-8.pc @ONLY) 529 SET(pkg_config_files ${pkg_config_files} "${CMAKE_CURRENT_BINARY_DIR}/libpcre2-8.pc") 530 SET(enable_pcre2_8 "yes") 531ELSE() 532 SET(enable_pcre2_8 "no") 533ENDIF() 534 535IF(PCRE2_BUILD_PCRE2_16) 536 CONFIGURE_FILE(libpcre2-16.pc.in libpcre2-16.pc @ONLY) 537 SET(pkg_config_files ${pkg_config_files} "${CMAKE_CURRENT_BINARY_DIR}/libpcre2-16.pc") 538 SET(enable_pcre2_16 "yes") 539ELSE() 540 SET(enable_pcre2_16 "no") 541ENDIF() 542 543IF(PCRE2_BUILD_PCRE2_32) 544 CONFIGURE_FILE(libpcre2-32.pc.in libpcre2-32.pc @ONLY) 545 SET(pkg_config_files ${pkg_config_files} "${CMAKE_CURRENT_BINARY_DIR}/libpcre2-32.pc") 546 SET(enable_pcre2_32 "yes") 547ELSE() 548 SET(enable_pcre2_32 "no") 549ENDIF() 550 551CONFIGURE_FILE(pcre2-config.in pcre2-config @ONLY) 552 553# Character table generation 554 555OPTION(PCRE2_REBUILD_CHARTABLES "Rebuild char tables" OFF) 556IF(PCRE2_REBUILD_CHARTABLES) 557 ADD_EXECUTABLE(pcre2_dftables src/pcre2_dftables.c) 558 ADD_CUSTOM_COMMAND( 559 COMMENT "Generating character tables (pcre2_chartables.c) for current locale" 560 DEPENDS pcre2_dftables 561 COMMAND pcre2_dftables 562 ARGS ${PROJECT_BINARY_DIR}/pcre2_chartables.c 563 OUTPUT ${PROJECT_BINARY_DIR}/pcre2_chartables.c 564 ) 565ELSE(PCRE2_REBUILD_CHARTABLES) 566 CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/src/pcre2_chartables.c.dist 567 ${PROJECT_BINARY_DIR}/pcre2_chartables.c 568 COPYONLY) 569ENDIF(PCRE2_REBUILD_CHARTABLES) 570 571# Source code 572 573SET(PCRE2_HEADERS ${PROJECT_BINARY_DIR}/pcre2.h) 574 575SET(PCRE2_SOURCES 576 src/pcre2_auto_possess.c 577 ${PROJECT_BINARY_DIR}/pcre2_chartables.c 578 src/pcre2_compile.c 579 src/pcre2_config.c 580 src/pcre2_context.c 581 src/pcre2_convert.c 582 src/pcre2_dfa_match.c 583 src/pcre2_error.c 584 src/pcre2_extuni.c 585 src/pcre2_find_bracket.c 586 src/pcre2_jit_compile.c 587 src/pcre2_maketables.c 588 src/pcre2_match.c 589 src/pcre2_match_data.c 590 src/pcre2_newline.c 591 src/pcre2_ord2utf.c 592 src/pcre2_pattern_info.c 593 src/pcre2_script_run.c 594 src/pcre2_serialize.c 595 src/pcre2_string_utils.c 596 src/pcre2_study.c 597 src/pcre2_substitute.c 598 src/pcre2_substring.c 599 src/pcre2_tables.c 600 src/pcre2_ucd.c 601 src/pcre2_valid_utf.c 602 src/pcre2_xclass.c 603) 604 605SET(PCRE2POSIX_HEADERS src/pcre2posix.h) 606SET(PCRE2POSIX_SOURCES src/pcre2posix.c) 607 608IF(MINGW AND BUILD_SHARED_LIBS) 609 IF (EXISTS ${PROJECT_SOURCE_DIR}/pcre2.rc) 610 ADD_CUSTOM_COMMAND(OUTPUT ${PROJECT_SOURCE_DIR}/pcre2.o 611 PRE-LINK 612 COMMAND windres ARGS pcre2.rc pcre2.o 613 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} 614 COMMENT Using pcre2 coff info in mingw build) 615 SET(PCRE2_SOURCES ${PCRE2_SOURCES} ${PROJECT_SOURCE_DIR}/pcre2.o) 616 ENDIF(EXISTS ${PROJECT_SOURCE_DIR}/pcre2.rc) 617 618 IF (EXISTS ${PROJECT_SOURCE_DIR}/pcre2posix.rc) 619 ADD_CUSTOM_COMMAND(OUTPUT ${PROJECT_SOURCE_DIR}/pcre2posix.o 620 PRE-LINK 621 COMMAND windres ARGS pcre2posix.rc pcre2posix.o 622 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} 623 COMMENT Using pcre2posix coff info in mingw build) 624 SET(PCRE2POSIX_SOURCES ${PCRE2POSIX_SOURCES} ${PROJECT_SOURCE_DIR}/pcre2posix.o) 625 ENDIF(EXISTS ${PROJECT_SOURCE_DIR}/pcre2posix.rc) 626ENDIF(MINGW AND BUILD_SHARED_LIBS) 627 628IF(MSVC AND BUILD_SHARED_LIBS) 629 IF (EXISTS ${PROJECT_SOURCE_DIR}/pcre2.rc) 630 SET(PCRE2_SOURCES ${PCRE2_SOURCES} pcre2.rc) 631 ENDIF(EXISTS ${PROJECT_SOURCE_DIR}/pcre2.rc) 632 633 IF (EXISTS ${PROJECT_SOURCE_DIR}/pcre2posix.rc) 634 SET(PCRE2POSIX_SOURCES ${PCRE2POSIX_SOURCES} pcre2posix.rc) 635 ENDIF (EXISTS ${PROJECT_SOURCE_DIR}/pcre2posix.rc) 636ENDIF(MSVC AND BUILD_SHARED_LIBS) 637 638# Fix static compilation with MSVC: https://bugs.exim.org/show_bug.cgi?id=1681 639# This code was taken from the CMake wiki, not from WebM. 640 641IF(MSVC AND PCRE2_STATIC_RUNTIME) 642 MESSAGE(STATUS "** MSVC and PCRE2_STATIC_RUNTIME: modifying compiler flags to use static runtime library") 643 foreach(flag_var 644 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE 645 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO) 646 string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") 647 endforeach() 648ENDIF(MSVC AND PCRE2_STATIC_RUNTIME) 649 650# Build setup 651 652ADD_DEFINITIONS(-DHAVE_CONFIG_H) 653 654IF(MSVC) 655 ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS) 656ENDIF(MSVC) 657 658SET(CMAKE_INCLUDE_CURRENT_DIR 1) 659 660SET(targets) 661 662# 8-bit library 663 664IF(PCRE2_BUILD_PCRE2_8) 665 IF(BUILD_STATIC_LIBS) 666 ADD_LIBRARY(pcre2-8-static STATIC ${PCRE2_HEADERS} ${PCRE2_SOURCES} ${PROJECT_BINARY_DIR}/config.h) 667 SET_TARGET_PROPERTIES(pcre2-8-static PROPERTIES 668 COMPILE_DEFINITIONS PCRE2_CODE_UNIT_WIDTH=8 669 MACHO_COMPATIBILITY_VERSION "${LIBPCRE2_8_MACHO_COMPATIBILITY_VERSION}" 670 MACHO_CURRENT_VERSION "${LIBPCRE2_8_MACHO_CURRENT_VERSION}" 671 VERSION ${LIBPCRE2_8_VERSION} 672 SOVERSION ${LIBPCRE2_8_SOVERSION}) 673 TARGET_COMPILE_DEFINITIONS(pcre2-8-static PUBLIC PCRE2_STATIC) 674 SET(targets ${targets} pcre2-8-static) 675 ADD_LIBRARY(pcre2-posix-static STATIC ${PCRE2POSIX_HEADERS} ${PCRE2POSIX_SOURCES}) 676 SET_TARGET_PROPERTIES(pcre2-posix-static PROPERTIES 677 COMPILE_DEFINITIONS PCRE2_CODE_UNIT_WIDTH=8 678 MACHO_COMPATIBILITY_VERSION "${LIBPCRE2_POSIX_MACHO_COMPATIBILITY_VERSION}" 679 MACHO_CURRENT_VERSION "${LIBPCRE2_POSIX_MACHO_CURRENT_VERSION}" 680 VERSION ${LIBPCRE2_POSIX_VERSION} 681 SOVERSION ${LIBPCRE2_POSIX_SOVERSION}) 682 TARGET_LINK_LIBRARIES(pcre2-posix-static pcre2-8-static) 683 TARGET_COMPILE_DEFINITIONS(pcre2-posix-static PUBLIC PCRE2_STATIC) 684 SET(targets ${targets} pcre2-posix-static) 685 686 IF(MSVC) 687 SET_TARGET_PROPERTIES(pcre2-8-static PROPERTIES OUTPUT_NAME pcre2-8-static) 688 SET_TARGET_PROPERTIES(pcre2-posix-static PROPERTIES OUTPUT_NAME pcre2-posix-static) 689 ELSE(MSVC) 690 SET_TARGET_PROPERTIES(pcre2-8-static PROPERTIES OUTPUT_NAME pcre2-8) 691 SET_TARGET_PROPERTIES(pcre2-posix-static PROPERTIES OUTPUT_NAME pcre2-posix) 692 ENDIF(MSVC) 693 IF(PCRE2_STATIC_PIC) 694 SET_TARGET_PROPERTIES(pcre2-8-static pcre2-posix-static PROPERTIES POSITION_INDEPENDENT_CODE 1) 695 ENDIF(PCRE2_STATIC_PIC) 696 ENDIF(BUILD_STATIC_LIBS) 697 698 IF(BUILD_SHARED_LIBS) 699 ADD_LIBRARY(pcre2-8-shared SHARED ${PCRE2_HEADERS} ${PCRE2_SOURCES} ${PROJECT_BINARY_DIR}/config.h) 700 SET_TARGET_PROPERTIES(pcre2-8-shared PROPERTIES 701 COMPILE_DEFINITIONS PCRE2_CODE_UNIT_WIDTH=8 702 MACHO_COMPATIBILITY_VERSION "${LIBPCRE2_8_MACHO_COMPATIBILITY_VERSION}" 703 MACHO_CURRENT_VERSION "${LIBPCRE2_8_MACHO_CURRENT_VERSION}" 704 VERSION ${LIBPCRE2_8_VERSION} 705 SOVERSION ${LIBPCRE2_8_SOVERSION} 706 OUTPUT_NAME pcre2-8) 707 SET(targets ${targets} pcre2-8-shared) 708 ADD_LIBRARY(pcre2-posix-shared SHARED ${PCRE2POSIX_HEADERS} ${PCRE2POSIX_SOURCES}) 709 SET_TARGET_PROPERTIES(pcre2-posix-shared PROPERTIES 710 COMPILE_DEFINITIONS PCRE2_CODE_UNIT_WIDTH=8 711 MACHO_COMPATIBILITY_VERSION "${LIBPCRE2_POSIX_MACHO_COMPATIBILITY_VERSION}" 712 MACHO_CURRENT_VERSION "${LIBPCRE2_POSIX_MACHO_CURRENT_VERSION}" 713 VERSION ${LIBPCRE2_POSIX_VERSION} 714 SOVERSION ${LIBPCRE2_POSIX_SOVERSION} 715 OUTPUT_NAME pcre2-posix) 716 TARGET_LINK_LIBRARIES(pcre2-posix-shared pcre2-8-shared) 717 SET(targets ${targets} pcre2-posix-shared) 718 719 IF(MINGW) 720 IF(NON_STANDARD_LIB_PREFIX) 721 SET_TARGET_PROPERTIES(pcre2-8-shared pcre2-posix-shared PROPERTIES PREFIX "") 722 ENDIF(NON_STANDARD_LIB_PREFIX) 723 IF(NON_STANDARD_LIB_SUFFIX) 724 SET_TARGET_PROPERTIES(pcre2-8-shared pcre2-posix-shared PROPERTIES SUFFIX "-0.dll") 725 ENDIF(NON_STANDARD_LIB_SUFFIX) 726 ENDIF(MINGW) 727 ENDIF(BUILD_SHARED_LIBS) 728 729 IF(BUILD_STATIC_LIBS) 730 ADD_LIBRARY(pcre2-8 ALIAS pcre2-8-static) 731 ADD_LIBRARY(pcre2-posix ALIAS pcre2-posix-static) 732 ELSE(BUILD_STATIC_LIBS) 733 ADD_LIBRARY(pcre2-8 ALIAS pcre2-8-shared) 734 ADD_LIBRARY(pcre2-posix ALIAS pcre2-posix-shared) 735 ENDIF(BUILD_STATIC_LIBS) 736ENDIF(PCRE2_BUILD_PCRE2_8) 737 738# 16-bit library 739 740IF(PCRE2_BUILD_PCRE2_16) 741 IF(BUILD_STATIC_LIBS) 742 ADD_LIBRARY(pcre2-16-static STATIC ${PCRE2_HEADERS} ${PCRE2_SOURCES} ${PROJECT_BINARY_DIR}/config.h) 743 SET_TARGET_PROPERTIES(pcre2-16-static PROPERTIES 744 COMPILE_DEFINITIONS PCRE2_CODE_UNIT_WIDTH=16 745 MACHO_COMPATIBILITY_VERSION "${LIBPCRE2_32_MACHO_COMPATIBILITY_VERSION}" 746 MACHO_CURRENT_VERSION "${LIBPCRE2_32_MACHO_CURRENT_VERSION}" 747 VERSION ${LIBPCRE2_16_VERSION} 748 SOVERSION ${LIBPCRE2_16_SOVERSION}) 749 TARGET_COMPILE_DEFINITIONS(pcre2-16-static PUBLIC PCRE2_STATIC) 750 SET(targets ${targets} pcre2-16-static) 751 752 IF(MSVC) 753 SET_TARGET_PROPERTIES(pcre2-16-static PROPERTIES OUTPUT_NAME pcre2-16-static) 754 ELSE(MSVC) 755 SET_TARGET_PROPERTIES(pcre2-16-static PROPERTIES OUTPUT_NAME pcre2-16) 756 ENDIF(MSVC) 757 IF(PCRE2_STATIC_PIC) 758 SET_TARGET_PROPERTIES(pcre2-16-static PROPERTIES POSITION_INDEPENDENT_CODE 1) 759 ENDIF(PCRE2_STATIC_PIC) 760 ENDIF(BUILD_STATIC_LIBS) 761 762 IF(BUILD_SHARED_LIBS) 763 ADD_LIBRARY(pcre2-16-shared SHARED ${PCRE2_HEADERS} ${PCRE2_SOURCES} ${PROJECT_BINARY_DIR}/config.h) 764 SET_TARGET_PROPERTIES(pcre2-16-shared PROPERTIES 765 COMPILE_DEFINITIONS PCRE2_CODE_UNIT_WIDTH=16 766 MACHO_COMPATIBILITY_VERSION "${LIBPCRE2_32_MACHO_COMPATIBILITY_VERSION}" 767 MACHO_CURRENT_VERSION "${LIBPCRE2_32_MACHO_CURRENT_VERSION}" 768 VERSION ${LIBPCRE2_16_VERSION} 769 SOVERSION ${LIBPCRE2_16_SOVERSION} 770 OUTPUT_NAME pcre2-16) 771 SET(targets ${targets} pcre2-16-shared) 772 773 IF(MINGW) 774 IF(NON_STANDARD_LIB_PREFIX) 775 SET_TARGET_PROPERTIES(pcre2-16-shared PROPERTIES PREFIX "") 776 ENDIF(NON_STANDARD_LIB_PREFIX) 777 IF(NON_STANDARD_LIB_SUFFIX) 778 SET_TARGET_PROPERTIES(pcre2-16-shared PROPERTIES SUFFIX "-0.dll") 779 ENDIF(NON_STANDARD_LIB_SUFFIX) 780 ENDIF(MINGW) 781 ENDIF(BUILD_SHARED_LIBS) 782 783 IF(BUILD_STATIC_LIBS) 784 ADD_LIBRARY(pcre2-16 ALIAS pcre2-16-static) 785 ELSE(BUILD_STATIC_LIBS) 786 ADD_LIBRARY(pcre2-16 ALIAS pcre2-16-shared) 787 ENDIF(BUILD_STATIC_LIBS) 788ENDIF(PCRE2_BUILD_PCRE2_16) 789 790# 32-bit library 791 792IF(PCRE2_BUILD_PCRE2_32) 793 IF(BUILD_STATIC_LIBS) 794 ADD_LIBRARY(pcre2-32-static STATIC ${PCRE2_HEADERS} ${PCRE2_SOURCES} ${PROJECT_BINARY_DIR}/config.h) 795 SET_TARGET_PROPERTIES(pcre2-32-static PROPERTIES 796 COMPILE_DEFINITIONS PCRE2_CODE_UNIT_WIDTH=32 797 MACHO_COMPATIBILITY_VERSION "${LIBPCRE2_32_MACHO_COMPATIBILITY_VERSION}" 798 MACHO_CURRENT_VERSION "${LIBPCRE2_32_MACHO_CURRENT_VERSION}" 799 VERSION ${LIBPCRE2_32_VERSION} 800 SOVERSION ${LIBPCRE2_32_SOVERSION}) 801 TARGET_COMPILE_DEFINITIONS(pcre2-32-static PUBLIC PCRE2_STATIC) 802 SET(targets ${targets} pcre2-32-static) 803 804 IF(MSVC) 805 SET_TARGET_PROPERTIES(pcre2-32-static PROPERTIES OUTPUT_NAME pcre2-32-static) 806 ELSE(MSVC) 807 SET_TARGET_PROPERTIES(pcre2-32-static PROPERTIES OUTPUT_NAME pcre2-32) 808 ENDIF(MSVC) 809 IF(PCRE2_STATIC_PIC) 810 SET_TARGET_PROPERTIES(pcre2-32-static PROPERTIES POSITION_INDEPENDENT_CODE 1) 811 ENDIF(PCRE2_STATIC_PIC) 812 ENDIF(BUILD_STATIC_LIBS) 813 814 IF(BUILD_SHARED_LIBS) 815 ADD_LIBRARY(pcre2-32-shared SHARED ${PCRE2_HEADERS} ${PCRE2_SOURCES} ${PROJECT_BINARY_DIR}/config.h) 816 SET_TARGET_PROPERTIES(pcre2-32-shared PROPERTIES 817 COMPILE_DEFINITIONS PCRE2_CODE_UNIT_WIDTH=32 818 MACHO_COMPATIBILITY_VERSION "${LIBPCRE2_32_MACHO_COMPATIBILITY_VERSION}" 819 MACHO_CURRENT_VERSION "${LIBPCRE2_32_MACHO_CURRENT_VERSION}" 820 VERSION ${LIBPCRE2_32_VERSION} 821 SOVERSION ${LIBPCRE2_32_SOVERSION} 822 OUTPUT_NAME pcre2-32) 823 SET(targets ${targets} pcre2-32-shared) 824 825 IF(MINGW) 826 IF(NON_STANDARD_LIB_PREFIX) 827 SET_TARGET_PROPERTIES(pcre2-32-shared PROPERTIES PREFIX "") 828 ENDIF(NON_STANDARD_LIB_PREFIX) 829 IF(NON_STANDARD_LIB_SUFFIX) 830 SET_TARGET_PROPERTIES(pcre2-32-shared PROPERTIES SUFFIX "-0.dll") 831 ENDIF(NON_STANDARD_LIB_SUFFIX) 832 ENDIF(MINGW) 833 ENDIF(BUILD_SHARED_LIBS) 834 835 IF(BUILD_STATIC_LIBS) 836 ADD_LIBRARY(pcre2-32 ALIAS pcre2-32-static) 837 ELSE(BUILD_STATIC_LIBS) 838 ADD_LIBRARY(pcre2-32 ALIAS pcre2-32-shared) 839 ENDIF(BUILD_STATIC_LIBS) 840ENDIF(PCRE2_BUILD_PCRE2_32) 841 842# Executables 843 844IF(PCRE2_BUILD_PCRE2GREP) 845 ADD_EXECUTABLE(pcre2grep src/pcre2grep.c) 846 SET_PROPERTY(TARGET pcre2grep 847 PROPERTY COMPILE_DEFINITIONS PCRE2_CODE_UNIT_WIDTH=8) 848 SET(targets ${targets} pcre2grep) 849 TARGET_LINK_LIBRARIES(pcre2grep pcre2-posix ${PCRE2GREP_LIBS}) 850ENDIF(PCRE2_BUILD_PCRE2GREP) 851 852# Testing 853 854IF(PCRE2_BUILD_TESTS) 855 ENABLE_TESTING() 856 857 SET(PCRE2TEST_SOURCES src/pcre2test.c) 858 859 IF(MSVC) 860 # This is needed to avoid a stack overflow error in the standard tests. The 861 # flag should be indicated with a forward-slash instead of a hyphen, but 862 # then CMake treats it as a file path. 863 SET(PCRE2TEST_LINKER_FLAGS -STACK:2500000) 864 ENDIF(MSVC) 865 866 ADD_EXECUTABLE(pcre2test ${PCRE2TEST_SOURCES}) 867 SET(targets ${targets} pcre2test) 868 IF(PCRE2_BUILD_PCRE2_8) 869 LIST(APPEND PCRE2TEST_LIBS pcre2-posix pcre2-8) 870 ENDIF(PCRE2_BUILD_PCRE2_8) 871 IF(PCRE2_BUILD_PCRE2_16) 872 LIST(APPEND PCRE2TEST_LIBS pcre2-16) 873 ENDIF(PCRE2_BUILD_PCRE2_16) 874 IF(PCRE2_BUILD_PCRE2_32) 875 LIST(APPEND PCRE2TEST_LIBS pcre2-32) 876 ENDIF(PCRE2_BUILD_PCRE2_32) 877 TARGET_LINK_LIBRARIES(pcre2test ${PCRE2TEST_LIBS} ${PCRE2TEST_LINKER_FLAGS}) 878 879 IF(PCRE2_SUPPORT_JIT) 880 ADD_EXECUTABLE(pcre2_jit_test src/pcre2_jit_test.c) 881 SET(targets ${targets} pcre2_jit_test) 882 SET(PCRE2_JIT_TEST_LIBS ) 883 IF(PCRE2_BUILD_PCRE2_8) 884 LIST(APPEND PCRE2_JIT_TEST_LIBS pcre2-8) 885 ENDIF(PCRE2_BUILD_PCRE2_8) 886 IF(PCRE2_BUILD_PCRE2_16) 887 LIST(APPEND PCRE2_JIT_TEST_LIBS pcre2-16) 888 ENDIF(PCRE2_BUILD_PCRE2_16) 889 IF(PCRE2_BUILD_PCRE2_32) 890 LIST(APPEND PCRE2_JIT_TEST_LIBS pcre2-32) 891 ENDIF(PCRE2_BUILD_PCRE2_32) 892 TARGET_LINK_LIBRARIES(pcre2_jit_test ${PCRE2_JIT_TEST_LIBS}) 893 ENDIF(PCRE2_SUPPORT_JIT) 894 895 # exes in Debug location tested by the RunTest and RunGrepTest shell scripts 896 # via "make test" 897 898 # The commented out code below provokes a warning about future removal 899 # of the facility, and requires policy CMP0026 to be set to "OLD". I have 900 # got fed-up with the warnings, but my plea for help on the mailing list 901 # produced no response. So, I've hacked. The new code below seems to work on 902 # Linux. 903 904# IF(PCRE2_BUILD_PCRE2GREP) 905# GET_TARGET_PROPERTY(PCRE2GREP_EXE pcre2grep DEBUG_LOCATION) 906# ENDIF(PCRE2_BUILD_PCRE2GREP) 907# 908# GET_TARGET_PROPERTY(PCRE2TEST_EXE pcre2test DEBUG_LOCATION) 909 910 IF(PCRE2_BUILD_PCRE2GREP) 911 SET(PCRE2GREP_EXE $<TARGET_FILE:pcre2grep>) 912 ENDIF(PCRE2_BUILD_PCRE2GREP) 913 914 SET(PCRE2TEST_EXE $<TARGET_FILE:pcre2test>) 915 916 917# ================================================= 918 # Write out a CTest configuration file 919 # 920 FILE(WRITE ${PROJECT_BINARY_DIR}/CTestCustom.ctest 921 "# This is a generated file. 922MESSAGE(\"When testing is complete, review test output in the 923\\\"${PROJECT_BINARY_DIR}/Testing/Temporary\\\" folder.\") 924MESSAGE(\" \") 925") 926 927 FILE(WRITE ${PROJECT_BINARY_DIR}/pcre2_test.sh 928 "#! /bin/sh 929# This is a generated file. 930. ${PROJECT_SOURCE_DIR}/RunTest 931if test \"$?\" != \"0\"; then exit 1; fi 932# End 933") 934 935 IF(UNIX) 936 ADD_TEST(pcre2_test sh ${PROJECT_BINARY_DIR}/pcre2_test.sh) 937 ENDIF(UNIX) 938 939 IF(PCRE2_BUILD_PCRE2GREP) 940 FILE(WRITE ${PROJECT_BINARY_DIR}/pcre2_grep_test.sh 941 "#! /bin/sh 942# This is a generated file. 943. ${PROJECT_SOURCE_DIR}/RunGrepTest 944if test \"$?\" != \"0\"; then exit 1; fi 945# End 946") 947 948 IF(UNIX) 949 ADD_TEST(pcre2_grep_test sh ${PROJECT_BINARY_DIR}/pcre2_grep_test.sh) 950 ENDIF(UNIX) 951 ENDIF(PCRE2_BUILD_PCRE2GREP) 952 953 IF(WIN32) 954 # Provide environment for executing the bat file version of RunTest 955 FILE(TO_NATIVE_PATH ${PROJECT_SOURCE_DIR} winsrc) 956 FILE(TO_NATIVE_PATH ${PROJECT_BINARY_DIR} winbin) 957 FILE(TO_NATIVE_PATH ${PCRE2TEST_EXE} winexe) 958 959 FILE(WRITE ${PROJECT_BINARY_DIR}/pcre2_test.bat 960 "\@REM This is a generated file. 961\@echo off 962setlocal 963SET srcdir=\"${winsrc}\" 964# The next line was replaced by the following one after a user comment. 965# SET pcre2test=\"${winexe}\" 966SET pcre2test=\"${winbin}\\pcre2test.exe\" 967if not [%CMAKE_CONFIG_TYPE%]==[] SET pcre2test=\"${winbin}\\%CMAKE_CONFIG_TYPE%\\pcre2test.exe\" 968call %srcdir%\\RunTest.Bat 969if errorlevel 1 exit /b 1 970echo RunTest.bat tests successfully completed 971") 972 973 ADD_TEST(NAME pcre2_test_bat 974 COMMAND pcre2_test.bat) 975 SET_TESTS_PROPERTIES(pcre2_test_bat PROPERTIES 976 PASS_REGULAR_EXPRESSION "RunTest\\.bat tests successfully completed") 977 978 IF("$ENV{OSTYPE}" STREQUAL "msys") 979 # Both the sh and bat file versions of RunTest are run if make test is used 980 # in msys 981 ADD_TEST(pcre2_test_sh sh.exe ${PROJECT_BINARY_DIR}/pcre2_test.sh) 982 IF(PCRE2_BUILD_PCRE2GREP) 983 ADD_TEST(pcre2_grep_test sh.exe ${PROJECT_BINARY_DIR}/pcre2_grep_test.sh) 984 ENDIF(PCRE2_BUILD_PCRE2GREP) 985 ENDIF("$ENV{OSTYPE}" STREQUAL "msys") 986 ENDIF(WIN32) 987 988 # Changed to accommodate testing whichever location was just built 989 990 IF(PCRE2_SUPPORT_JIT) 991 ADD_TEST(pcre2_jit_test pcre2_jit_test) 992 ENDIF(PCRE2_SUPPORT_JIT) 993 994ENDIF(PCRE2_BUILD_TESTS) 995 996# Installation 997 998SET(CMAKE_INSTALL_ALWAYS 1) 999 1000INSTALL(TARGETS ${targets} 1001 RUNTIME DESTINATION bin 1002 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} 1003 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) 1004INSTALL(FILES ${pkg_config_files} DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) 1005INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/pcre2-config" 1006 DESTINATION bin 1007 # Set 0755 permissions 1008 PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) 1009 1010INSTALL(FILES ${PCRE2_HEADERS} ${PCRE2POSIX_HEADERS} DESTINATION include) 1011 1012# CMake config files. 1013set(PCRE2_CONFIG_IN ${CMAKE_CURRENT_SOURCE_DIR}/cmake/pcre2-config.cmake.in) 1014set(PCRE2_CONFIG_OUT ${CMAKE_CURRENT_BINARY_DIR}/cmake/pcre2-config.cmake) 1015configure_file(${PCRE2_CONFIG_IN} ${PCRE2_CONFIG_OUT} @ONLY) 1016set(PCRE2_CONFIG_VERSION_IN ${CMAKE_CURRENT_SOURCE_DIR}/cmake/pcre2-config-version.cmake.in) 1017set(PCRE2_CONFIG_VERSION_OUT ${CMAKE_CURRENT_BINARY_DIR}/cmake/pcre2-config-version.cmake) 1018configure_file(${PCRE2_CONFIG_VERSION_IN} ${PCRE2_CONFIG_VERSION_OUT} @ONLY) 1019install(FILES ${PCRE2_CONFIG_OUT} ${PCRE2_CONFIG_VERSION_OUT} DESTINATION cmake) 1020 1021FILE(GLOB html ${PROJECT_SOURCE_DIR}/doc/html/*.html) 1022FILE(GLOB man1 ${PROJECT_SOURCE_DIR}/doc/*.1) 1023FILE(GLOB man3 ${PROJECT_SOURCE_DIR}/doc/*.3) 1024 1025FOREACH(man ${man3}) 1026 GET_FILENAME_COMPONENT(man_tmp ${man} NAME) 1027 SET(man3_new ${man3} ${man}) 1028ENDFOREACH(man ${man3}) 1029SET(man3 ${man3_new}) 1030 1031INSTALL(FILES ${man1} DESTINATION man/man1) 1032INSTALL(FILES ${man3} DESTINATION man/man3) 1033INSTALL(FILES ${html} DESTINATION share/doc/pcre2/html) 1034 1035IF(MSVC AND INSTALL_MSVC_PDB) 1036 INSTALL(FILES ${PROJECT_BINARY_DIR}/pcre2.pdb 1037 ${PROJECT_BINARY_DIR}/pcre2posix.pdb 1038 DESTINATION bin 1039 CONFIGURATIONS RelWithDebInfo) 1040 INSTALL(FILES ${PROJECT_BINARY_DIR}/pcre2d.pdb 1041 ${PROJECT_BINARY_DIR}/pcre2posixd.pdb 1042 DESTINATION bin 1043 CONFIGURATIONS Debug) 1044ENDIF(MSVC AND INSTALL_MSVC_PDB) 1045 1046# Help, only for nice output 1047IF(BUILD_STATIC_LIBS) 1048 SET(BUILD_STATIC_LIBS ON) 1049ELSE(BUILD_STATIC_LIBS) 1050 SET(BUILD_STATIC_LIBS OFF) 1051ENDIF(BUILD_STATIC_LIBS) 1052 1053IF(PCRE2_HEAP_MATCH_RECURSE) 1054 MESSAGE(WARNING "HEAP_MATCH_RECURSE is obsolete and does nothing.") 1055ENDIF(PCRE2_HEAP_MATCH_RECURSE) 1056 1057IF(PCRE2_SHOW_REPORT) 1058 STRING(TOUPPER "${CMAKE_BUILD_TYPE}" buildtype) 1059 IF (CMAKE_C_FLAGS) 1060 SET(cfsp " ") 1061 ENDIF(CMAKE_C_FLAGS) 1062 MESSAGE(STATUS "") 1063 MESSAGE(STATUS "") 1064 MESSAGE(STATUS "PCRE2-${PCRE2_MAJOR}.${PCRE2_MINOR} configuration summary:") 1065 MESSAGE(STATUS "") 1066 MESSAGE(STATUS " Install prefix .................. : ${CMAKE_INSTALL_PREFIX}") 1067 MESSAGE(STATUS " C compiler ...................... : ${CMAKE_C_COMPILER}") 1068 MESSAGE(STATUS " C compiler flags ................ : ${CMAKE_C_FLAGS}${cfsp}${CMAKE_C_FLAGS_${buildtype}}") 1069 MESSAGE(STATUS "") 1070 MESSAGE(STATUS " Build 8 bit PCRE2 library ....... : ${PCRE2_BUILD_PCRE2_8}") 1071 MESSAGE(STATUS " Build 16 bit PCRE2 library ...... : ${PCRE2_BUILD_PCRE2_16}") 1072 MESSAGE(STATUS " Build 32 bit PCRE2 library ...... : ${PCRE2_BUILD_PCRE2_32}") 1073 MESSAGE(STATUS " Enable JIT compiling support .... : ${PCRE2_SUPPORT_JIT}") 1074 MESSAGE(STATUS " Use SELinux allocator in JIT .... : ${PCRE2_SUPPORT_JIT_SEALLOC}") 1075 MESSAGE(STATUS " Enable Unicode support .......... : ${PCRE2_SUPPORT_UNICODE}") 1076 MESSAGE(STATUS " Newline char/sequence ........... : ${PCRE2_NEWLINE}") 1077 MESSAGE(STATUS " \\R matches only ANYCRLF ......... : ${PCRE2_SUPPORT_BSR_ANYCRLF}") 1078 MESSAGE(STATUS " \\C is disabled .................. : ${PCRE2_NEVER_BACKSLASH_C}") 1079 MESSAGE(STATUS " EBCDIC coding ................... : ${PCRE2_EBCDIC}") 1080 MESSAGE(STATUS " EBCDIC coding with NL=0x25 ...... : ${PCRE2_EBCDIC_NL25}") 1081 MESSAGE(STATUS " Rebuild char tables ............. : ${PCRE2_REBUILD_CHARTABLES}") 1082 MESSAGE(STATUS " Internal link size .............. : ${PCRE2_LINK_SIZE}") 1083 MESSAGE(STATUS " Parentheses nest limit .......... : ${PCRE2_PARENS_NEST_LIMIT}") 1084 MESSAGE(STATUS " Heap limit ...................... : ${PCRE2_HEAP_LIMIT}") 1085 MESSAGE(STATUS " Match limit ..................... : ${PCRE2_MATCH_LIMIT}") 1086 MESSAGE(STATUS " Match depth limit ............... : ${PCRE2_MATCH_LIMIT_DEPTH}") 1087 MESSAGE(STATUS " Build shared libs ............... : ${BUILD_SHARED_LIBS}") 1088 MESSAGE(STATUS " Build static libs ............... : ${BUILD_STATIC_LIBS}") 1089 MESSAGE(STATUS " with PIC enabled ............. : ${PCRE2_STATIC_PIC}") 1090 MESSAGE(STATUS " Build pcre2grep ................. : ${PCRE2_BUILD_PCRE2GREP}") 1091 MESSAGE(STATUS " Enable JIT in pcre2grep ......... : ${PCRE2GREP_SUPPORT_JIT}") 1092 MESSAGE(STATUS " Enable callouts in pcre2grep .... : ${PCRE2GREP_SUPPORT_CALLOUT}") 1093 MESSAGE(STATUS " Enable callout fork in pcre2grep. : ${PCRE2GREP_SUPPORT_CALLOUT_FORK}") 1094 MESSAGE(STATUS " Buffer size for pcre2grep ....... : ${PCRE2GREP_BUFSIZE}") 1095 MESSAGE(STATUS " Build tests (implies pcre2test .. : ${PCRE2_BUILD_TESTS}") 1096 MESSAGE(STATUS " and pcre2grep)") 1097 IF(ZLIB_FOUND) 1098 MESSAGE(STATUS " Link pcre2grep with libz ........ : ${PCRE2_SUPPORT_LIBZ}") 1099 ELSE(ZLIB_FOUND) 1100 MESSAGE(STATUS " Link pcre2grep with libz ........ : Library not found" ) 1101 ENDIF(ZLIB_FOUND) 1102 IF(BZIP2_FOUND) 1103 MESSAGE(STATUS " Link pcre2grep with libbz2 ...... : ${PCRE2_SUPPORT_LIBBZ2}") 1104 ELSE(BZIP2_FOUND) 1105 MESSAGE(STATUS " Link pcre2grep with libbz2 ...... : Library not found" ) 1106 ENDIF(BZIP2_FOUND) 1107 IF(EDITLINE_FOUND) 1108 MESSAGE(STATUS " Link pcre2test with libeditline . : ${PCRE2_SUPPORT_LIBEDIT}") 1109 ELSE(EDITLINE_FOUND) 1110 MESSAGE(STATUS " Link pcre2test with libeditline . : Library not found" ) 1111 ENDIF(EDITLINE_FOUND) 1112 IF(READLINE_FOUND) 1113 MESSAGE(STATUS " Link pcre2test with libreadline . : ${PCRE2_SUPPORT_LIBREADLINE}") 1114 ELSE(READLINE_FOUND) 1115 MESSAGE(STATUS " Link pcre2test with libreadline . : Library not found" ) 1116 ENDIF(READLINE_FOUND) 1117 MESSAGE(STATUS " Support Valgrind .................: ${PCRE2_SUPPORT_VALGRIND}") 1118 IF(PCRE2_DISABLE_PERCENT_ZT) 1119 MESSAGE(STATUS " Use %zu and %td ..................: OFF" ) 1120 ELSE(PCRE2_DISABLE_PERCENT_ZT) 1121 MESSAGE(STATUS " Use %zu and %td ..................: AUTO" ) 1122 ENDIF(PCRE2_DISABLE_PERCENT_ZT) 1123 1124 IF(MINGW AND BUILD_SHARED_LIBS) 1125 MESSAGE(STATUS " Non-standard dll names (prefix) . : ${NON_STANDARD_LIB_PREFIX}") 1126 MESSAGE(STATUS " Non-standard dll names (suffix) . : ${NON_STANDARD_LIB_SUFFIX}") 1127 ENDIF(MINGW AND BUILD_SHARED_LIBS) 1128 1129 IF(MSVC) 1130 MESSAGE(STATUS " Install MSVC .pdb files ..........: ${INSTALL_MSVC_PDB}") 1131 ENDIF(MSVC) 1132 1133 MESSAGE(STATUS "") 1134ENDIF(PCRE2_SHOW_REPORT) 1135 1136# end CMakeLists.txt 1137