@@ -161,6 +161,7 @@ include(CheckSymbolExists)
161161include (CheckIncludeFile)
162162include (CheckTypeSize)
163163include (CMakePackageConfigHelpers)
164+ include (CMakePushCheckState)
164165include (GNUInstallDirs) # for CMAKE_INSTALL_LIBDIR
165166include (PCRE2CheckLinkerFlag)
166167include (PCRE2UseSystemExtensions)
@@ -172,8 +173,25 @@ check_include_file(sys/types.h HAVE_SYS_TYPES_H)
172173check_include_file(unistd.h HAVE_UNISTD_H)
173174check_include_file(windows.h HAVE_WINDOWS_H)
174175
175- check_symbol_exists(memfd_create "sys/mman.h" HAVE_MEMFD_CREATE)
176- check_symbol_exists(secure_getenv "stdlib.h" HAVE_SECURE_GETENV)
176+ # Check whether any system-wide extensions need to be enabled, in order for
177+ # OS functionality to be exposed.
178+ pcre2_use_system_extensions()
179+
180+ cmake_push_check_state(RESET)
181+ # Somewhat awkward code to propagate the _GNU_SOURCE definition (added to
182+ # COMPILE_DEFINITIONS by pcre2_use_system_extensions()).
183+ get_directory_property (_pcre2_compile_definitions COMPILE_DEFINITIONS )
184+ if (DEFINED _pcre2_compile_definitions)
185+ set (CMAKE_REQUIRED_DEFINITIONS "" )
186+ foreach (_def IN LISTS _pcre2_compile_definitions)
187+ list (APPEND CMAKE_REQUIRED_DEFINITIONS "-D${_def} " )
188+ endforeach ()
189+ endif ()
190+
191+ check_symbol_exists(mkostemp stdlib.h HAVE_MKOSTEMP) # glibc 2.7
192+ check_symbol_exists(memfd_create "sys/mman.h" HAVE_MEMFD_CREATE) # glibc 2.27
193+ check_symbol_exists(secure_getenv "stdlib.h" HAVE_SECURE_GETENV) # glibc 2.17
194+ cmake_pop_check_state()
177195
178196check_c_source_compiles(
179197 [=[
@@ -184,10 +202,10 @@ check_c_source_compiles(
184202 HAVE_REALPATH
185203)
186204
205+ cmake_push_check_state()
187206if (NOT DEFINED CMAKE_REQUIRED_FLAGS)
188207 set (CMAKE_REQUIRED_FLAGS "" )
189208endif ()
190- set (ORIG_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} )
191209if (NOT MSVC AND NOT CMAKE_C_COMPILER_ID STREQUAL "XL" AND NOT CMAKE_C_COMPILER_ID STREQUAL "SunPro" )
192210 set (CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror" )
193211endif ()
@@ -197,6 +215,7 @@ check_c_source_compiles(
197215 HAVE_ATTRIBUTE_UNINITIALIZED
198216)
199217
218+ # TODO Consider switching to modern "GenerateExportHeader"
200219check_c_source_compiles(
201220 [=[
202221 extern __attribute__ ((visibility ("default"))) int f(void);
@@ -206,14 +225,14 @@ check_c_source_compiles(
206225 HAVE_VISIBILITY
207226)
208227
228+ cmake_pop_check_state()
229+
209230if (HAVE_VISIBILITY)
210231 set (PCRE2_EXPORT [=[__attribute__ ((visibility ("default")))]=])
211232else ()
212233 set (PCRE2_EXPORT)
213234endif ()
214235
215- set (CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS} )
216-
217236check_c_source_compiles("int main(void) { __assume(1); return 0; }" HAVE_BUILTIN_ASSUME)
218237
219238check_c_source_compiles(
@@ -271,11 +290,6 @@ if(INTEL_CET_ENABLED)
271290 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mshstk" )
272291endif ()
273292
274- # Check whether any system-wide extensions need to be enabled, in order for
275- # OS functionality to be exposed.
276-
277- pcre2_use_system_extensions()
278-
279293# User-configurable options
280294#
281295# Note: CMakeSetup displays these in alphabetical order, regardless of
@@ -436,32 +450,45 @@ if(BZIP2_FOUND)
436450 option (PCRE2_SUPPORT_LIBBZ2 "Enable support for linking pcre2grep with libbz2." ON )
437451endif ()
438452if (PCRE2_SUPPORT_LIBBZ2)
439- include_directories (${BZIP2_INCLUDE_DIR} )
453+ if (BZIP2_FOUND)
454+ include_directories (${BZIP2_INCLUDE_DIR} )
455+ else ()
456+ message (
457+ FATAL_ERROR
458+ " libbz2 not found. Set BZIP2_INCLUDE_DIR to a compatible header\n "
459+ " or set BZip2_ROOT to a full bzip2 installed tree, as needed."
460+ )
461+ endif ()
440462endif ()
441463
442464# zlib
443465if (ZLIB_FOUND)
444466 option (PCRE2_SUPPORT_LIBZ "Enable support for linking pcre2grep with libz." ON )
445467endif ()
446468if (PCRE2_SUPPORT_LIBZ)
447- include_directories (${ZLIB_INCLUDE_DIR} )
469+ if (ZLIB_FOUND)
470+ include_directories (${ZLIB_INCLUDE_DIR} )
471+ else ()
472+ message (
473+ FATAL_ERROR
474+ " zlib not found. Set ZLIB_INCLUDE_DIR to a compatible header\n "
475+ " or set ZLIB_ROOT to a full zlib installed tree, as needed."
476+ )
477+ endif ()
448478endif ()
449479
450480# editline lib
451481if (EDITLINE_FOUND)
452482 option (PCRE2_SUPPORT_LIBEDIT "Enable support for linking pcre2test with libedit." OFF )
453483endif ()
454- if (EDITLINE_FOUND )
455- if (PCRE2_SUPPORT_LIBEDIT )
484+ if (PCRE2_SUPPORT_LIBEDIT )
485+ if (EDITLINE_FOUND )
456486 include_directories (${EDITLINE_INCLUDE_DIR} )
457- endif ()
458- else ()
459- if (PCRE2_SUPPORT_LIBEDIT)
487+ else ()
460488 message (
461489 FATAL_ERROR
462- " libedit not found, set EDITLINE_INCLUDE_DIR to a compatible header\n "
463- " or set Editline_ROOT to a full libedit installed tree, as needed\n "
464- " Might need to enable policy CMP0074 in CMakeLists.txt"
490+ " libedit not found. Set EDITLINE_INCLUDE_DIR to a compatible header\n "
491+ " or set Editline_ROOT to a full libedit installed tree, as needed."
465492 )
466493 endif ()
467494endif ()
@@ -471,7 +498,15 @@ if(READLINE_FOUND)
471498 option (PCRE2_SUPPORT_LIBREADLINE "Enable support for linking pcre2test with libreadline." ON )
472499endif ()
473500if (PCRE2_SUPPORT_LIBREADLINE)
474- include_directories (${READLINE_INCLUDE_DIR} )
501+ if (READLINE_FOUND)
502+ include_directories (${READLINE_INCLUDE_DIR} )
503+ else ()
504+ message (
505+ FATAL_ERROR
506+ " libreadline not found. Set READLINE_INCLUDE_DIR to a compatible header\n "
507+ " or set Readline_ROOT to a full libreadline installed tree, as needed."
508+ )
509+ endif ()
475510endif ()
476511
477512# Prepare build configuration
@@ -537,19 +572,7 @@ if(PCRE2_SUPPORT_JIT)
537572endif ()
538573
539574if (PCRE2_SUPPORT_JIT_SEALLOC)
540- set (CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
541- check_symbol_exists(mkostemp stdlib.h REQUIRED)
542- unset (CMAKE_REQUIRED_DEFINITIONS)
543- if (${REQUIRED} )
544- if (${CMAKE_SYSTEM_NAME} MATCHES Linux|NetBSD)
545- add_compile_definitions (_GNU_SOURCE)
546- set (SLJIT_PROT_EXECUTABLE_ALLOCATOR 1)
547- else ()
548- message (FATAL_ERROR "Your configuration is not supported" )
549- endif ()
550- else ()
551- set (PCRE2_SUPPORT_JIT_SEALLOC OFF )
552- endif ()
575+ set (SLJIT_PROT_EXECUTABLE_ALLOCATOR 1)
553576endif ()
554577
555578if (PCRE2GREP_SUPPORT_JIT)
@@ -1491,7 +1514,12 @@ if(PCRE2_SHOW_REPORT)
14911514 endforeach ()
14921515 else ()
14931516 string (TOUPPER "${CMAKE_BUILD_TYPE} " buildtype)
1494- message (STATUS " C compiler flags .................. : ${CMAKE_C_FLAGS}${CFSP} ${CMAKE_C_FLAGS_${buildtype} }" )
1517+ if (buildtype STREQUAL "" )
1518+ set (CFBLD "" )
1519+ else ()
1520+ set (CFBLD "${CMAKE_C_FLAGS_${buildtype} }" )
1521+ endif ()
1522+ message (STATUS " C compiler flags .................. : ${CMAKE_C_FLAGS}${CFSP}${CFBLD} " )
14951523 endif ()
14961524
14971525 message (STATUS "" )
0 commit comments