|
| 1 | +#[=============================================================================[ |
| 2 | +Check for reentrant functions and their declarations. |
| 3 | +
|
| 4 | +Some systems didn't declare some reentrant functions if '_REENTRANT' or |
| 5 | +'_POSIX_C_SOURCE' was not defined (certain versions of mingw etc.). This is |
| 6 | +mostly obsolete. The CMake's 'check_symbol_exists()' is sufficient to check for |
| 7 | +reentrant functions on current systems and this check might be obsolete in the |
| 8 | +future. |
| 9 | +
|
| 10 | +Result variables: |
| 11 | +
|
| 12 | +* HAVE_ASCTIME_R - Whether asctime_r() is available. |
| 13 | +* HAVE_CTIME_R - Whether ctime_r() is available. |
| 14 | +* HAVE_GMTIME_R - Whether gmtime_r() is available. |
| 15 | +* HAVE_LOCALTIME_R - Whether localtime_r() is available. |
| 16 | +* HAVE_STRTOK_R - Whether strtok_r() is available. |
| 17 | +* MISSING_ASCTIME_R_DECL - Whether asctime_r() is not declared. |
| 18 | +* MISSING_CTIME_R_DECL - Whether ctime_r() is not declared. |
| 19 | +* MISSING_GMTIME_R_DECL - Whether gmtime_r() is not declared. |
| 20 | +* MISSING_LOCALTIME_R_DECL - Whether localtime_r() is not declared. |
| 21 | +* MISSING_STRTOK_R_DECL - Whether `strtok_r()` is not declared. |
| 22 | +
|
| 23 | +Also the type of reentrant time-related functions are checked. Type can be irix, |
| 24 | +hpux or POSIX. This check is obsolete as it is relevant for obsolete systems. |
| 25 | +
|
| 26 | +Cache variables: |
| 27 | +
|
| 28 | +* PHP_HPUX_TIME_R - Whether HP-UX 10.x is used. |
| 29 | +* PHP_IRIX_TIME_R - Whether IRIX-style functions are used. |
| 30 | +#]=============================================================================] |
| 31 | + |
| 32 | +include_guard(GLOBAL) |
| 33 | + |
| 34 | +include(CheckFunctionExists) |
| 35 | +include(CheckSourceRuns) |
| 36 | +include(CheckSymbolExists) |
| 37 | + |
| 38 | +# Define HAVE_<symbol> if linker sees the function, and MISSING_<symbol>_DECL if |
| 39 | +# function is not declared by checking the required header and test body. |
| 40 | +function(_php_check_reentrant_function symbol header) |
| 41 | + string(TOUPPER "${symbol}" const) |
| 42 | + |
| 43 | + set(HAVE_${const} FALSE) |
| 44 | + set(MISSING_${const}_DECL TRUE) |
| 45 | + |
| 46 | + # Reentrant functions checked in this module aren't available on Windows. |
| 47 | + if(CMAKE_SYSTEM_NAME STREQUAL "Windows") |
| 48 | + return(PROPAGATE HAVE_${const} MISSING_${const}_DECL) |
| 49 | + endif() |
| 50 | + |
| 51 | + check_symbol_exists(${symbol} "${header}" PHP_HAS_${const}) |
| 52 | + |
| 53 | + if(PHP_HAS_${const}) |
| 54 | + set(HAVE_${const} TRUE) |
| 55 | + set(MISSING_${const}_DECL FALSE) |
| 56 | + |
| 57 | + return(PROPAGATE HAVE_${const} MISSING_${const}_DECL) |
| 58 | + endif() |
| 59 | + |
| 60 | + check_function_exists(${symbol} PHP_HAS_FUNCTION_${const}) |
| 61 | + |
| 62 | + if(PHP_HAS_FUNCTION_${const}) |
| 63 | + set(HAVE_${const} TRUE) |
| 64 | + |
| 65 | + return(PROPAGATE HAVE_${const} MISSING_${const}_DECL) |
| 66 | + endif() |
| 67 | + |
| 68 | + return(PROPAGATE HAVE_${const} MISSING_${const}_DECL) |
| 69 | +endfunction() |
| 70 | + |
| 71 | +_php_check_reentrant_function(asctime_r time.h) |
| 72 | +_php_check_reentrant_function(ctime_r time.h) |
| 73 | +_php_check_reentrant_function(gmtime_r time.h) |
| 74 | +_php_check_reentrant_function(localtime_r time.h) |
| 75 | +_php_check_reentrant_function(strtok_r string.h) |
| 76 | + |
| 77 | +################################################################################ |
| 78 | +# Check type of reentrant time-related functions. |
| 79 | +################################################################################ |
| 80 | + |
| 81 | +if(NOT HAVE_ASCTIME_R OR NOT HAVE_GMTIME_R) |
| 82 | + return() |
| 83 | +endif() |
| 84 | + |
| 85 | +# Skip in consecutive configuration phases. |
| 86 | +if(DEFINED PHP_HPUX_TIME_R OR DEFINED PHP_IRIX_TIME_R) |
| 87 | + return() |
| 88 | +endif() |
| 89 | + |
| 90 | +# When cross-compiling, assume POSIX style. |
| 91 | +if(CMAKE_CROSSCOMPILING AND NOT CMAKE_CROSSCOMPILING_EMULATOR) |
| 92 | + set(PHP_HPUX_TIME_R_EXITCODE 1) |
| 93 | + set(PHP_IRIX_TIME_R_EXITCODE 1) |
| 94 | +endif() |
| 95 | + |
| 96 | +message(CHECK_START "Checking type of reentrant time-related functions") |
| 97 | + |
| 98 | +check_source_runs(C [[ |
| 99 | + #include <time.h> |
| 100 | +
|
| 101 | + int main(void) |
| 102 | + { |
| 103 | + char buf[27]; |
| 104 | + struct tm t; |
| 105 | + time_t old = 0; |
| 106 | + int r, s; |
| 107 | +
|
| 108 | + s = gmtime_r(&old, &t); |
| 109 | + r = (int) asctime_r(&t, buf, 26); |
| 110 | + if (r == s && s == 0) { |
| 111 | + return 0; |
| 112 | + } |
| 113 | +
|
| 114 | + return 1; |
| 115 | + } |
| 116 | +]] PHP_HPUX_TIME_R) |
| 117 | + |
| 118 | +if(NOT PHP_HPUX_TIME_R) |
| 119 | + check_source_runs(C [[ |
| 120 | + #include <time.h> |
| 121 | +
|
| 122 | + int main(void) |
| 123 | + { |
| 124 | + struct tm t, *s; |
| 125 | + time_t old = 0; |
| 126 | + char buf[27], *p; |
| 127 | +
|
| 128 | + s = gmtime_r(&old, &t); |
| 129 | + p = asctime_r(&t, buf, 26); |
| 130 | + if (p == buf && s == &t) { |
| 131 | + return 0; |
| 132 | + } |
| 133 | +
|
| 134 | + return 1; |
| 135 | + } |
| 136 | + ]] PHP_IRIX_TIME_R) |
| 137 | +endif() |
| 138 | + |
| 139 | +if(PHP_HPUX_TIME_R) |
| 140 | + message(CHECK_PASS "HP-UX") |
| 141 | +elseif(PHP_IRIX_TIME_R) |
| 142 | + message(CHECK_PASS "IRIX") |
| 143 | +else() |
| 144 | + message(CHECK_PASS "POSIX") |
| 145 | +endif() |
0 commit comments