114114# -- ./CMakeLists.txt ./cmake/*.cmake ./cmake/*.cmake.in
115115################################################################################
116116
117+ message (STATUS "Using CMake version ${CMAKE_VERSION} (${CMAKE_COMMAND} )" )
118+
117119# Increased minimum to 3.15 to allow use of string(REPEAT).
118120cmake_minimum_required (VERSION 3.15 FATAL_ERROR)
119121project (PCRE2 C)
120122set (CMAKE_C_STANDARD 99)
121123set (CMAKE_C_STANDARD_REQUIRED TRUE )
122-
123124set (CMAKE_C_VISIBILITY_PRESET hidden)
124125
125126# Solaris-specific fix for "CMAKE_C_VISIBILITY_PRESET": this feature was only
@@ -141,12 +142,10 @@ endif()
141142# cmake_policy(SET CMP0026 OLD)
142143# cmake_policy(SET CMP0074 NEW)
143144
144- # For FindReadline. cmake. This uses list(APPEND) rather than set() to allow
145+ # For our modules in cmake/ . This uses list(APPEND) rather than set() to allow
145146# setting CMAKE_MODULE_PATH on the command line.
146147list (APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR} /cmake)
147148
148- include_directories (${PROJECT_BINARY_DIR} /interface ${PROJECT_BINARY_DIR} /src ${PROJECT_SOURCE_DIR} /src)
149-
150149# external packages
151150find_package (BZip2)
152151find_package (ZLIB)
@@ -163,7 +162,7 @@ include(CheckTypeSize)
163162include (CMakePackageConfigHelpers)
164163include (CMakePushCheckState)
165164include (GNUInstallDirs) # for CMAKE_INSTALL_LIBDIR
166- include (PCRE2CheckLinkerFlag )
165+ include (PCRE2CheckVscript )
167166include (PCRE2UseSystemExtensions)
168167include (PCRE2WarningAsError)
169168
@@ -270,29 +269,7 @@ check_c_source_compiles(
270269
271270# Detect support for linker scripts.
272271
273- file (WRITE ${PROJECT_BINARY_DIR} /test -map-file.sym "PCRE2_10.00 { global: main; };" )
274- file (WRITE ${PROJECT_BINARY_DIR} /test -map-file-broken.sym "PCRE2_10.00 { global: main; }; {" )
275- if (NOT MSVC )
276- pcre2_check_linker_flag(C -Wl,--version -script,${PROJECT_BINARY_DIR} /test -map-file.sym HAVE_VSCRIPT_GNU)
277- pcre2_check_linker_flag(C -Wl,-M,${PROJECT_BINARY_DIR} /test -map-file.sym HAVE_VSCRIPT_SUN)
278- endif ()
279- if (HAVE_VSCRIPT_GNU)
280- set (VSCRIPT_FLAG --version -script)
281- set (HAVE_VSCRIPT TRUE )
282- elseif (HAVE_VSCRIPT_SUN)
283- set (VSCRIPT_FLAG -M)
284- set (HAVE_VSCRIPT TRUE )
285- endif ()
286- if (HAVE_VSCRIPT)
287- # Perform the same logic as ax_check_vscript.m4, to test whether the linker
288- # silently ignores (and overwrites) linker scripts it doesn't understand.
289- pcre2_check_linker_flag(C -Wl,${VSCRIPT_FLAG} ,${PROJECT_BINARY_DIR} /test -map-file-broken.sym HAVE_VSCRIPT_BROKEN)
290- if (HAVE_VSCRIPT_BROKEN)
291- set (HAVE_VSCRIPT FALSE )
292- endif ()
293- endif ()
294- file (REMOVE ${PROJECT_BINARY_DIR} /test -map-file.sym)
295- file (REMOVE ${PROJECT_BINARY_DIR} /test -map-file-broken.sym)
272+ pcre2_check_vscript(HAVE_VSCRIPT VSCRIPT_FLAG)
296273
297274# Check whether Intel CET is enabled, and if so, adjust compiler flags. This
298275# code was written by PH, trying to imitate the logic from the autotools
@@ -472,6 +449,54 @@ endif()
472449if (BZIP2_FOUND)
473450 option (PCRE2_SUPPORT_LIBBZ2 "Enable support for linking pcre2grep with libbz2." ON )
474451endif ()
452+
453+ # zlib
454+ if (ZLIB_FOUND)
455+ option (PCRE2_SUPPORT_LIBZ "Enable support for linking pcre2grep with libz." ON )
456+ endif ()
457+
458+ # editline lib
459+ if (EDITLINE_FOUND)
460+ option (PCRE2_SUPPORT_LIBEDIT "Enable support for linking pcre2test with libedit." OFF )
461+ endif ()
462+
463+ # readline lib
464+ if (READLINE_FOUND)
465+ option (PCRE2_SUPPORT_LIBREADLINE "Enable support for linking pcre2test with libreadline." ON )
466+ endif ()
467+
468+ # Prepare build configuration
469+
470+ include_directories (${PROJECT_BINARY_DIR} /interface ${PROJECT_BINARY_DIR} /src ${PROJECT_SOURCE_DIR} /src)
471+
472+ if (NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_LIBS)
473+ message (FATAL_ERROR "At least one of BUILD_SHARED_LIBS or BUILD_STATIC_LIBS must be enabled." )
474+ endif ()
475+
476+ if (NOT PCRE2_BUILD_PCRE2_8 AND NOT PCRE2_BUILD_PCRE2_16 AND NOT PCRE2_BUILD_PCRE2_32)
477+ message (
478+ FATAL_ERROR
479+ "At least one of PCRE2_BUILD_PCRE2_8, PCRE2_BUILD_PCRE2_16 or PCRE2_BUILD_PCRE2_32 must be enabled"
480+ )
481+ endif ()
482+
483+ if (PCRE2_BUILD_PCRE2_8)
484+ set (SUPPORT_PCRE2_8 1)
485+ endif ()
486+
487+ if (PCRE2_BUILD_PCRE2_16)
488+ set (SUPPORT_PCRE2_16 1)
489+ endif ()
490+
491+ if (PCRE2_BUILD_PCRE2_32)
492+ set (SUPPORT_PCRE2_32 1)
493+ endif ()
494+
495+ if (PCRE2_BUILD_PCRE2GREP AND NOT PCRE2_BUILD_PCRE2_8)
496+ message (STATUS "** PCRE2_BUILD_PCRE2_8 must be enabled for the pcre2grep program" )
497+ set (PCRE2_BUILD_PCRE2GREP OFF )
498+ endif ()
499+
475500if (PCRE2_SUPPORT_LIBBZ2)
476501 if (BZIP2_FOUND)
477502 include_directories (${BZIP2_INCLUDE_DIR} )
@@ -484,10 +509,6 @@ if(PCRE2_SUPPORT_LIBBZ2)
484509 endif ()
485510endif ()
486511
487- # zlib
488- if (ZLIB_FOUND)
489- option (PCRE2_SUPPORT_LIBZ "Enable support for linking pcre2grep with libz." ON )
490- endif ()
491512if (PCRE2_SUPPORT_LIBZ)
492513 if (ZLIB_FOUND)
493514 include_directories (${ZLIB_INCLUDE_DIR} )
@@ -500,10 +521,6 @@ if(PCRE2_SUPPORT_LIBZ)
500521 endif ()
501522endif ()
502523
503- # editline lib
504- if (EDITLINE_FOUND)
505- option (PCRE2_SUPPORT_LIBEDIT "Enable support for linking pcre2test with libedit." OFF )
506- endif ()
507524if (PCRE2_SUPPORT_LIBEDIT)
508525 if (EDITLINE_FOUND)
509526 include_directories (${EDITLINE_INCLUDE_DIR} )
@@ -516,10 +533,6 @@ if(PCRE2_SUPPORT_LIBEDIT)
516533 endif ()
517534endif ()
518535
519- # readline lib
520- if (READLINE_FOUND)
521- option (PCRE2_SUPPORT_LIBREADLINE "Enable support for linking pcre2test with libreadline." ON )
522- endif ()
523536if (PCRE2_SUPPORT_LIBREADLINE)
524537 if (READLINE_FOUND)
525538 include_directories (${READLINE_INCLUDE_DIR} )
@@ -532,36 +545,6 @@ if(PCRE2_SUPPORT_LIBREADLINE)
532545 endif ()
533546endif ()
534547
535- # Prepare build configuration
536-
537- if (NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_LIBS)
538- message (FATAL_ERROR "At least one of BUILD_SHARED_LIBS or BUILD_STATIC_LIBS must be enabled." )
539- endif ()
540-
541- if (NOT PCRE2_BUILD_PCRE2_8 AND NOT PCRE2_BUILD_PCRE2_16 AND NOT PCRE2_BUILD_PCRE2_32)
542- message (
543- FATAL_ERROR
544- "At least one of PCRE2_BUILD_PCRE2_8, PCRE2_BUILD_PCRE2_16 or PCRE2_BUILD_PCRE2_32 must be enabled"
545- )
546- endif ()
547-
548- if (PCRE2_BUILD_PCRE2_8)
549- set (SUPPORT_PCRE2_8 1)
550- endif ()
551-
552- if (PCRE2_BUILD_PCRE2_16)
553- set (SUPPORT_PCRE2_16 1)
554- endif ()
555-
556- if (PCRE2_BUILD_PCRE2_32)
557- set (SUPPORT_PCRE2_32 1)
558- endif ()
559-
560- if (PCRE2_BUILD_PCRE2GREP AND NOT PCRE2_BUILD_PCRE2_8)
561- message (STATUS "** PCRE2_BUILD_PCRE2_8 must be enabled for the pcre2grep program" )
562- set (PCRE2_BUILD_PCRE2GREP OFF )
563- endif ()
564-
565548if (PCRE2_SUPPORT_LIBREADLINE AND PCRE2_SUPPORT_LIBEDIT)
566549 if (READLINE_FOUND)
567550 message (
0 commit comments