Skip to content

Commit f7f225f

Browse files
committed
Sync Zend Engine and add various improvements
- Zend Engine configuration cleaned, synced and enhanced - All regex patterns fixed as `\t`, `\n` and other whitespace characters in double quoted arguments are actually expanded to literal strings. In bracket arguments they are replaced as literal backslash and letter which makes such regexes behave wrong. - Patches updated
1 parent d5ab942 commit f7f225f

26 files changed

+165
-139
lines changed

cmake/Zend/CMakeLists.txt

Lines changed: 37 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
#[=============================================================================[
22
Zend Engine.
33
4+
## Targets
5+
6+
* OBJECT library `zend` (ALIAS `Zend::Zend`) holds all Zend Engine objects
7+
and compile properties.
8+
9+
## Target properties
10+
411
CMake target properties for the `Zend::Zend` target:
512
613
* `VERSION`
@@ -27,18 +34,7 @@ message(STATUS "-----------------------")
2734
message(STATUS "Configuring Zend Engine")
2835
message(STATUS "-----------------------\n")
2936

30-
# Read the Zend Engine version.
31-
block(PROPAGATE Zend_VERSION Zend_VERSION_LABEL)
32-
file(READ zend.h content)
33-
string(
34-
REGEX MATCH
35-
[[#[ \t]*define[ \t]+ZEND_VERSION[ \t]+"([0-9.]+)([^"]*)]]
36-
_
37-
"${content}"
38-
)
39-
set(Zend_VERSION "${CMAKE_MATCH_1}")
40-
set(Zend_VERSION_LABEL "${CMAKE_MATCH_2}")
41-
endblock()
37+
include(cmake/Version.cmake)
4238

4339
project(
4440
Zend
@@ -47,9 +43,6 @@ project(
4743
LANGUAGES C ASM
4844
)
4945

50-
string(APPEND Zend_VERSION "${Zend_VERSION_LABEL}")
51-
message(STATUS "Zend Engine version: ${Zend_VERSION}")
52-
5346
include(CheckIncludeFile)
5447
include(CheckSourceCompiles)
5548
include(CheckSymbolExists)
@@ -315,33 +308,13 @@ target_compile_definitions(
315308
$<$<PLATFORM_ID:Windows>:LIBZEND_EXPORTS>
316309
)
317310

318-
block()
319-
file(READ zend_extensions.h content)
320-
string(
321-
REGEX MATCH
322-
"#[ \t]*define[ \t]+ZEND_EXTENSION_API_NO[ \t]+([0-9]+)"
323-
_
324-
"${content}"
325-
)
326-
set(zendExtensionApiNumber "${CMAKE_MATCH_1}")
327-
328-
file(READ zend_modules.h content)
329-
string(
330-
REGEX MATCH
331-
"#[ \t]*define[ \t]+ZEND_MODULE_API_NO[ \t]+([0-9]+)"
332-
_
333-
"${content}"
334-
)
335-
set(zendModuleApiNumber "${CMAKE_MATCH_1}")
336-
337-
set_target_properties(
338-
zend
339-
PROPERTIES
340-
VERSION ${Zend_VERSION}
341-
ZEND_EXTENSION_API_NO ${zendExtensionApiNumber}
342-
ZEND_MODULE_API_NO ${zendModuleApiNumber}
343-
)
344-
endblock()
311+
set_target_properties(
312+
zend
313+
PROPERTIES
314+
VERSION ${Zend_VERSION}
315+
ZEND_EXTENSION_API_NO ${Zend_VERSION_EXTENSION_API_NO}
316+
ZEND_MODULE_API_NO ${Zend_VERSION_MODULE_API_NO}
317+
)
345318

346319
# Add Zend PUBLIC/INTERFACE compile properties to configuration.
347320
# Cleaner COMPILE_ONLY generator expression is available in CMake >= 3.27.
@@ -493,17 +466,29 @@ else()
493466
message(CHECK_FAIL "no")
494467
endif()
495468

496-
# Check Zend signals.
469+
include(cmake/CheckDlsym.cmake)
470+
include(cmake/CheckFloatPrecision.cmake)
471+
472+
if(ZEND_GLOBAL_REGISTER_VARIABLES)
473+
include(cmake/CheckGlobalRegisterVariables.cmake)
474+
endif()
475+
476+
include(cmake/CheckMMAlignment.cmake)
477+
include(cmake/CheckStackDirection.cmake)
478+
include(cmake/CheckStrerrorR.cmake)
479+
480+
################################################################################
481+
# Zend signals.
482+
################################################################################
483+
497484
message(CHECK_START "Checking whether to enable Zend signal handling")
498485
check_symbol_exists(sigaction "signal.h" HAVE_SIGACTION)
499486
if(HAVE_SIGACTION AND ZEND_SIGNALS)
500487
message(CHECK_PASS "yes")
501488

502-
set_property(CACHE ZEND_SIGNALS PROPERTY VALUE ON)
503-
504489
# zend_config.h (or its parent php_config.h) isn't included in some zend_*
505-
# files, therefore also compilation definitions are added.
506-
target_compile_definitions(zend PRIVATE ZEND_SIGNALS)
490+
# files, therefore also compilation definition is added.
491+
target_compile_definitions(zend PUBLIC ZEND_SIGNALS)
507492
else()
508493
set_property(CACHE ZEND_SIGNALS PROPERTY VALUE OFF)
509494
message(CHECK_FAIL "no")
@@ -514,32 +499,15 @@ add_feature_info(
514499
"signals handling within the Zend Engine for performance"
515500
)
516501

517-
# Check Zend max execution timers.
502+
################################################################################
503+
# Zend max execution timers.
504+
################################################################################
505+
518506
include(cmake/MaxExecutionTimers.cmake)
519507
if(TARGET Zend::MaxExecutionTimers)
520508
target_link_libraries(zend PRIVATE Zend::MaxExecutionTimers)
521509
endif()
522510

523-
# Check if dlsym() needs underscore.
524-
include(cmake/CheckDlsym.cmake)
525-
526-
# Check MM alignment.
527-
include(cmake/CheckMMAlignment.cmake)
528-
529-
# Check for global register variables.
530-
if(ZEND_GLOBAL_REGISTER_VARIABLES)
531-
include(cmake/CheckGlobalRegisterVariables.cmake)
532-
endif()
533-
534-
# Check if stack grows downward.
535-
include(cmake/CheckStackLimit.cmake)
536-
537-
# Check float precision.
538-
include(cmake/CheckFloatPrecision.cmake)
539-
540-
# Check for strerror_r, and if its a POSIX-compatible or a GNU-specific version.
541-
include(cmake/CheckStrerrorR.cmake)
542-
543511
################################################################################
544512
# Generate lexers and parsers.
545513
################################################################################
@@ -682,7 +650,7 @@ if(NOT CMAKE_SIZEOF_VOID_P EQUAL 4)
682650
)
683651
endif()
684652

685-
configure_file(zend_config.cmake.h.in CMakeFiles/zend_config.h)
653+
configure_file(cmake/zend_config.h.in CMakeFiles/zend_config.h)
686654

687655
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
688656
message(STATUS "Creating Zend/zend_config.h")

cmake/Zend/cmake/CheckDlsym.cmake

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,41 +41,41 @@ block()
4141
DLSYM_NEEDS_UNDERSCORE_COMPILED
4242
SOURCE_FROM_CONTENT src.c [[
4343
#ifdef HAVE_DLFCN_H
44-
# include <dlfcn.h>
44+
# include <dlfcn.h>
4545
#endif
4646

4747
#include <stdio.h>
4848

4949
#ifdef RTLD_GLOBAL
50-
# define LT_DLGLOBAL RTLD_GLOBAL
50+
# define LT_DLGLOBAL RTLD_GLOBAL
5151
#else
52-
# ifdef DL_GLOBAL
53-
# define LT_DLGLOBAL DL_GLOBAL
54-
# else
55-
# define LT_DLGLOBAL 0
56-
# endif
52+
# ifdef DL_GLOBAL
53+
# define LT_DLGLOBAL DL_GLOBAL
54+
# else
55+
# define LT_DLGLOBAL 0
56+
# endif
5757
#endif
5858

5959
/* We may need to define LT_DLLAZY_OR_NOW on the command line if we
60-
discover that it does not work on some platform. */
60+
discover that it does not work on some platform. */
6161
#ifndef LT_DLLAZY_OR_NOW
62-
# ifdef RTLD_LAZY
63-
# define LT_DLLAZY_OR_NOW RTLD_LAZY
62+
# ifdef RTLD_LAZY
63+
# define LT_DLLAZY_OR_NOW RTLD_LAZY
64+
# else
65+
# ifdef DL_LAZY
66+
# define LT_DLLAZY_OR_NOW DL_LAZY
6467
# else
65-
# ifdef DL_LAZY
66-
# define LT_DLLAZY_OR_NOW DL_LAZY
68+
# ifdef RTLD_NOW
69+
# define LT_DLLAZY_OR_NOW RTLD_NOW
70+
# else
71+
# ifdef DL_NOW
72+
# define LT_DLLAZY_OR_NOW DL_NOW
6773
# else
68-
# ifdef RTLD_NOW
69-
# define LT_DLLAZY_OR_NOW RTLD_NOW
70-
# else
71-
# ifdef DL_NOW
72-
# define LT_DLLAZY_OR_NOW DL_NOW
73-
# else
74-
# define LT_DLLAZY_OR_NOW 0
75-
# endif
76-
# endif
74+
# define LT_DLLAZY_OR_NOW 0
7775
# endif
76+
# endif
7877
# endif
78+
# endif
7979
#endif
8080

8181
/* When -fvisibility=hidden is used, assume the code has been annotated

cmake/Zend/cmake/CheckFloatPrecision.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ See: https://wiki.php.net/rfc/rounding
99
1010
* `HAVE__FPU_SETCW`
1111
12-
Whether `_FPU_SETCW` is usable.
12+
Whether `_FPU_SETCW` is present and usable.
1313
1414
* `HAVE_FPSETPREC`
1515

cmake/Zend/cmake/CheckMMAlignment.cmake

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,15 @@ block(
7979
string(STRIP "${ZEND_MM_OUTPUT}" ZEND_MM_OUTPUT)
8080
string(REPLACE " " ";" ZEND_MM_OUTPUT "${ZEND_MM_OUTPUT}")
8181

82-
list(GET ZEND_MM_OUTPUT 0 zend_mm_alignment)
83-
list(GET ZEND_MM_OUTPUT 1 zend_mm_alignment_log2)
84-
list(GET ZEND_MM_OUTPUT 2 zend_mm_need_eight_byte_realignment)
82+
list(GET ZEND_MM_OUTPUT 0 ZEND_MM_ALIGNMENT)
83+
list(GET ZEND_MM_OUTPUT 1 ZEND_MM_ALIGNMENT_LOG2)
84+
list(GET ZEND_MM_OUTPUT 2 ZEND_MM_NEED_EIGHT_BYTE_REALIGNMENT)
8585
else()
8686
message(CHECK_FAIL "Failed")
8787
message(
8888
FATAL_ERROR
89-
"ZEND_MM alignment defines failed. Please, check CMake logs.")
89+
"ZEND_MM alignment values couldn't be determined.")
9090
endif()
91-
92-
set(ZEND_MM_ALIGNMENT ${zend_mm_alignment})
93-
set(ZEND_MM_ALIGNMENT_LOG2 ${zend_mm_alignment_log2})
94-
set(ZEND_MM_NEED_EIGHT_BYTE_REALIGNMENT ${zend_mm_need_eight_byte_realignment})
9591
endblock()
9692

9793
message(

cmake/Zend/cmake/CheckStackLimit.cmake renamed to cmake/Zend/cmake/CheckStackDirection.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#[=============================================================================[
2-
# CheckStackLimit
2+
# CheckStackDirection
33
44
Check whether the stack grows downwards. Assumes contiguous stack.
55
66
## Cache variables
77
8-
* `ZEND_CHECK_STACK_LIMIT
8+
* `ZEND_CHECK_STACK_LIMIT`
99
1010
Whether checking the stack limit is supported.
1111
#]=============================================================================]

cmake/Zend/cmake/CheckStrerrorR.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[=============================================================================[
22
# CheckStrerrorR
33
4-
Check for `strerror_r()`, and if its a POSIX-compatible or a GNU-specific
4+
Check whether `strerror_r()` is the POSIX-compatible version or the GNU-specific
55
version.
66
77
## Cache variables

cmake/Zend/cmake/MaxExecutionTimers.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Check whether to enable Zend max execution timers.
55
66
## Cache variables
77
8-
* [`ZEND_MAX_EXECUTION_TIMERS`](/docs/cmake/variables/ZEND_MAX_EXECUTION_TIMERS.md)
8+
* `ZEND_MAX_EXECUTION_TIMERS`
99
1010
* `HAVE_TIMER_CREATE`
1111

cmake/Zend/cmake/Version.cmake

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#[=============================================================================[
2+
Set Zend Engine version variables from the php-src/Zend/*.h header files.
3+
4+
Variables:
5+
6+
* `Zend_VERSION_EXTENSION_API_NO`
7+
* `Zend_VERSION_LABEL`
8+
* `Zend_VERSION_MODULE_API_NO`
9+
* `Zend_VERSION`
10+
#]=============================================================================]
11+
12+
include_guard(GLOBAL)
13+
14+
# Set Zend Engine version variables.
15+
block(PROPAGATE Zend_VERSION Zend_VERSION_LABEL)
16+
set(regex "^[ \t]*#[ \t]*define[ \t]+ZEND_VERSION[ \t]+\"([0-9.]+)([^\"]*)")
17+
file(STRINGS zend.h _ REGEX "${regex}")
18+
19+
if(CMAKE_VERSION VERSION_LESS 3.29)
20+
string(REGEX MATCH "${regex}" _ "${_}")
21+
endif()
22+
23+
set(Zend_VERSION "${CMAKE_MATCH_1}")
24+
set(Zend_VERSION_LABEL "${CMAKE_MATCH_2}")
25+
endblock()
26+
27+
# This is automatically executed with the project(Zend...) invocation.
28+
function(_zend_version_post_project)
29+
if(DEFINED Zend_VERSION_MODULE_API_NO)
30+
return()
31+
endif()
32+
33+
# Append extra version label suffix to version.
34+
string(APPEND Zend_VERSION "${Zend_VERSION_LABEL}")
35+
message(STATUS "Zend Engine version: ${Zend_VERSION}")
36+
37+
# Get extensions API number.
38+
set(regex "^[ \t]*#[ \t]*define[ \t]+ZEND_EXTENSION_API_NO[ \t]+([0-9]+)")
39+
file(STRINGS zend_extensions.h _ REGEX "${regex}")
40+
if(CMAKE_VERSION VERSION_LESS 3.29)
41+
string(REGEX MATCH "${regex}" _ "${_}")
42+
endif()
43+
set(Zend_VERSION_EXTENSION_API_NO "${CMAKE_MATCH_1}")
44+
45+
# Get modules API number.
46+
set(regex "^[ \t]*#[ \t]*define[ \t]+ZEND_MODULE_API_NO[ \t]+([0-9]+)")
47+
file(STRINGS zend_modules.h _ REGEX "${regex}")
48+
if(CMAKE_VERSION VERSION_LESS 3.29)
49+
string(REGEX MATCH "${regex}" _ "${_}")
50+
endif()
51+
set(Zend_VERSION_MODULE_API_NO "${CMAKE_MATCH_1}")
52+
53+
return(
54+
PROPAGATE
55+
Zend_VERSION
56+
Zend_VERSION_EXTENSION_API_NO
57+
Zend_VERSION_MODULE_API_NO
58+
)
59+
endfunction()
60+
variable_watch(Zend_DESCRIPTION _zend_version_post_project)
File renamed without changes.

0 commit comments

Comments
 (0)