|
| 1 | +# This CMake module is supposed to give similar results to the |
| 2 | +# AC_USE_SYSTEM_EXTENSIONS Autoconf macro, which turns on a load of |
| 3 | +# system feature-check macros, including _ALL_SOURCE, _GNU_SOURCE, |
| 4 | +# _NETBSD_SOURCE, and many more. |
| 5 | +# |
| 6 | +# Because PCRE2 uses so few OS features, we don't seem to actually need to |
| 7 | +# enable many of these. Modern platforms with CMake users generally enable |
| 8 | +# all the basic POSIX features by default. |
| 9 | +# |
| 10 | +# So far, we know that we require: |
| 11 | +# - _ALL_SOURCE on IBM systems (z/OS, probably AIX) in order to call |
| 12 | +# getrlimit() in pcre2test. |
| 13 | +# |
| 14 | +# Autoconf enables this unconditionally. However, our CMake script potentially |
| 15 | +# supports *more* platforms than Autoconf, so we use a feature check. |
| 16 | + |
| 17 | +function(pcre2_use_system_extensions) |
| 18 | + if (WIN32) |
| 19 | + return() |
| 20 | + endif() |
| 21 | + |
| 22 | + include(CheckCSourceCompiles) |
| 23 | + |
| 24 | + set(_pcre2_test_src " |
| 25 | +#include <sys/time.h> |
| 26 | +#include <sys/resource.h> |
| 27 | +
|
| 28 | +int main(void) { |
| 29 | + struct rlimit rlim; |
| 30 | + getrlimit(RLIMIT_STACK, &rlim); |
| 31 | + return 0; |
| 32 | +} |
| 33 | +") |
| 34 | + |
| 35 | + check_c_source_compiles("${_pcre2_test_src}" HAVE_GETRLIMIT) |
| 36 | + |
| 37 | + if (NOT HAVE_GETRLIMIT) |
| 38 | + # Try again with _ALL_SOURCE |
| 39 | + set(CMAKE_REQUIRED_DEFINITIONS "-D_ALL_SOURCE") |
| 40 | + check_c_source_compiles("${_pcre2_test_src}" HAVE_GETRLIMIT_ALLSOURCE) |
| 41 | + unset(CMAKE_REQUIRED_DEFINITIONS) |
| 42 | + |
| 43 | + if (HAVE_GETRLIMIT_ALLSOURCE) |
| 44 | + add_compile_definitions(_ALL_SOURCE) |
| 45 | + endif() |
| 46 | + endif() |
| 47 | +endfunction() |
0 commit comments