Skip to content

Commit 54785a5

Browse files
committed
Simplify CheckStrptime module
1 parent d03329e commit 54785a5

File tree

1 file changed

+22
-60
lines changed

1 file changed

+22
-60
lines changed
Lines changed: 22 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,52 @@
11
#[=============================================================================[
2-
# CheckStrptime
2+
Check 'strptime()' and its declaration.
33
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.
57
6-
Note: This module is obsolete. PHP `strptime()` is deprecated as of PHP 8.1.0.
8+
Result variables:
79
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
2612
#]=============================================================================]
2713

2814
include_guard(GLOBAL)
2915

3016
include(CheckFunctionExists)
31-
include(CheckSourceCompiles)
3217
include(CheckSymbolExists)
3318
include(CMakePushCheckState)
3419

3520
if(PHP_VERSION VERSION_GREATER_EQUAL 9.0)
3621
message(
3722
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."
4025
)
4126
endif()
4227

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+
4335
cmake_push_check_state(RESET)
4436
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)
4638
cmake_pop_check_state()
4739

48-
if(HAVE_STRPTIME)
40+
if(PHP_EXT_STANDARD_HAS_STRPTIME)
41+
set(HAVE_STRPTIME TRUE)
4942
set(HAVE_STRPTIME_DECL_FAILS TRUE)
5043
return()
5144
endif()
5245

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-
5846
# 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)
6348

64-
if(NOT HAVE_STRPTIME)
49+
if(PHP_EXT_STANDARD_HAS_STRPTIME_FUNCTION)
50+
set(HAVE_STRPTIME TRUE)
6551
return()
6652
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

Comments
 (0)