|
1 | 1 | #[=============================================================================[ |
2 | | -# CheckStrptime |
| 2 | +Check 'strptime()' and its declaration. |
3 | 3 |
|
4 | | -Check `strptime()` and its declaration. |
| 4 | +Note: This module is obsolete. PHP 'strptime()' is deprecated as of PHP 8.1.0 |
| 5 | +and strptime(), where available, simply needs the _GNU_SOURCE defined or |
| 6 | +compiler flag -std=gnuXX appended to be declared in time.h. |
5 | 7 |
|
6 | | -Note: This module is obsolete. PHP `strptime()` is deprecated as of PHP 8.1.0. |
| 8 | +Result variables: |
7 | 9 |
|
8 | | -## Cache variables |
9 | | -
|
10 | | -* `HAVE_STRPTIME` |
11 | | -
|
12 | | - Whether `strptime()` is available. |
13 | | -
|
14 | | -## Result variables |
15 | | -
|
16 | | -* `HAVE_STRPTIME_DECL_FAILS` |
17 | | -
|
18 | | - Whether `strptime()` declaration fails. |
19 | | -
|
20 | | -## Usage |
21 | | -
|
22 | | -```cmake |
23 | | -# CMakeLists.txt |
24 | | -include(cmake/CheckStrptime.cmake) |
25 | | -``` |
| 10 | +* HAVE_STRPTIME |
| 11 | +* HAVE_STRPTIME_DECL_FAILS |
26 | 12 | #]=============================================================================] |
27 | 13 |
|
28 | 14 | include_guard(GLOBAL) |
29 | 15 |
|
30 | 16 | include(CheckFunctionExists) |
31 | | -include(CheckSourceCompiles) |
32 | 17 | include(CheckSymbolExists) |
33 | 18 | include(CMakePushCheckState) |
34 | 19 |
|
35 | 20 | if(PHP_VERSION VERSION_GREATER_EQUAL 9.0) |
36 | 21 | message( |
37 | 22 | DEPRECATION |
38 | | - "PHP/CheckStrptime module is obsolete and should be removed. PHP " |
39 | | - "'strptime()' function is deprecated as of PHP 8.1.0." |
| 23 | + "CheckStrptime module is obsolete and should be removed. PHP 'strptime()' " |
| 24 | + "function is deprecated as of PHP 8.1.0." |
40 | 25 | ) |
41 | 26 | endif() |
42 | 27 |
|
| 28 | +set(HAVE_STRPTIME FALSE) |
| 29 | +set(HAVE_STRPTIME_DECL_FAILS FALSE) |
| 30 | + |
| 31 | +if(CMAKE_SYSTEM_NAME STREQUAL "Windows") |
| 32 | + return() |
| 33 | +endif() |
| 34 | + |
43 | 35 | cmake_push_check_state(RESET) |
44 | 36 | set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) |
45 | | - check_symbol_exists(strptime time.h HAVE_STRPTIME) |
| 37 | + check_symbol_exists(strptime time.h PHP_EXT_STANDARD_HAS_STRPTIME) |
46 | 38 | cmake_pop_check_state() |
47 | 39 |
|
48 | | -if(HAVE_STRPTIME) |
| 40 | +if(PHP_EXT_STANDARD_HAS_STRPTIME) |
| 41 | + set(HAVE_STRPTIME TRUE) |
49 | 42 | set(HAVE_STRPTIME_DECL_FAILS TRUE) |
50 | 43 | return() |
51 | 44 | endif() |
52 | 45 |
|
53 | | -# The rest of this module is obsolete because strptime(), where available, |
54 | | -# simply needs the _GNU_SOURCE defined or compiler flag -std=gnuXX appended to |
55 | | -# be declared in time.h. This part can be removed in favor of the above |
56 | | -# check_symbol_exists(). |
57 | | - |
58 | 46 | # Check if linker sees the function. |
59 | | -if(NOT HAVE_STRPTIME) |
60 | | - unset(HAVE_STRPTIME CACHE) |
61 | | - check_function_exists(strptime HAVE_STRPTIME) |
62 | | -endif() |
| 47 | +check_function_exists(strptime PHP_EXT_STANDARD_HAS_STRPTIME_FUNCTION) |
63 | 48 |
|
64 | | -if(NOT HAVE_STRPTIME) |
| 49 | +if(PHP_EXT_STANDARD_HAS_STRPTIME_FUNCTION) |
| 50 | + set(HAVE_STRPTIME TRUE) |
65 | 51 | return() |
66 | 52 | endif() |
67 | | - |
68 | | -message(CHECK_START "Checking whether strptime() is declared") |
69 | | - |
70 | | -cmake_push_check_state(RESET) |
71 | | - set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) |
72 | | - set(CMAKE_REQUIRED_QUIET TRUE) |
73 | | - |
74 | | - # Use invalid declaration to see if it fails to compile. |
75 | | - check_source_compiles(C [[ |
76 | | - #include <time.h> |
77 | | - int main(void) |
78 | | - { |
79 | | - int strptime(const char *s, const char *format, struct tm *tm); |
80 | | - return 0; |
81 | | - } |
82 | | - ]] HAVE_STRPTIME_DECL) |
83 | | -cmake_pop_check_state() |
84 | | - |
85 | | -if(NOT HAVE_STRPTIME_DECL) |
86 | | - message(CHECK_PASS "yes") |
87 | | - set(HAVE_STRPTIME_DECL_FAILS TRUE) |
88 | | -else() |
89 | | - message(CHECK_FAIL "no") |
90 | | -endif() |
0 commit comments