Skip to content

Commit 31265a6

Browse files
committed
Update and refactor checks
- CheckTiocgwinsz.cmake - CheckTtynameR.cmake - CheckArmCrc32.cmake - CheckStrptime.cmake - CheckClockGetTime.cmake (checking for clock_get_time() is obsolete) on current POSIX systems clock_gettime() should be used similar to ext/opcache/jir/ir/ir_perf.c.
1 parent aca6ebf commit 31265a6

File tree

6 files changed

+161
-160
lines changed

6 files changed

+161
-160
lines changed

cmake/cmake/toolchains/template.cmake

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ set(ZEND_MM_EXITCODE__TRYRUN_OUTPUT "(size_t)8 (size_t)3 0")
5454
# sapi/fpm
5555
################################################################################
5656

57-
# Set the exit code for the clock_get_time() check.
58-
set(PHP_SAPI_FPM_HAS_CLOCK_GET_TIME_EXITCODE 0)
59-
6057
# Set the exit code of the ptrace() check.
6158
set(PHP_SAPI_FPM_HAS_PTRACE_EXITCODE 0)
6259

Lines changed: 75 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,100 @@
11
#[=============================================================================[
2-
Check ttyname_r().
3-
2+
This check determines whether the ttyname_r() is present and works as expected.
43
On Solaris/illumos ttyname_r() works only with larger buffers (>= 128), unlike,
5-
for example, on Linux and other systems, where buffer size can be any
6-
'size_t' size, also < 128. PHP code uses ttyname_r() with large buffers, so it
7-
wouldn't be necessary to check small buffers but the run check below is kept for
8-
brevity.
4+
for example, on Linux and other systems, where buffer size can be any 'size_t'
5+
size, also < 128. PHP code uses ttyname_r() with large buffers, so it wouldn't
6+
be necessary to check small buffers but the run check below is kept for brevity.
97
108
On modern systems a simpler check is sufficient in the future:
119
12-
check_symbol_exists(ttyname_r unistd.h HAVE_TTYNAME_R)
13-
14-
Result variables:
15-
16-
* HAVE_TTYNAME_R - Whether ttyname_r() works as expected.
10+
check_symbol_exists(ttyname_r unistd.h <result-var>)
1711
#]=============================================================================]
1812

19-
include_guard(GLOBAL)
20-
2113
include(CheckPrototypeDefinition)
2214
include(CheckSourceRuns)
2315
include(CMakePushCheckState)
2416
include(PHP/SystemExtensions)
2517

26-
set(HAVE_TTYNAME_R FALSE)
18+
function(_php_ext_posix_check_ttyname_r result)
19+
set(${result} FALSE)
2720

28-
# Skip in consecutive configuration phases.
29-
if(
30-
DEFINED PHP_EXT_POSIX_HAS_TTYNAME_R_PROTOTYPE
31-
OR DEFINED PHP_EXT_POSIX_HAS_TTYNAME_R
32-
)
3321
if(PHP_EXT_POSIX_HAS_TTYNAME_R)
34-
set(HAVE_TTYNAME_R TRUE)
35-
endif()
36-
37-
return()
38-
endif()
39-
40-
message(CHECK_START "Checking for working ttyname_r()")
41-
42-
cmake_push_check_state(RESET)
43-
cmake_language(GET_MESSAGE_LOG_LEVEL log_level)
44-
if(NOT log_level MATCHES "^(VERBOSE|DEBUG|TRACE)$")
45-
set(CMAKE_REQUIRED_QUIET TRUE)
46-
endif()
47-
48-
# To get the standard declaration with return type int instead of the char *:
49-
# - _POSIX_PTHREAD_SEMANTICS is needed on Solaris<=11.3 and illumos
50-
# - _DARWIN_C_SOURCE on older Mac OS X 10.4
51-
set(CMAKE_REQUIRED_LIBRARIES PHP::SystemExtensions)
52-
53-
check_prototype_definition(
54-
ttyname_r
55-
"int ttyname_r(int fd, char *buf, size_t buflen)"
56-
"0"
57-
"unistd.h"
58-
PHP_EXT_POSIX_HAS_TTYNAME_R_PROTOTYPE
59-
)
60-
61-
if(NOT PHP_EXT_POSIX_HAS_TTYNAME_R_PROTOTYPE)
62-
message(CHECK_FAIL "no (non-standard declaration)")
63-
cmake_pop_check_state()
64-
return()
22+
set(${result} TRUE)
23+
return(PROPAGATE ${result})
6524
endif()
6625

67-
if(
68-
CMAKE_CROSSCOMPILING
69-
AND NOT CMAKE_CROSSCOMPILING_EMULATOR
70-
AND NOT DEFINED PHP_EXT_POSIX_HAS_TTYNAME_R_EXITCODE
71-
)
72-
set(PHP_EXT_POSIX_HAS_TTYNAME_R_EXITCODE 0)
26+
if(DEFINED PHP_EXT_POSIX_HAS_TTYNAME_R_SYMBOL)
27+
return(PROPAGATE ${result})
7328
endif()
7429

75-
# PHP Autotools-based build system check uses a different return below due
76-
# to Autoconf's configure using the file descriptor 0 which results in an
77-
# error. The file descriptor 0 with CMake script execution is available and
78-
# doesn't result in an error when calling ttyname_r().
79-
check_source_runs(C [[
80-
#include <unistd.h>
81-
82-
int main(void)
83-
{
84-
#ifdef _SC_TTY_NAME_MAX
85-
int buflen = sysconf(_SC_TTY_NAME_MAX);
86-
#else
87-
int buflen = 32; /* Small buffers < 128 */
88-
#endif
89-
if (buflen < 1) {
90-
buflen = 32;
30+
message(CHECK_START "Checking for working ttyname_r()")
31+
32+
cmake_push_check_state(RESET)
33+
cmake_language(GET_MESSAGE_LOG_LEVEL log_level)
34+
if(NOT log_level MATCHES "^(VERBOSE|DEBUG|TRACE)$")
35+
set(CMAKE_REQUIRED_QUIET TRUE)
36+
endif()
37+
38+
# To get the standard declaration with return type int instead of the
39+
# 'char *':
40+
# - _POSIX_PTHREAD_SEMANTICS is needed on Solaris<=11.3 and illumos
41+
# - _DARWIN_C_SOURCE on older Mac OS X 10.4
42+
set(CMAKE_REQUIRED_LIBRARIES PHP::SystemExtensions)
43+
44+
check_prototype_definition(
45+
ttyname_r
46+
"int ttyname_r(int fd, char *buf, size_t buflen)"
47+
"0"
48+
"unistd.h"
49+
PHP_EXT_POSIX_HAS_TTYNAME_R_SYMBOL
50+
)
51+
52+
if(NOT PHP_EXT_POSIX_HAS_TTYNAME_R_SYMBOL)
53+
message(CHECK_FAIL "no (non-standard declaration)")
54+
cmake_pop_check_state()
55+
return(PROPAGATE ${result})
56+
endif()
57+
58+
if(
59+
CMAKE_CROSSCOMPILING
60+
AND NOT CMAKE_CROSSCOMPILING_EMULATOR
61+
AND NOT DEFINED PHP_EXT_POSIX_HAS_TTYNAME_R_EXITCODE
62+
)
63+
set(PHP_EXT_POSIX_HAS_TTYNAME_R_EXITCODE 0)
64+
endif()
65+
66+
# PHP Autotools-based build system check uses a different return below due
67+
# to Autoconf's configure using the file descriptor 0 which results in an
68+
# error. The file descriptor 0 with CMake script execution is available
69+
# and doesn't result in an error when calling ttyname_r().
70+
check_source_runs(C [[
71+
#include <unistd.h>
72+
73+
int main(void)
74+
{
75+
#ifdef _SC_TTY_NAME_MAX
76+
int buflen = sysconf(_SC_TTY_NAME_MAX);
77+
#else
78+
int buflen = 32; /* Small buffers < 128 */
79+
#endif
80+
if (buflen < 1) {
81+
buflen = 32;
82+
}
83+
char buf[buflen];
84+
85+
return ttyname_r(0, buf, buflen) ? 1 : 0;
9186
}
92-
char buf[buflen];
87+
]] PHP_EXT_POSIX_HAS_TTYNAME_R)
88+
cmake_pop_check_state()
9389

94-
return ttyname_r(0, buf, buflen) ? 1 : 0;
95-
}
96-
]] PHP_EXT_POSIX_HAS_TTYNAME_R)
9790
if(PHP_EXT_POSIX_HAS_TTYNAME_R)
98-
set(HAVE_TTYNAME_R TRUE)
91+
set(${result} TRUE)
9992
message(CHECK_PASS "yes")
10093
else()
10194
message(CHECK_FAIL "no (posix_ttyname() will be thread-unsafe)")
10295
endif()
103-
cmake_pop_check_state()
96+
97+
return(PROPAGATE ${result})
98+
endfunction()
99+
100+
_php_ext_posix_check_ttyname_r(HAVE_TTYNAME_R)

cmake/ext/standard/cmake/CheckArmCrc32.cmake

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,23 @@
11
#[=============================================================================[
22
Check whether CRC32 API is supported on ARM architecture.
3-
4-
Result variables:
5-
6-
* HAVE_AARCH64_CRC32
73
#]=============================================================================]
84

9-
if(DEFINED PHP_EXT_STANDARD_HAS_ARM_CRC32)
10-
set(HAVE_AARCH64_CRC32 FALSE)
5+
include(CheckSourceCompiles)
6+
include(CMakePushCheckState)
7+
8+
function(_php_ext_standard_check_arm_crc32 result)
9+
set(${result} FALSE)
1110

1211
if(PHP_EXT_STANDARD_HAS_ARM_CRC32)
13-
set(HAVE_AARCH64_CRC32 TRUE)
12+
set(${result} TRUE)
1413
endif()
1514

16-
return()
17-
endif()
18-
19-
include(CheckSourceCompiles)
20-
include(CMakePushCheckState)
21-
22-
include_guard(GLOBAL)
15+
if(DEFINED PHP_EXT_STANDARD_HAS_ARM_CRC32)
16+
return(PROPAGATE ${result})
17+
endif()
2318

24-
function(_php_ext_standard_check_arm_crc32 result)
2519
message(CHECK_START "Checking for ARM CRC32 API availability")
2620

27-
set(${result} FALSE)
28-
2921
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
3022
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "ARM64")
3123
set(${result} TRUE)

cmake/ext/standard/cmake/CheckStrptime.cmake

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@ Check 'strptime()' and its declaration.
33
44
Note: This module is obsolete. PHP 'strptime()' is deprecated as of PHP 8.1.0
55
and strptime(), where available, simply needs the _GNU_SOURCE defined or
6-
compiler flag -std=gnuXX appended to be declared in time.h.
7-
8-
Result variables:
9-
10-
* HAVE_STRPTIME
11-
* HAVE_STRPTIME_DECL_FAILS
6+
compiler flag -std=gnuXX appended to be declared in <time.h>.
127
#]=============================================================================]
138

149
include_guard(GLOBAL)
@@ -48,5 +43,4 @@ check_function_exists(strptime PHP_EXT_STANDARD_HAS_STRPTIME_FUNCTION)
4843

4944
if(PHP_EXT_STANDARD_HAS_STRPTIME_FUNCTION)
5045
set(HAVE_STRPTIME TRUE)
51-
return()
5246
endif()

cmake/sapi/fpm/cmake/CheckClockGetTime.cmake

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
Check for clock_get*time.
33
#]=============================================================================]
44

5-
include_guard(GLOBAL)
6-
75
include(CheckSourceRuns)
86
include(CMakePushCheckState)
97
include(PHP/SearchLibraries)
@@ -18,12 +16,24 @@ php_search_libraries(
1816
)
1917
set(HAVE_CLOCK_GETTIME ${PHP_SAPI_FPM_HAS_CLOCK_GETTIME})
2018

19+
# Checking for working clock_get_time() on macOS systems is obsolete as of macOS
20+
# Sierra (10.12) where the clock_gettime() was added.
2121
if(
2222
NOT PHP_SAPI_FPM_HAS_CLOCK_GETTIME
2323
AND NOT DEFINED PHP_SAPI_FPM_HAS_CLOCK_GET_TIME
2424
)
2525
message(CHECK_START "Checking for clock_get_time()")
2626

27+
# When crosscompiling, check only whether the test code builds and assume it
28+
# also runs.
29+
if(
30+
CMAKE_CROSSCOMPILING
31+
AND NOT CMAKE_CROSSCOMPILING_EMULATOR
32+
AND NOT DEFINED PHP_SAPI_FPM_HAS_CLOCK_GET_TIME_EXITCODE
33+
)
34+
set(PHP_SAPI_FPM_HAS_CLOCK_GET_TIME_EXITCODE 0)
35+
endif()
36+
2737
cmake_push_check_state(RESET)
2838
set(CMAKE_REQUIRED_QUIET TRUE)
2939
check_source_runs(C [[
@@ -59,4 +69,8 @@ if(
5969
endif()
6070
endif()
6171

62-
set(HAVE_CLOCK_GET_TIME ${PHP_SAPI_FPM_HAS_CLOCK_GET_TIME})
72+
if(PHP_SAPI_FPM_HAS_CLOCK_GET_TIME)
73+
set(HAVE_CLOCK_GET_TIME TRUE)
74+
else()
75+
set(HAVE_CLOCK_GET_TIME FALSE)
76+
endif()

0 commit comments

Comments
 (0)