1 # CMakeLists.txt 2 # 3 # 4 # This file enables PCRE2 to be built with the CMake configuration and build 5 # tool. Download CMake in source or binary form from http://www.cmake.org/ 6 # Converted to support PCRE2 from the original PCRE file, August 2014. 7 # 8 # Original listfile by Christian Ehrlicher <Ch.Ehrlicher (a] gmx.de> 9 # Refined and expanded by Daniel Richard G. <skunk (a] iSKUNK.ORG> 10 # 2007-09-14 mod by Sheri so 7.4 supported configuration options can be entered 11 # 2007-09-19 Adjusted by PH to retain previous default settings 12 # 2007-12-26 (a) On UNIX, use names libpcre instead of just pcre 13 # (b) Ensure pcretest and pcregrep link with the local library, 14 # not a previously-installed one. 15 # (c) Add PCRE_SUPPORT_LIBREADLINE, PCRE_SUPPORT_LIBZ, and 16 # PCRE_SUPPORT_LIBBZ2. 17 # 2008-01-20 Brought up to date to include several new features by Christian 18 # Ehrlicher. 19 # 2008-01-22 Sheri added options for backward compatibility of library names 20 # when building with minGW: 21 # if "ON", NON_STANDARD_LIB_PREFIX causes shared libraries to 22 # be built without "lib" as prefix. (The libraries will be named 23 # pcre.dll, pcreposix.dll and pcrecpp.dll). 24 # if "ON", NON_STANDARD_LIB_SUFFIX causes shared libraries to 25 # be built with suffix of "-0.dll". (The libraries will be named 26 # libpcre-0.dll, libpcreposix-0.dll and libpcrecpp-0.dll - same names 27 # built by default with Configure and Make. 28 # 2008-01-23 PH removed the automatic build of pcredemo. 29 # 2008-04-22 PH modified READLINE support so it finds NCURSES when needed. 30 # 2008-07-03 PH updated for revised UCP property support (change of files) 31 # 2009-03-23 PH applied Steven Van Ingelgem's patch to change the name 32 # CMAKE_BINARY_DIR to PROJECT_BINARY_DIR so that it works when PCRE 33 # is included within another project. 34 # 2009-03-23 PH applied a modified version of Steven Van Ingelgem's patches to 35 # add options to stop the building of pcregrep and the tests, and 36 # to disable the final configuration report. 37 # 2009-04-11 PH applied Christian Ehrlicher's patch to show compiler flags that 38 # are set by specifying a release type. 39 # 2010-01-02 PH added test for stdint.h 40 # 2010-03-02 PH added test for inttypes.h 41 # 2011-08-01 PH added PCREGREP_BUFSIZE 42 # 2011-08-22 PH added PCRE_SUPPORT_JIT 43 # 2011-09-06 PH modified WIN32 ADD_TEST line as suggested by Sergey Cherepanov 44 # 2011-09-06 PH added PCRE_SUPPORT_PCREGREP_JIT 45 # 2011-10-04 Sheri added support for including coff data in windows shared libraries 46 # compiled with MINGW if pcre.rc and/or pcreposix.rc are placed in 47 # the source dir by the user prior to building 48 # 2011-10-04 Sheri changed various add_test's to use exes' location built instead 49 # of DEBUG location only (likely only matters in MSVC) 50 # 2011-10-04 Sheri added scripts to provide needed variables to RunTest and 51 # RunGrepTest (used for UNIX and Msys) 52 # 2011-10-04 Sheri added scripts to provide needed variables and to execute 53 # RunTest.bat in Win32 (for effortless testing with "make test") 54 # 2011-10-04 Sheri Increased minimum required cmake version 55 # 2012-01-06 PH removed pcre_info.c and added pcre_string_utils.c 56 # 2012-01-10 Zoltan Herczeg added libpcre16 support 57 # 2012-01-13 Stephen Kelly added out of source build support 58 # 2012-01-17 PH applied Stephen Kelly's patch to parse the version data out 59 # of the configure.ac file 60 # 2012-02-26 PH added support for libedit 61 # 2012-09-06 PH added support for PCRE_EBCDIC_NL25 62 # 2012-09-08 ChPe added PCRE32 support 63 # 2012-10-23 PH added support for VALGRIND and GCOV 64 # 2012-12-08 PH added patch from Daniel Richard G to quash some MSVC warnings 65 # 2013-07-01 PH realized that the "support" for GCOV was a total nonsense and 66 # so it has been removed. 67 # 2013-10-08 PH got rid of the "source" command, which is a bash-ism (use ".") 68 # 2013-11-05 PH added support for PARENS_NEST_LIMIT 69 # 2014-08-29 PH converted the file for PCRE2 (which has no C++). 70 # 2015-04-24 PH added support for PCRE2_DEBUG 71 # 2015-07-16 PH updated for new pcre2_find_bracket source module 72 # 2015-08-24 PH correct C_FLAGS setting (patch from Roy Ivy III) 73 # 2015-10=16 PH added support for never-backslash-C 74 # 2016-03-01 PH applied Chris Wilson's patch for MSVC static 75 # 2016-06-24 PH applied Chris Wilson's second patch, putting the first under 76 # a new option instead of being unconditional. 77 78 PROJECT(PCRE2 C) 79 80 # Increased minimum to 2.8.0 to support newer add_test features. Set policy 81 # CMP0026 to avoid warnings for the use of LOCATION in GET_TARGET_PROPERTY. 82 83 CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0) 84 CMAKE_POLICY(SET CMP0026 OLD) 85 86 SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) # for FindReadline.cmake 87 88 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I${PROJECT_SOURCE_DIR}/src") 89 90 # external packages 91 FIND_PACKAGE( BZip2 ) 92 FIND_PACKAGE( ZLIB ) 93 FIND_PACKAGE( Readline ) 94 FIND_PACKAGE( Editline ) 95 96 # Configuration checks 97 98 INCLUDE(CheckIncludeFile) 99 INCLUDE(CheckFunctionExists) 100 INCLUDE(CheckTypeSize) 101 102 CHECK_INCLUDE_FILE(dirent.h HAVE_DIRENT_H) 103 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H) 104 CHECK_INCLUDE_FILE(inttypes.h HAVE_INTTYPES_H) 105 CHECK_INCLUDE_FILE(sys/stat.h HAVE_SYS_STAT_H) 106 CHECK_INCLUDE_FILE(sys/types.h HAVE_SYS_TYPES_H) 107 CHECK_INCLUDE_FILE(unistd.h HAVE_UNISTD_H) 108 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H) 109 110 CHECK_FUNCTION_EXISTS(bcopy HAVE_BCOPY) 111 CHECK_FUNCTION_EXISTS(memmove HAVE_MEMMOVE) 112 CHECK_FUNCTION_EXISTS(strerror HAVE_STRERROR) 113 114 # User-configurable options 115 # 116 # Note: CMakeSetup displays these in alphabetical order, regardless of 117 # the order we use here. 118 119 SET(BUILD_SHARED_LIBS OFF CACHE BOOL 120 "Build shared libraries instead of static ones.") 121 122 OPTION(PCRE2_BUILD_PCRE2_8 "Build 8 bit PCRE2 library" ON) 123 124 OPTION(PCRE2_BUILD_PCRE2_16 "Build 16 bit PCRE2 library" OFF) 125 126 OPTION(PCRE2_BUILD_PCRE2_32 "Build 32 bit PCRE2 library" OFF) 127 128 OPTION(PCRE2_DEBUG "Include debugging code" OFF) 129 130 SET(PCRE2_EBCDIC OFF CACHE BOOL 131 "Use EBCDIC coding instead of ASCII. (This is rarely used outside of mainframe systems.)") 132 133 SET(PCRE2_EBCDIC_NL25 OFF CACHE BOOL 134 "Use 0x25 as EBCDIC NL character instead of 0x15; implies EBCDIC.") 135 136 SET(PCRE2_LINK_SIZE "2" CACHE STRING 137 "Internal link size (2, 3 or 4 allowed). See LINK_SIZE in config.h.in for details.") 138 139 SET(PCRE2_PARENS_NEST_LIMIT "250" CACHE STRING 140 "Default nested parentheses limit. See PARENS_NEST_LIMIT in config.h.in for details.") 141 142 SET(PCRE2_MATCH_LIMIT "10000000" CACHE STRING 143 "Default limit on internal looping. See MATCH_LIMIT in config.h.in for details.") 144 145 SET(PCRE2_MATCH_LIMIT_RECURSION "MATCH_LIMIT" CACHE STRING 146 "Default limit on internal recursion. See MATCH_LIMIT_RECURSION in config.h.in for details.") 147 148 SET(PCRE2GREP_BUFSIZE "20480" CACHE STRING 149 "Buffer size parameter for pcre2grep. See PCRE2GREP_BUFSIZE in config.h.in for details.") 150 151 SET(PCRE2_NEWLINE "LF" CACHE STRING 152 "What to recognize as a newline (one of CR, LF, CRLF, ANY, ANYCRLF).") 153 154 SET(PCRE2_HEAP_MATCH_RECURSE OFF CACHE BOOL 155 "If ON, then don't use stack recursion when matching. See HEAP_MATCH_RECURSE in config.h.in for details.") 156 157 SET(PCRE2_SUPPORT_JIT OFF CACHE BOOL 158 "Enable support for Just-in-time compiling.") 159 160 SET(PCRE2_SUPPORT_PCRE2GREP_JIT ON CACHE BOOL 161 "Enable use of Just-in-time compiling in pcre2grep.") 162 163 SET(PCRE2_SUPPORT_PCRE2GREP_CALLOUT ON CACHE BOOL 164 "Enable callout string support in pcre2grep.") 165 166 SET(PCRE2_SUPPORT_UNICODE ON CACHE BOOL 167 "Enable support for Unicode and UTF-8/UTF-16/UTF-32 encoding.") 168 169 SET(PCRE2_SUPPORT_BSR_ANYCRLF OFF CACHE BOOL 170 "ON=Backslash-R matches only LF CR and CRLF, OFF=Backslash-R matches all Unicode Linebreaks") 171 172 SET(PCRE2_NEVER_BACKSLASH_C OFF CACHE BOOL 173 "If ON, backslash-C (upper case C) is locked out.") 174 175 SET(PCRE2_SUPPORT_VALGRIND OFF CACHE BOOL 176 "Enable Valgrind support.") 177 178 OPTION(PCRE2_SHOW_REPORT "Show the final configuration report" ON) 179 OPTION(PCRE2_BUILD_PCRE2GREP "Build pcre2grep" ON) 180 OPTION(PCRE2_BUILD_TESTS "Build the tests" ON) 181 182 IF (MINGW) 183 OPTION(NON_STANDARD_LIB_PREFIX 184 "ON=Shared libraries built in mingw will be named pcre2.dll, etc., instead of libpcre2.dll, etc." 185 OFF) 186 187 OPTION(NON_STANDARD_LIB_SUFFIX 188 "ON=Shared libraries built in mingw will be named libpcre2-0.dll, etc., instead of libpcre2.dll, etc." 189 OFF) 190 ENDIF(MINGW) 191 192 IF(MSVC) 193 OPTION(PCRE_STATIC_RUNTIME OFF CACHE BOOL 194 "ON=Compile against the static runtime (/MT)." 195 OFF) 196 OPTION(INSTALL_MSVC_PDB 197 "ON=Install .pdb files built by MSVC, if generated" 198 OFF) 199 ENDIF(MSVC) 200 201 # bzip2 lib 202 IF(BZIP2_FOUND) 203 OPTION (PCRE2_SUPPORT_LIBBZ2 "Enable support for linking pcre2grep with libbz2." ON) 204 ENDIF(BZIP2_FOUND) 205 IF(PCRE2_SUPPORT_LIBBZ2) 206 INCLUDE_DIRECTORIES(${BZIP2_INCLUDE_DIR}) 207 ENDIF(PCRE2_SUPPORT_LIBBZ2) 208 209 # zlib 210 IF(ZLIB_FOUND) 211 OPTION (PCRE2_SUPPORT_LIBZ "Enable support for linking pcre2grep with libz." ON) 212 ENDIF(ZLIB_FOUND) 213 IF(PCRE2_SUPPORT_LIBZ) 214 INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR}) 215 ENDIF(PCRE2_SUPPORT_LIBZ) 216 217 # editline lib 218 IF(EDITLINE_FOUND) 219 OPTION (PCRE2_SUPPORT_LIBEDIT "Enable support for linking pcre2test with libedit." OFF) 220 ENDIF(EDITLINE_FOUND) 221 IF(PCRE2_SUPPORT_LIBEDIT) 222 INCLUDE_DIRECTORIES(${EDITLINE_INCLUDE_DIR}) 223 ENDIF(PCRE2_SUPPORT_LIBEDIT) 224 225 # readline lib 226 IF(READLINE_FOUND) 227 OPTION (PCRE2_SUPPORT_LIBREADLINE "Enable support for linking pcre2test with libreadline." ON) 228 ENDIF(READLINE_FOUND) 229 IF(PCRE2_SUPPORT_LIBREADLINE) 230 INCLUDE_DIRECTORIES(${READLINE_INCLUDE_DIR}) 231 ENDIF(PCRE2_SUPPORT_LIBREADLINE) 232 233 # Prepare build configuration 234 235 IF(NOT BUILD_SHARED_LIBS) 236 SET(PCRE2_STATIC 1) 237 ENDIF(NOT BUILD_SHARED_LIBS) 238 239 IF(NOT PCRE2_BUILD_PCRE2_8 AND NOT PCRE2_BUILD_PCRE2_16 AND NOT PCRE2_BUILD_PCRE2_32) 240 MESSAGE(FATAL_ERROR "At least one of PCRE2_BUILD_PCRE2_8, PCRE2_BUILD_PCRE2_16 or PCRE2_BUILD_PCRE2_32 must be enabled") 241 ENDIF(NOT PCRE2_BUILD_PCRE2_8 AND NOT PCRE2_BUILD_PCRE2_16 AND NOT PCRE2_BUILD_PCRE2_32) 242 243 IF(PCRE2_BUILD_PCRE2_8) 244 SET(SUPPORT_PCRE2_8 1) 245 ENDIF(PCRE2_BUILD_PCRE2_8) 246 247 IF(PCRE2_BUILD_PCRE2_16) 248 SET(SUPPORT_PCRE2_16 1) 249 ENDIF(PCRE2_BUILD_PCRE2_16) 250 251 IF(PCRE2_BUILD_PCRE2_32) 252 SET(SUPPORT_PCRE2_32 1) 253 ENDIF(PCRE2_BUILD_PCRE2_32) 254 255 IF(PCRE2_BUILD_PCRE2GREP AND NOT PCRE2_BUILD_PCRE2_8) 256 MESSAGE(STATUS "** PCRE2_BUILD_PCRE2_8 must be enabled for the pcre2grep program") 257 SET(PCRE2_BUILD_PCRE2GREP OFF) 258 ENDIF(PCRE2_BUILD_PCRE2GREP AND NOT PCRE2_BUILD_PCRE2_8) 259 260 IF(PCRE2_SUPPORT_LIBREADLINE AND PCRE2_SUPPORT_LIBEDIT) 261 MESSAGE(FATAL_ERROR "Only one of libreadline or libeditline can be specified") 262 ENDIF(PCRE2_SUPPORT_LIBREADLINE AND PCRE2_SUPPORT_LIBEDIT) 263 264 IF(PCRE2_SUPPORT_BSR_ANYCRLF) 265 SET(BSR_ANYCRLF 1) 266 ENDIF(PCRE2_SUPPORT_BSR_ANYCRLF) 267 268 IF(PCRE2_NEVER_BACKSLASH_C) 269 SET(NEVER_BACKSLASH_C 1) 270 ENDIF(PCRE2_NEVER_BACKSLASH_C) 271 272 IF(PCRE2_SUPPORT_UNICODE) 273 SET(SUPPORT_UNICODE 1) 274 ENDIF(PCRE2_SUPPORT_UNICODE) 275 276 IF(PCRE2_SUPPORT_JIT) 277 SET(SUPPORT_JIT 1) 278 ENDIF(PCRE2_SUPPORT_JIT) 279 280 IF(PCRE2_SUPPORT_PCRE2GREP_JIT) 281 SET(SUPPORT_PCRE2GREP_JIT 1) 282 ENDIF(PCRE2_SUPPORT_PCRE2GREP_JIT) 283 284 IF(PCRE2_SUPPORT_PCRE2GREP_CALLOUT) 285 SET(SUPPORT_PCRE2GREP_CALLOUT 1) 286 ENDIF(PCRE2_SUPPORT_PCRE2GREP_CALLOUT) 287 288 IF(PCRE2_SUPPORT_VALGRIND) 289 SET(SUPPORT_VALGRIND 1) 290 ENDIF(PCRE2_SUPPORT_VALGRIND) 291 292 # This next one used to reference ${READLINE_LIBRARY}) 293 # but I was advised to add the NCURSES test as well, along with 294 # some modifications to cmake/FindReadline.cmake which should 295 # make it possible to override the default if necessary. PH 296 297 IF(PCRE2_SUPPORT_LIBREADLINE) 298 SET(SUPPORT_LIBREADLINE 1) 299 SET(PCRE2TEST_LIBS ${READLINE_LIBRARY} ${NCURSES_LIBRARY}) 300 ENDIF(PCRE2_SUPPORT_LIBREADLINE) 301 302 # libedit is a plug-compatible alternative to libreadline 303 304 IF(PCRE2_SUPPORT_LIBEDIT) 305 SET(SUPPORT_LIBEDIT 1) 306 SET(PCRE2TEST_LIBS ${EDITLINE_LIBRARY} ${NCURSES_LIBRARY}) 307 ENDIF(PCRE2_SUPPORT_LIBEDIT) 308 309 IF(PCRE2_SUPPORT_LIBZ) 310 SET(SUPPORT_LIBZ 1) 311 SET(PCRE2GREP_LIBS ${PCRE2GREP_LIBS} ${ZLIB_LIBRARIES}) 312 ENDIF(PCRE2_SUPPORT_LIBZ) 313 314 IF(PCRE2_SUPPORT_LIBBZ2) 315 SET(SUPPORT_LIBBZ2 1) 316 SET(PCRE2GREP_LIBS ${PCRE2GREP_LIBS} ${BZIP2_LIBRARIES}) 317 ENDIF(PCRE2_SUPPORT_LIBBZ2) 318 319 SET(NEWLINE_DEFAULT "") 320 321 IF(PCRE2_NEWLINE STREQUAL "CR") 322 SET(NEWLINE_DEFAULT "1") 323 ENDIF(PCRE2_NEWLINE STREQUAL "CR") 324 IF(PCRE2_NEWLINE STREQUAL "LF") 325 SET(NEWLINE_DEFAULT "2") 326 ENDIF(PCRE2_NEWLINE STREQUAL "LF") 327 IF(PCRE2_NEWLINE STREQUAL "CRLF") 328 SET(NEWLINE_DEFAULT "3") 329 ENDIF(PCRE2_NEWLINE STREQUAL "CRLF") 330 IF(PCRE2_NEWLINE STREQUAL "ANY") 331 SET(NEWLINE_DEFAULT "4") 332 ENDIF(PCRE2_NEWLINE STREQUAL "ANY") 333 IF(PCRE2_NEWLINE STREQUAL "ANYCRLF") 334 SET(NEWLINE_DEFAULT "5") 335 ENDIF(PCRE2_NEWLINE STREQUAL "ANYCRLF") 336 337 IF(NEWLINE_DEFAULT STREQUAL "") 338 MESSAGE(FATAL_ERROR "The PCRE2_NEWLINE variable must be set to one of the following values: \"LF\", \"CR\", \"CRLF\", \"ANY\", \"ANYCRLF\".") 339 ENDIF(NEWLINE_DEFAULT STREQUAL "") 340 341 IF(PCRE2_EBCDIC) 342 SET(EBCDIC 1) 343 ENDIF(PCRE2_EBCDIC) 344 345 IF(PCRE2_EBCDIC_NL25) 346 SET(EBCDIC 1) 347 SET(EBCDIC_NL25 1) 348 ENDIF(PCRE2_EBCDIC_NL25) 349 350 IF(PCRE2_HEAP_MATCH_RECURSE) 351 SET(HEAP_MATCH_RECURSE 1) 352 ENDIF(PCRE2_HEAP_MATCH_RECURSE) 353 354 # Output files 355 356 CONFIGURE_FILE(config-cmake.h.in 357 ${PROJECT_BINARY_DIR}/config.h 358 @ONLY) 359 360 # Parse version numbers and date out of configure.ac 361 362 file(STRINGS ${PROJECT_SOURCE_DIR}/configure.ac 363 configure_lines 364 LIMIT_COUNT 50 # Read only the first 50 lines of the file 365 ) 366 367 set(SEARCHED_VARIABLES "pcre2_major" "pcre2_minor" "pcre2_prerelease" "pcre2_date") 368 foreach(configure_line ${configure_lines}) 369 foreach(_substitution_variable ${SEARCHED_VARIABLES}) 370 string(TOUPPER ${_substitution_variable} _substitution_variable_upper) 371 if (NOT ${_substitution_variable_upper}) 372 string(REGEX MATCH "m4_define\\(${_substitution_variable}, \\[(.*)\\]" MACTHED_STRING ${configure_line}) 373 if (CMAKE_MATCH_1) 374 set(${_substitution_variable_upper} ${CMAKE_MATCH_1}) 375 endif() 376 endif() 377 endforeach() 378 endforeach() 379 380 CONFIGURE_FILE(src/pcre2.h.in 381 ${PROJECT_BINARY_DIR}/pcre2.h 382 @ONLY) 383 384 # What about pcre2-config and libpcre2.pc? 385 386 # Character table generation 387 388 OPTION(PCRE2_REBUILD_CHARTABLES "Rebuild char tables" OFF) 389 IF(PCRE2_REBUILD_CHARTABLES) 390 ADD_EXECUTABLE(dftables src/dftables.c) 391 ADD_CUSTOM_COMMAND( 392 COMMENT "Generating character tables (pcre2_chartables.c) for current locale" 393 DEPENDS dftables 394 COMMAND dftables 395 ARGS ${PROJECT_BINARY_DIR}/pcre2_chartables.c 396 OUTPUT ${PROJECT_BINARY_DIR}/pcre2_chartables.c 397 ) 398 ELSE(PCRE2_REBUILD_CHARTABLES) 399 CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/src/pcre2_chartables.c.dist 400 ${PROJECT_BINARY_DIR}/pcre2_chartables.c 401 COPYONLY) 402 ENDIF(PCRE2_REBUILD_CHARTABLES) 403 404 # Source code 405 406 SET(PCRE2_HEADERS ${PROJECT_BINARY_DIR}/pcre2.h) 407 408 SET(PCRE2_SOURCES 409 src/pcre2_auto_possess.c 410 ${PROJECT_BINARY_DIR}/pcre2_chartables.c 411 src/pcre2_compile.c 412 src/pcre2_config.c 413 src/pcre2_context.c 414 src/pcre2_dfa_match.c 415 src/pcre2_error.c 416 src/pcre2_find_bracket.c 417 src/pcre2_jit_compile.c 418 src/pcre2_maketables.c 419 src/pcre2_match.c 420 src/pcre2_match_data.c 421 src/pcre2_newline.c 422 src/pcre2_ord2utf.c 423 src/pcre2_pattern_info.c 424 src/pcre2_serialize.c 425 src/pcre2_string_utils.c 426 src/pcre2_study.c 427 src/pcre2_substitute.c 428 src/pcre2_substring.c 429 src/pcre2_tables.c 430 src/pcre2_ucd.c 431 src/pcre2_valid_utf.c 432 src/pcre2_xclass.c 433 ) 434 435 SET(PCRE2POSIX_HEADERS src/pcre2posix.h) 436 SET(PCRE2POSIX_SOURCES src/pcre2posix.c) 437 438 IF(MINGW AND NOT PCRE2_STATIC) 439 IF (EXISTS ${PROJECT_SOURCE_DIR}/pcre2.rc) 440 ADD_CUSTOM_COMMAND(OUTPUT ${PROJECT_SOURCE_DIR}/pcre2.o 441 PRE-LINK 442 COMMAND windres ARGS pcre2.rc pcre2.o 443 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} 444 COMMENT Using pcre2 coff info in mingw build) 445 SET(PCRE2_SOURCES 446 ${PCRE2_SOURCES} ${PROJECT_SOURCE_DIR}/pcre2.o 447 ) 448 ENDIF(EXISTS ${PROJECT_SOURCE_DIR}/pcre2.rc) 449 IF (EXISTS ${PROJECT_SOURCE_DIR}/pcre2posix.rc) 450 ADD_CUSTOM_COMMAND(OUTPUT ${PROJECT_SOURCE_DIR}/pcre2posix.o 451 PRE-LINK 452 COMMAND windres ARGS pcre2posix.rc pcre2posix.o 453 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} 454 COMMENT Using pcre2posix coff info in mingw build) 455 SET(PCRE2POSIX_SOURCES 456 ${PCRE2POSIX_SOURCES} ${PROJECT_SOURCE_DIR}/pcre2posix.o 457 ) 458 ENDIF(EXISTS ${PROJECT_SOURCE_DIR}/pcre2posix.rc) 459 ENDIF(MINGW AND NOT PCRE2_STATIC) 460 461 IF(MSVC AND NOT PCRE2_STATIC) 462 IF (EXISTS ${PROJECT_SOURCE_DIR}/pcre2.rc) 463 SET(PCRE2_SOURCES 464 ${PCRE2_SOURCES} pcre2.rc) 465 ENDIF(EXISTS ${PROJECT_SOURCE_DIR}/pcre2.rc) 466 IF (EXISTS ${PROJECT_SOURCE_DIR}/pcre2posix.rc) 467 SET(PCRE2POSIX_SOURCES 468 ${PCRE2POSIX_SOURCES} pcre2posix.rc) 469 ENDIF (EXISTS ${PROJECT_SOURCE_DIR}/pcre2posix.rc) 470 ENDIF(MSVC AND NOT PCRE2_STATIC) 471 472 # Fix static compilation with MSVC: https://bugs.exim.org/show_bug.cgi?id=1681 473 # This code was taken from the CMake wiki, not from WebM. 474 475 IF(MSVC AND PCRE2_STATIC_RUNTIME) 476 MESSAGE(STATUS "** MSVC and PCRE2_STATIC_RUNTIME: modifying compiler flags to use static runtime library") 477 foreach(flag_var 478 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE 479 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO) 480 string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") 481 endforeach() 482 ENDIF(MSVC AND PCRE2_STATIC_RUNTIME) 483 484 # Build setup 485 486 ADD_DEFINITIONS(-DHAVE_CONFIG_H) 487 488 IF(MSVC) 489 ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS) 490 ENDIF(MSVC) 491 492 SET(CMAKE_INCLUDE_CURRENT_DIR 1) 493 # needed to make sure to not link debug libs 494 # against release libs and vice versa 495 IF(WIN32) 496 SET(CMAKE_DEBUG_POSTFIX "d") 497 ENDIF(WIN32) 498 499 SET(targets) 500 501 # 8-bit library 502 503 IF(PCRE2_BUILD_PCRE2_8) 504 ADD_LIBRARY(pcre2-8 ${PCRE2_HEADERS} ${PCRE2_SOURCES} ${PROJECT_BINARY_DIR}/config.h) 505 SET_PROPERTY(TARGET pcre2-8 506 PROPERTY COMPILE_DEFINITIONS PCRE2_CODE_UNIT_WIDTH=8) 507 SET(targets ${targets} pcre2-8) 508 ADD_LIBRARY(pcre2posix ${PCRE2POSIX_HEADERS} ${PCRE2POSIX_SOURCES}) 509 SET_PROPERTY(TARGET pcre2posix 510 PROPERTY COMPILE_DEFINITIONS PCRE2_CODE_UNIT_WIDTH=8) 511 SET(targets ${targets} pcre2posix) 512 TARGET_LINK_LIBRARIES(pcre2posix pcre2-8) 513 514 IF(MINGW AND NOT PCRE2_STATIC) 515 IF(NON_STANDARD_LIB_PREFIX) 516 SET_TARGET_PROPERTIES(pcre2-8 pcre2posix PROPERTIES PREFIX "") 517 ENDIF(NON_STANDARD_LIB_PREFIX) 518 IF(NON_STANDARD_LIB_SUFFIX) 519 SET_TARGET_PROPERTIES(pcre2-8 pcre2posix PROPERTIES SUFFIX "-0.dll") 520 ENDIF(NON_STANDARD_LIB_SUFFIX) 521 ENDIF(MINGW AND NOT PCRE2_STATIC) 522 ENDIF(PCRE2_BUILD_PCRE2_8) 523 524 # 16-bit library 525 526 IF(PCRE2_BUILD_PCRE2_16) 527 ADD_LIBRARY(pcre2-16 ${PCRE2_HEADERS} ${PCRE2_SOURCES} ${PROJECT_BINARY_DIR}/config.h) 528 SET_PROPERTY(TARGET pcre2-16 529 PROPERTY COMPILE_DEFINITIONS PCRE2_CODE_UNIT_WIDTH=16) 530 SET(targets ${targets} pcre2-16) 531 532 IF(MINGW AND NOT PCRE2_STATIC) 533 IF(NON_STANDARD_LIB_PREFIX) 534 SET_TARGET_PROPERTIES(pcre2-16 PROPERTIES PREFIX "") 535 ENDIF(NON_STANDARD_LIB_PREFIX) 536 IF(NON_STANDARD_LIB_SUFFIX) 537 SET_TARGET_PROPERTIES(pcre2-16 PROPERTIES SUFFIX "-0.dll") 538 ENDIF(NON_STANDARD_LIB_SUFFIX) 539 ENDIF(MINGW AND NOT PCRE2_STATIC) 540 ENDIF(PCRE2_BUILD_PCRE2_16) 541 542 # 32-bit library 543 544 IF(PCRE2_BUILD_PCRE2_32) 545 ADD_LIBRARY(pcre2-32 ${PCRE2_HEADERS} ${PCRE2_SOURCES} ${PROJECT_BINARY_DIR}/config.h) 546 SET_PROPERTY(TARGET pcre2-32 547 PROPERTY COMPILE_DEFINITIONS PCRE2_CODE_UNIT_WIDTH=32) 548 SET(targets ${targets} pcre2-32) 549 550 IF(MINGW AND NOT PCRE2_STATIC) 551 IF(NON_STANDARD_LIB_PREFIX) 552 SET_TARGET_PROPERTIES(pcre2-32 PROPERTIES PREFIX "") 553 ENDIF(NON_STANDARD_LIB_PREFIX) 554 IF(NON_STANDARD_LIB_SUFFIX) 555 SET_TARGET_PROPERTIES(pcre2-32 PROPERTIES SUFFIX "-0.dll") 556 ENDIF(NON_STANDARD_LIB_SUFFIX) 557 ENDIF(MINGW AND NOT PCRE2_STATIC) 558 ENDIF(PCRE2_BUILD_PCRE2_32) 559 560 # Executables 561 562 IF(PCRE2_BUILD_PCRE2GREP) 563 ADD_EXECUTABLE(pcre2grep src/pcre2grep.c) 564 SET_PROPERTY(TARGET pcre2grep 565 PROPERTY COMPILE_DEFINITIONS PCRE2_CODE_UNIT_WIDTH=8) 566 SET(targets ${targets} pcre2grep) 567 TARGET_LINK_LIBRARIES(pcre2grep pcre2posix ${PCRE2GREP_LIBS}) 568 ENDIF(PCRE2_BUILD_PCRE2GREP) 569 570 # Testing 571 572 IF(PCRE2_BUILD_TESTS) 573 ENABLE_TESTING() 574 575 SET(PCRE2TEST_SOURCES src/pcre2test.c) 576 577 ADD_EXECUTABLE(pcre2test ${PCRE2TEST_SOURCES}) 578 SET(targets ${targets} pcre2test) 579 IF(PCRE2_BUILD_PCRE2_8) 580 LIST(APPEND PCRE2TEST_LIBS pcre2posix pcre2-8) 581 ENDIF(PCRE2_BUILD_PCRE2_8) 582 IF(PCRE2_BUILD_PCRE2_16) 583 LIST(APPEND PCRE2TEST_LIBS pcre2-16) 584 ENDIF(PCRE2_BUILD_PCRE2_16) 585 IF(PCRE2_BUILD_PCRE2_32) 586 LIST(APPEND PCRE2TEST_LIBS pcre2-32) 587 ENDIF(PCRE2_BUILD_PCRE2_32) 588 TARGET_LINK_LIBRARIES(pcre2test ${PCRE2TEST_LIBS}) 589 590 IF(PCRE2_SUPPORT_JIT) 591 ADD_EXECUTABLE(pcre2_jit_test src/pcre2_jit_test.c) 592 SET(targets ${targets} pcre2_jit_test) 593 SET(PCRE2_JIT_TEST_LIBS ) 594 IF(PCRE2_BUILD_PCRE2_8) 595 LIST(APPEND PCRE2_JIT_TEST_LIBS pcre2-8) 596 ENDIF(PCRE2_BUILD_PCRE2_8) 597 IF(PCRE2_BUILD_PCRE2_16) 598 LIST(APPEND PCRE2_JIT_TEST_LIBS pcre2-16) 599 ENDIF(PCRE2_BUILD_PCRE2_16) 600 IF(PCRE2_BUILD_PCRE2_32) 601 LIST(APPEND PCRE2_JIT_TEST_LIBS pcre2-32) 602 ENDIF(PCRE2_BUILD_PCRE2_32) 603 TARGET_LINK_LIBRARIES(pcre2_jit_test ${PCRE2_JIT_TEST_LIBS}) 604 ENDIF(PCRE2_SUPPORT_JIT) 605 606 # exes in Debug location tested by the RunTest shell script 607 # via "make test" 608 609 IF(PCRE2_BUILD_PCRE2GREP) 610 GET_TARGET_PROPERTY(PCRE2GREP_EXE pcre2grep DEBUG_LOCATION) 611 ENDIF(PCRE2_BUILD_PCRE2GREP) 612 613 GET_TARGET_PROPERTY(PCRE2TEST_EXE pcre2test DEBUG_LOCATION) 614 615 # ================================================= 616 # Write out a CTest configuration file 617 # 618 FILE(WRITE ${PROJECT_BINARY_DIR}/CTestCustom.ctest 619 "# This is a generated file. 620 MESSAGE(\"When testing is complete, review test output in the 621 \\\"${PROJECT_BINARY_DIR}/Testing/Temporary\\\" folder.\") 622 MESSAGE(\" \") 623 ") 624 625 FILE(WRITE ${PROJECT_BINARY_DIR}/pcre2_test.sh 626 "#! /bin/sh 627 # This is a generated file. 628 . ${PROJECT_SOURCE_DIR}/RunTest 629 if test \"$?\" != \"0\"; then exit 1; fi 630 # End 631 ") 632 633 IF(UNIX) 634 ADD_TEST(pcre2_test sh ${PROJECT_BINARY_DIR}/pcre2_test.sh) 635 ENDIF(UNIX) 636 637 IF(PCRE2_BUILD_PCRE2GREP) 638 FILE(WRITE ${PROJECT_BINARY_DIR}/pcre2_grep_test.sh 639 "#! /bin/sh 640 # This is a generated file. 641 . ${PROJECT_SOURCE_DIR}/RunGrepTest 642 if test \"$?\" != \"0\"; then exit 1; fi 643 # End 644 ") 645 646 IF(UNIX) 647 ADD_TEST(pcre2_grep_test sh ${PROJECT_BINARY_DIR}/pcre2_grep_test.sh) 648 ENDIF(UNIX) 649 ENDIF(PCRE2_BUILD_PCRE2GREP) 650 651 IF(WIN32) 652 # Provide environment for executing the bat file version of RunTest 653 FILE(TO_NATIVE_PATH ${PROJECT_SOURCE_DIR} winsrc) 654 FILE(TO_NATIVE_PATH ${PROJECT_BINARY_DIR} winbin) 655 FILE(TO_NATIVE_PATH ${PCRE2TEST_EXE} winexe) 656 657 FILE(WRITE ${PROJECT_BINARY_DIR}/pcre2_test.bat 658 "\@REM This is a generated file. 659 \@echo off 660 setlocal 661 SET srcdir=\"${winsrc}\" 662 SET pcre2test=\"${winexe}\" 663 if not [%CMAKE_CONFIG_TYPE%]==[] SET pcre2test=\"${winbin}\\%CMAKE_CONFIG_TYPE%\\pcre2test.exe\" 664 call %srcdir%\\RunTest.Bat 665 if errorlevel 1 exit /b 1 666 echo RunTest.bat tests successfully completed 667 ") 668 669 ADD_TEST(NAME pcre2_test_bat 670 COMMAND pcre2_test.bat) 671 SET_TESTS_PROPERTIES(pcre2_test_bat PROPERTIES 672 PASS_REGULAR_EXPRESSION "RunTest\\.bat tests successfully completed") 673 674 IF("$ENV{OSTYPE}" STREQUAL "msys") 675 # Both the sh and bat file versions of RunTest are run if make test is used 676 # in msys 677 ADD_TEST(pcre2_test_sh sh.exe ${PROJECT_BINARY_DIR}/pcre2_test.sh) 678 IF(PCRE2_BUILD_PCRE2GREP) 679 ADD_TEST(pcre2_grep_test sh.exe ${PROJECT_BINARY_DIR}/pcre2_grep_test.sh) 680 ENDIF(PCRE2_BUILD_PCRE2GREP) 681 ENDIF("$ENV{OSTYPE}" STREQUAL "msys") 682 ENDIF(WIN32) 683 684 # Changed to accommodate testing whichever location was just built 685 686 IF(PCRE2_SUPPORT_JIT) 687 ADD_TEST(pcre2_jit_test pcre2_jit_test) 688 ENDIF(PCRE2_SUPPORT_JIT) 689 690 ENDIF(PCRE2_BUILD_TESTS) 691 692 # Installation 693 694 SET(CMAKE_INSTALL_ALWAYS 1) 695 696 INSTALL(TARGETS ${targets} 697 RUNTIME DESTINATION bin 698 LIBRARY DESTINATION lib 699 ARCHIVE DESTINATION lib) 700 701 INSTALL(FILES ${PCRE2_HEADERS} ${PCRE2POSIX_HEADERS} DESTINATION include) 702 703 FILE(GLOB html ${PROJECT_SOURCE_DIR}/doc/html/*.html) 704 FILE(GLOB man1 ${PROJECT_SOURCE_DIR}/doc/*.1) 705 FILE(GLOB man3 ${PROJECT_SOURCE_DIR}/doc/*.3) 706 707 FOREACH(man ${man3}) 708 GET_FILENAME_COMPONENT(man_tmp ${man} NAME) 709 SET(man3_new ${man3} ${man}) 710 ENDFOREACH(man ${man3}) 711 SET(man3 ${man3_new}) 712 713 INSTALL(FILES ${man1} DESTINATION man/man1) 714 INSTALL(FILES ${man3} DESTINATION man/man3) 715 INSTALL(FILES ${html} DESTINATION share/doc/pcre2/html) 716 717 IF(MSVC AND INSTALL_MSVC_PDB) 718 INSTALL(FILES ${PROJECT_BINARY_DIR}/pcre2.pdb 719 ${PROJECT_BINARY_DIR}/pcre2posix.pdb 720 DESTINATION bin 721 CONFIGURATIONS RelWithDebInfo) 722 INSTALL(FILES ${PROJECT_BINARY_DIR}/pcre2d.pdb 723 ${PROJECT_BINARY_DIR}/pcre2posixd.pdb 724 DESTINATION bin 725 CONFIGURATIONS Debug) 726 ENDIF(MSVC AND INSTALL_MSVC_PDB) 727 728 # Help, only for nice output 729 IF(BUILD_SHARED_LIBS) 730 SET(BUILD_STATIC_LIBS OFF) 731 ELSE(BUILD_SHARED_LIBS) 732 SET(BUILD_STATIC_LIBS ON) 733 ENDIF(BUILD_SHARED_LIBS) 734 735 IF(PCRE2_SHOW_REPORT) 736 STRING(TOUPPER "${CMAKE_BUILD_TYPE}" buildtype) 737 IF (CMAKE_C_FLAGS) 738 SET(cfsp " ") 739 ENDIF(CMAKE_C_FLAGS) 740 MESSAGE(STATUS "") 741 MESSAGE(STATUS "") 742 MESSAGE(STATUS "PCRE2 configuration summary:") 743 MESSAGE(STATUS "") 744 MESSAGE(STATUS " Install prefix .................. : ${CMAKE_INSTALL_PREFIX}") 745 MESSAGE(STATUS " C compiler ...................... : ${CMAKE_C_COMPILER}") 746 MESSAGE(STATUS " C compiler flags ................ : ${CMAKE_C_FLAGS}${cfsp}${CMAKE_C_FLAGS_${buildtype}}") 747 MESSAGE(STATUS "") 748 MESSAGE(STATUS " Build 8 bit PCRE2 library ....... : ${PCRE2_BUILD_PCRE2_8}") 749 MESSAGE(STATUS " Build 16 bit PCRE2 library ...... : ${PCRE2_BUILD_PCRE2_16}") 750 MESSAGE(STATUS " Build 32 bit PCRE2 library ...... : ${PCRE2_BUILD_PCRE2_32}") 751 MESSAGE(STATUS " Enable JIT compiling support .... : ${PCRE2_SUPPORT_JIT}") 752 MESSAGE(STATUS " Enable Unicode support .......... : ${PCRE2_SUPPORT_UNICODE}") 753 MESSAGE(STATUS " Newline char/sequence ........... : ${PCRE2_NEWLINE}") 754 MESSAGE(STATUS " \\R matches only ANYCRLF ......... : ${PCRE2_SUPPORT_BSR_ANYCRLF}") 755 MESSAGE(STATUS " \\C is disabled .................. : ${PCRE2_NEVER_BACKSLASH_C}") 756 MESSAGE(STATUS " EBCDIC coding ................... : ${PCRE2_EBCDIC}") 757 MESSAGE(STATUS " EBCDIC coding with NL=0x25 ...... : ${PCRE2_EBCDIC_NL25}") 758 MESSAGE(STATUS " Rebuild char tables ............. : ${PCRE2_REBUILD_CHARTABLES}") 759 MESSAGE(STATUS " Use heap recursion .............. : ${PCRE2_HEAP_MATCH_RECURSE}") 760 MESSAGE(STATUS " Internal link size .............. : ${PCRE2_LINK_SIZE}") 761 MESSAGE(STATUS " Parentheses nest limit .......... : ${PCRE2_PARENS_NEST_LIMIT}") 762 MESSAGE(STATUS " Match limit ..................... : ${PCRE2_MATCH_LIMIT}") 763 MESSAGE(STATUS " Match limit recursion ........... : ${PCRE2_MATCH_LIMIT_RECURSION}") 764 MESSAGE(STATUS " Build shared libs ............... : ${BUILD_SHARED_LIBS}") 765 MESSAGE(STATUS " Build static libs ............... : ${BUILD_STATIC_LIBS}") 766 MESSAGE(STATUS " Build pcre2grep ................. : ${PCRE2_BUILD_PCRE2GREP}") 767 MESSAGE(STATUS " Enable JIT in pcre2grep ......... : ${PCRE2_SUPPORT_PCRE2GREP_JIT}") 768 MESSAGE(STATUS " Enable callouts in pcre2grep .... : ${PCRE2_SUPPORT_PCRE2GREP_CALLOUT}") 769 MESSAGE(STATUS " Buffer size for pcre2grep ....... : ${PCRE2GREP_BUFSIZE}") 770 MESSAGE(STATUS " Build tests (implies pcre2test . : ${PCRE2_BUILD_TESTS}") 771 MESSAGE(STATUS " and pcre2grep)") 772 IF(ZLIB_FOUND) 773 MESSAGE(STATUS " Link pcre2grep with libz ........ : ${PCRE2_SUPPORT_LIBZ}") 774 ELSE(ZLIB_FOUND) 775 MESSAGE(STATUS " Link pcre2grep with libz ........ : Library not found" ) 776 ENDIF(ZLIB_FOUND) 777 IF(BZIP2_FOUND) 778 MESSAGE(STATUS " Link pcre2grep with libbz2 ...... : ${PCRE2_SUPPORT_LIBBZ2}") 779 ELSE(BZIP2_FOUND) 780 MESSAGE(STATUS " Link pcre2grep with libbz2 ...... : Library not found" ) 781 ENDIF(BZIP2_FOUND) 782 IF(EDITLINE_FOUND) 783 MESSAGE(STATUS " Link pcre2test with libeditline . : ${PCRE2_SUPPORT_LIBEDIT}") 784 ELSE(EDITLINE_FOUND) 785 MESSAGE(STATUS " Link pcre2test with libeditline . : Library not found" ) 786 ENDIF(EDITLINE_FOUND) 787 IF(READLINE_FOUND) 788 MESSAGE(STATUS " Link pcre2test with libreadline . : ${PCRE2_SUPPORT_LIBREADLINE}") 789 ELSE(READLINE_FOUND) 790 MESSAGE(STATUS " Link pcre2test with libreadline . : Library not found" ) 791 ENDIF(READLINE_FOUND) 792 MESSAGE(STATUS " Support Valgrind .................: ${PCRE2_SUPPORT_VALGRIND}") 793 794 IF(MINGW AND NOT PCRE2_STATIC) 795 MESSAGE(STATUS " Non-standard dll names (prefix) . : ${NON_STANDARD_LIB_PREFIX}") 796 MESSAGE(STATUS " Non-standard dll names (suffix) . : ${NON_STANDARD_LIB_SUFFIX}") 797 ENDIF(MINGW AND NOT PCRE2_STATIC) 798 799 IF(MSVC) 800 MESSAGE(STATUS " Install MSVC .pdb files ..........: ${INSTALL_MSVC_PDB}") 801 ENDIF(MSVC) 802 803 MESSAGE(STATUS "") 804 ENDIF(PCRE2_SHOW_REPORT) 805 806 # end CMakeLists.txt 807