@@ -19,11 +19,18 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "^alpha")
19
19
endif ()
20
20
endif ()
21
21
22
- # Check for broken GCC optimize-strlen.
23
- include (PHP/CheckBrokenGccStrlenOpt )
24
- if (PHP_HAVE_BROKEN_OPTIMIZE_STRLEN )
25
- php_check_compiler_flag (C -fno-optimize-strlen HAVE_FNO_OPTIMIZE_STRLEN_C )
26
- if (HAVE_FNO_OPTIMIZE_STRLEN_C )
22
+ # Check if GCC has broken strlen() optimization. Early GCC 8 versions shipped
23
+ # with a strlen() optimization bug, so it didn't properly handle the
24
+ # 'char val[1]' struct hack. Fixed in GCC 8.3. If below check is successful the
25
+ # '-fno-optimize-strlen' compiler flag should be added.
26
+ # See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86914
27
+ if (
28
+ CMAKE_C_COMPILER_ID STREQUAL "GNU"
29
+ AND DEFINED CMAKE_C_COMPILER_VERSION
30
+ AND CMAKE_C_COMPILER_VERSION VERSION_LESS 8.3
31
+ )
32
+ php_check_compiler_flag (C -fno-optimize-strlen PHP_HAS_FNO_OPTIMIZE_STRLEN_C )
33
+ if (PHP_HAS_FNO_OPTIMIZE_STRLEN_C )
27
34
target_compile_options (
28
35
php_config
29
36
INTERFACE
@@ -32,28 +39,28 @@ if(PHP_HAVE_BROKEN_OPTIMIZE_STRLEN)
32
39
endif ()
33
40
endif ()
34
41
35
- php_check_compiler_flag (C -Wno-sign-compare HAVE_WNO_SIGN_COMPARE_C )
42
+ php_check_compiler_flag (C -Wno-sign-compare PHP_HAS_WNO_SIGN_COMPARE_C )
36
43
if (CXX IN_LIST enabledLanguages )
37
- php_check_compiler_flag (CXX -Wno-sign-compare HAVE_WNO_SIGN_COMPARE_CXX )
44
+ php_check_compiler_flag (CXX -Wno-sign-compare PHP_HAS_WNO_SIGN_COMPARE_CXX )
38
45
endif ()
39
46
target_compile_options (
40
47
php_config
41
48
BEFORE
42
49
INTERFACE
43
- $< $< AND:$< BOOL:${HAVE_WNO_SIGN_COMPARE_C } > ,$< COMPILE_LANGUAGE:ASM,C> > :-Wno-sign-compare>
44
- $< $< AND:$< BOOL:${HAVE_WNO_SIGN_COMPARE_CXX } > ,$< COMPILE_LANGUAGE:CXX> > :-Wno-sign-compare>
50
+ $< $< AND:$< BOOL:${PHP_HAS_WNO_SIGN_COMPARE_C } > ,$< COMPILE_LANGUAGE:ASM,C> > :-Wno-sign-compare>
51
+ $< $< AND:$< BOOL:${PHP_HAS_WNO_SIGN_COMPARE_CXX } > ,$< COMPILE_LANGUAGE:CXX> > :-Wno-sign-compare>
45
52
)
46
53
47
- php_check_compiler_flag (C -Wno-unused-parameter HAVE_WNO_UNUSED_PARAMETER_C )
54
+ php_check_compiler_flag (C -Wno-unused-parameter PHP_HAS_WNO_UNUSED_PARAMETER_C )
48
55
if (CXX IN_LIST enabledLanguages )
49
- php_check_compiler_flag (CXX -Wno-unused-parameter HAVE_WNO_UNUSED_PARAMETER_CXX )
56
+ php_check_compiler_flag (CXX -Wno-unused-parameter PHP_HAS_WNO_UNUSED_PARAMETER_CXX )
50
57
endif ()
51
58
target_compile_options (
52
59
php_config
53
60
BEFORE
54
61
INTERFACE
55
- $< $< AND:$< BOOL:${HAVE_WNO_UNUSED_PARAMETER_C } > ,$< COMPILE_LANGUAGE:ASM,C> > :-Wno-unused-parameter>
56
- $< $< AND:$< BOOL:${HAVE_WNO_UNUSED_PARAMETER_CXX } > ,$< COMPILE_LANGUAGE:CXX> > :-Wno-unused-parameter>
62
+ $< $< AND:$< BOOL:${PHP_HAS_WNO_UNUSED_PARAMETER_C } > ,$< COMPILE_LANGUAGE:ASM,C> > :-Wno-unused-parameter>
63
+ $< $< AND:$< BOOL:${PHP_HAS_WNO_UNUSED_PARAMETER_CXX } > ,$< COMPILE_LANGUAGE:CXX> > :-Wno-unused-parameter>
57
64
)
58
65
59
66
if (MSVC )
@@ -73,99 +80,99 @@ else()
73
80
endif ()
74
81
75
82
# Check if compiler supports -Wno-clobbered (only GCC).
76
- php_check_compiler_flag (C -Wno-clobbered HAVE_WNO_CLOBBERED_C )
83
+ php_check_compiler_flag (C -Wno-clobbered PHP_HAS_WNO_CLOBBERED_C )
77
84
if (CXX IN_LIST enabledLanguages )
78
- php_check_compiler_flag (CXX -Wno-clobbered HAVE_WNO_CLOBBERED_CXX )
85
+ php_check_compiler_flag (CXX -Wno-clobbered PHP_HAS_WNO_CLOBBERED_CXX )
79
86
endif ()
80
87
target_compile_options (
81
88
php_config
82
89
BEFORE
83
90
INTERFACE
84
- $< $< AND:$< BOOL:${HAVE_WNO_CLOBBERED_C } > ,$< COMPILE_LANGUAGE:ASM,C> > :-Wno-clobbered>
85
- $< $< AND:$< BOOL:${HAVE_WNO_CLOBBERED_CXX } > ,$< COMPILE_LANGUAGE:CXX> > :-Wno-clobbered>
91
+ $< $< AND:$< BOOL:${PHP_HAS_WNO_CLOBBERED_C } > ,$< COMPILE_LANGUAGE:ASM,C> > :-Wno-clobbered>
92
+ $< $< AND:$< BOOL:${PHP_HAS_WNO_CLOBBERED_CXX } > ,$< COMPILE_LANGUAGE:CXX> > :-Wno-clobbered>
86
93
)
87
94
88
95
# Check for support for implicit fallthrough level 1, also add after previous
89
96
# CFLAGS as level 3 is enabled in -Wextra.
90
97
php_check_compiler_flag (
91
98
C
92
99
-Wimplicit-fallthrough=1
93
- HAVE_WIMPLICIT_FALLTHROUGH_1_C
100
+ PHP_HAS_WIMPLICIT_FALLTHROUGH_1_C
94
101
)
95
102
if (CXX IN_LIST enabledLanguages )
96
103
php_check_compiler_flag (
97
104
CXX
98
105
-Wimplicit-fallthrough=1
99
- HAVE_WIMPLICIT_FALLTHROUGH_1_CXX
106
+ PHP_HAS_WIMPLICIT_FALLTHROUGH_1_CXX
100
107
)
101
108
endif ()
102
109
target_compile_options (
103
110
php_config
104
111
INTERFACE
105
- $< $< AND:$< BOOL:${HAVE_WIMPLICIT_FALLTHROUGH_1_C } > ,$< COMPILE_LANGUAGE:ASM,C> > :-Wimplicit-fallthrough=1>
106
- $< $< AND:$< BOOL:${HAVE_WIMPLICIT_FALLTHROUGH_1_CXX } > ,$< COMPILE_LANGUAGE:CXX> > :-Wimplicit-fallthrough=1>
112
+ $< $< AND:$< BOOL:${PHP_HAS_WIMPLICIT_FALLTHROUGH_1_C } > ,$< COMPILE_LANGUAGE:ASM,C> > :-Wimplicit-fallthrough=1>
113
+ $< $< AND:$< BOOL:${PHP_HAS_WIMPLICIT_FALLTHROUGH_1_CXX } > ,$< COMPILE_LANGUAGE:CXX> > :-Wimplicit-fallthrough=1>
107
114
)
108
115
109
- php_check_compiler_flag (C -Wduplicated-cond HAVE_WDUPLICATED_COND_C )
116
+ php_check_compiler_flag (C -Wduplicated-cond PHP_HAS_WDUPLICATED_COND_C )
110
117
if (CXX IN_LIST enabledLanguages )
111
- php_check_compiler_flag (CXX -Wduplicated-cond HAVE_WDUPLICATED_COND_CXX )
118
+ php_check_compiler_flag (CXX -Wduplicated-cond PHP_HAS_WDUPLICATED_COND_CXX )
112
119
endif ()
113
120
target_compile_options (
114
121
php_config
115
122
BEFORE
116
123
INTERFACE
117
- $< $< AND:$< BOOL:${HAVE_WDUPLICATED_COND_C } > ,$< COMPILE_LANGUAGE:ASM,C> > :-Wduplicated-cond>
118
- $< $< AND:$< BOOL:${HAVE_WDUPLICATED_COND_CXX } > ,$< COMPILE_LANGUAGE:CXX> > :-Wduplicated-cond>
124
+ $< $< AND:$< BOOL:${PHP_HAS_WDUPLICATED_COND_C } > ,$< COMPILE_LANGUAGE:ASM,C> > :-Wduplicated-cond>
125
+ $< $< AND:$< BOOL:${PHP_HAS_WDUPLICATED_COND_CXX } > ,$< COMPILE_LANGUAGE:CXX> > :-Wduplicated-cond>
119
126
)
120
127
121
- php_check_compiler_flag (C -Wlogical-op HAVE_WLOGICAL_OP_C )
128
+ php_check_compiler_flag (C -Wlogical-op PHP_HAS_WLOGICAL_OP_C )
122
129
if (CXX IN_LIST enabledLanguages )
123
- php_check_compiler_flag (CXX -Wlogical-op HAVE_WLOGICAL_OP_CXX )
130
+ php_check_compiler_flag (CXX -Wlogical-op PHP_HAS_WLOGICAL_OP_CXX )
124
131
endif ()
125
132
target_compile_options (
126
133
php_config
127
134
BEFORE
128
135
INTERFACE
129
- $< $< AND:$< BOOL:${HAVE_WLOGICAL_OP_C } > ,$< COMPILE_LANGUAGE:ASM,C> > :-Wlogical-op>
130
- $< $< AND:$< BOOL:${HAVE_WLOGICAL_OP_CXX } > ,$< COMPILE_LANGUAGE:CXX> > :-Wlogical-op>
136
+ $< $< AND:$< BOOL:${PHP_HAS_WLOGICAL_OP_C } > ,$< COMPILE_LANGUAGE:ASM,C> > :-Wlogical-op>
137
+ $< $< AND:$< BOOL:${PHP_HAS_WLOGICAL_OP_CXX } > ,$< COMPILE_LANGUAGE:CXX> > :-Wlogical-op>
131
138
)
132
139
133
- php_check_compiler_flag (C -Wformat-truncation HAVE_WFORMAT_TRUNCATION_C )
140
+ php_check_compiler_flag (C -Wformat-truncation PHP_HAS_WFORMAT_TRUNCATION_C )
134
141
if (CXX IN_LIST enabledLanguages )
135
- php_check_compiler_flag (CXX -Wformat-truncation HAVE_WFORMAT_TRUNCATION_CXX )
142
+ php_check_compiler_flag (CXX -Wformat-truncation PHP_HAS_WFORMAT_TRUNCATION_CXX )
136
143
endif ()
137
144
target_compile_options (
138
145
php_config
139
146
BEFORE
140
147
INTERFACE
141
- $< $< AND:$< BOOL:${HAVE_WFORMAT_TRUNCATION_C } > ,$< COMPILE_LANGUAGE:ASM,C> > :-Wformat-truncation>
142
- $< $< AND:$< BOOL:${HAVE_WFORMAT_TRUNCATION_CXX } > ,$< COMPILE_LANGUAGE:CXX> > :-Wformat-truncation>
148
+ $< $< AND:$< BOOL:${PHP_HAS_WFORMAT_TRUNCATION_C } > ,$< COMPILE_LANGUAGE:ASM,C> > :-Wformat-truncation>
149
+ $< $< AND:$< BOOL:${PHP_HAS_WFORMAT_TRUNCATION_CXX } > ,$< COMPILE_LANGUAGE:CXX> > :-Wformat-truncation>
143
150
)
144
151
145
- php_check_compiler_flag (C -Wstrict-prototypes HAVE_WSTRICT_PROTOTYPES_C )
152
+ php_check_compiler_flag (C -Wstrict-prototypes PHP_HAS_WSTRICT_PROTOTYPES_C )
146
153
target_compile_options (
147
154
php_config
148
155
BEFORE
149
156
INTERFACE
150
- $< $< AND:$< BOOL:${HAVE_WSTRICT_PROTOTYPES_C } > ,$< COMPILE_LANGUAGE:ASM,C> > :-Wstrict-prototypes>
157
+ $< $< AND:$< BOOL:${PHP_HAS_WSTRICT_PROTOTYPES_C } > ,$< COMPILE_LANGUAGE:ASM,C> > :-Wstrict-prototypes>
151
158
)
152
159
153
- php_check_compiler_flag (C -fno-common HAVE_FNO_COMMON_C )
160
+ php_check_compiler_flag (C -fno-common PHP_HAS_FNO_COMMON_C )
154
161
if (CXX IN_LIST enabledLanguages )
155
- php_check_compiler_flag (CXX -fno-common HAVE_FNO_COMMON_CXX )
162
+ php_check_compiler_flag (CXX -fno-common PHP_HAS_FNO_COMMON_CXX )
156
163
endif ()
157
164
target_compile_options (
158
165
php_config
159
166
BEFORE
160
167
INTERFACE
161
- $< $< AND:$< BOOL:${HAVE_FNO_COMMON_C } > ,$< COMPILE_LANGUAGE:ASM,C> > :-fno-common>
162
- $< $< AND:$< BOOL:${HAVE_FNO_COMMON_CXX } > ,$< COMPILE_LANGUAGE:CXX> > :-fno-common>
168
+ $< $< AND:$< BOOL:${PHP_HAS_FNO_COMMON_C } > ,$< COMPILE_LANGUAGE:ASM,C> > :-fno-common>
169
+ $< $< AND:$< BOOL:${PHP_HAS_FNO_COMMON_CXX } > ,$< COMPILE_LANGUAGE:CXX> > :-fno-common>
163
170
)
164
171
165
172
# Explicitly disable floating-point expression contraction, even if already done
166
173
# by CMAKE_C_STANDARD. See https://github.com/php/php-src/issues/14140
167
- php_check_compiler_flag (C -ffp-contract=off HAVE_FFP_CONTRACT_OFF_C )
168
- if (HAVE_FFP_CONTRACT_OFF_C )
174
+ php_check_compiler_flag (C -ffp-contract=off PHP_HAS_FFP_CONTRACT_OFF_C )
175
+ if (PHP_HAS_FFP_CONTRACT_OFF_C )
169
176
target_compile_options (
170
177
php_config
171
178
INTERFACE
@@ -198,19 +205,19 @@ if(PHP_MEMORY_SANITIZER)
198
205
php_check_compiler_flag (
199
206
C
200
207
"-fsanitize=memory;-fsanitize-memory-track-origins"
201
- HAVE_MEMORY_SANITIZER_C
208
+ PHP_HAS_MEMORY_SANITIZER_C
202
209
)
203
210
204
211
if (CXX IN_LIST enabledLanguages )
205
212
php_check_compiler_flag (
206
213
CXX
207
214
"-fsanitize=memory;-fsanitize-memory-track-origins"
208
- HAVE_MEMORY_SANITIZER_CXX
215
+ PHP_HAS_MEMORY_SANITIZER_CXX
209
216
)
210
217
endif ()
211
218
cmake_pop_check_state ()
212
219
213
- if (HAVE_MEMORY_SANITIZER_C OR HAVE_MEMORY_SANITIZER_CXX )
220
+ if (PHP_HAS_MEMORY_SANITIZER_C OR PHP_HAS_MEMORY_SANITIZER_CXX )
214
221
target_compile_options (
215
222
php_config
216
223
INTERFACE
@@ -246,13 +253,13 @@ if(PHP_ADDRESS_SANITIZER)
246
253
cmake_push_check_state (RESET )
247
254
set (CMAKE_REQUIRED_LINK_OPTIONS "-fsanitize=address" )
248
255
249
- php_check_compiler_flag (C -fsanitize=address HAVE_ADDRESS_SANITIZER_C )
256
+ php_check_compiler_flag (C -fsanitize=address PHP_HAS_ADDRESS_SANITIZER_C )
250
257
if (CXX IN_LIST enabledLanguages )
251
- php_check_compiler_flag (CXX -fsanitize=address HAVE_ADDRESS_SANITIZER_CXX )
258
+ php_check_compiler_flag (CXX -fsanitize=address PHP_HAS_ADDRESS_SANITIZER_CXX )
252
259
endif ()
253
260
cmake_pop_check_state ()
254
261
255
- if (HAVE_ADDRESS_SANITIZER_C OR HAVE_ADDRESS_SANITIZER_CXX )
262
+ if (PHP_HAS_ADDRESS_SANITIZER_C OR PHP_HAS_ADDRESS_SANITIZER_CXX )
256
263
target_compile_options (
257
264
php_config
258
265
INTERFACE
@@ -288,18 +295,18 @@ if(PHP_UNDEFINED_SANITIZER)
288
295
php_check_compiler_flag (
289
296
C
290
297
-fsanitize=undefined
291
- HAVE_UNDEFINED_SANITIZER_C
298
+ PHP_HAS_UNDEFINED_SANITIZER_C
292
299
)
293
300
if (CXX IN_LIST enabledLanguages )
294
301
php_check_compiler_flag (
295
302
CXX
296
303
-fsanitize=undefined
297
- HAVE_UNDEFINED_SANITIZER_CXX
304
+ PHP_HAS_UNDEFINED_SANITIZER_CXX
298
305
)
299
306
endif ()
300
307
cmake_pop_check_state ()
301
308
302
- if (HAVE_UNDEFINED_SANITIZER_C OR HAVE_UNDEFINED_SANITIZER_CXX )
309
+ if (PHP_HAS_UNDEFINED_SANITIZER_C OR PHP_HAS_UNDEFINED_SANITIZER_CXX )
303
310
target_compile_options (
304
311
php_config
305
312
INTERFACE
@@ -320,18 +327,18 @@ if(PHP_UNDEFINED_SANITIZER)
320
327
php_check_compiler_flag (
321
328
C
322
329
-fno-sanitize=object-size
323
- HAVE_OBJECT_SIZE_SANITIZER_C
330
+ PHP_HAS_OBJECT_SIZE_SANITIZER_C
324
331
)
325
332
if (CXX IN_LIST enabledLanguages )
326
333
php_check_compiler_flag (
327
334
CXX
328
335
-fno-sanitize=object-size
329
- HAVE_OBJECT_SIZE_SANITIZER_CXX
336
+ PHP_HAS_OBJECT_SIZE_SANITIZER_CXX
330
337
)
331
338
endif ()
332
339
cmake_pop_check_state ()
333
340
334
- if (HAVE_OBJECT_SIZE_SANITIZER_C OR HAVE_OBJECT_SIZE_SANITIZER_CXX )
341
+ if (PHP_HAS_OBJECT_SIZE_SANITIZER_C OR PHP_HAS_OBJECT_SIZE_SANITIZER_CXX )
335
342
target_compile_options (
336
343
php_config
337
344
INTERFACE
@@ -348,15 +355,15 @@ if(PHP_UNDEFINED_SANITIZER)
348
355
# Clang 17 adds stricter function pointer compatibility checks where pointer
349
356
# args cannot be cast to void*. In that case, set -fno-sanitize=function.
350
357
if (
351
- NOT DEFINED PHP_HAVE_UBSAN_EXITCODE
358
+ NOT DEFINED PHP_HAS_UBSAN_EXITCODE
352
359
AND CMAKE_CROSSCOMPILING
353
360
AND NOT CMAKE_CROSSCOMPILING_EMULATOR
354
361
AND CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang"
355
362
AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 17
356
363
)
357
364
# When cross-compiling without emulator and using Clang 17 and greater,
358
365
# assume that -fno-sanitize=function needs to be added.
359
- set (PHP_HAVE_UBSAN_EXITCODE 1 )
366
+ set (PHP_HAS_UBSAN_EXITCODE 1 )
360
367
endif ()
361
368
362
369
cmake_push_check_state (RESET )
@@ -372,32 +379,32 @@ if(PHP_UNDEFINED_SANITIZER)
372
379
f("foo");
373
380
return 0;
374
381
}
375
- ]] PHP_HAVE_UBSAN )
382
+ ]] PHP_HAS_UBSAN )
376
383
cmake_pop_check_state ()
377
384
378
- if (NOT PHP_HAVE_UBSAN )
385
+ if (NOT PHP_HAS_UBSAN )
379
386
php_check_compiler_flag (
380
387
C
381
388
-fno-sanitize=function
382
- HAVE_FNO_SANITIZE_FUNCTION_C
389
+ PHP_HAS_FNO_SANITIZE_FUNCTION_C
383
390
)
384
391
if (CXX IN_LIST enabledLanguages )
385
392
php_check_compiler_flag (
386
393
CXX
387
394
-fno-sanitize=function
388
- HAVE_FNO_SANITIZE_FUNCTION_CXX
395
+ PHP_HAS_FNO_SANITIZE_FUNCTION_CXX
389
396
)
390
397
endif ()
391
398
392
- if (HAVE_FNO_SANITIZE_FUNCTION_C )
399
+ if (PHP_HAS_FNO_SANITIZE_FUNCTION_C )
393
400
target_compile_options (
394
401
php_config
395
402
INTERFACE
396
403
$< $< COMPILE_LANGUAGE:ASM,C> :-fno-sanitize=function>
397
404
)
398
405
endif ()
399
406
400
- if (HAVE_FNO_SANITIZE_FUNCTION_CXX )
407
+ if (PHP_HAS_FNO_SANITIZE_FUNCTION_CXX )
401
408
target_compile_options (
402
409
php_config
403
410
INTERFACE
@@ -417,25 +424,25 @@ if(PHP_MEMORY_SANITIZER OR PHP_ADDRESS_SANITIZER OR PHP_UNDEFINED_SANITIZER)
417
424
php_check_compiler_flag (
418
425
C
419
426
-fno-omit-frame-pointer
420
- HAVE_FNO_OMIT_FRAME_POINTER_C
427
+ PHP_HAS_FNO_OMIT_FRAME_POINTER_C
421
428
)
422
429
if (CXX IN_LIST enabledLanguages )
423
430
php_check_compiler_flag (
424
431
CXX
425
432
-fno-omit-frame-pointer
426
- HAVE_FNO_OMIT_FRAME_POINTER_CXX
433
+ PHP_HAS_FNO_OMIT_FRAME_POINTER_CXX
427
434
)
428
435
endif ()
429
436
430
- if (HAVE_FNO_OMIT_FRAME_POINTER_C )
437
+ if (PHP_HAS_FNO_OMIT_FRAME_POINTER_C )
431
438
target_compile_options (
432
439
php_config
433
440
INTERFACE
434
441
$< $< COMPILE_LANGUAGE:ASM,C> :-fno-omit-frame-pointer>
435
442
)
436
443
endif ()
437
444
438
- if (HAVE_FNO_OMIT_FRAME_POINTER_CXX )
445
+ if (PHP_HAS_FNO_OMIT_FRAME_POINTER_CXX )
439
446
target_compile_options (
440
447
php_config
441
448
INTERFACE
0 commit comments