Skip to content

Commit 0183f88

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
2 parents e347c46 + 74a6c67 commit 0183f88

File tree

9 files changed

+136
-124
lines changed

9 files changed

+136
-124
lines changed

cmake/cmake/BuildTypes.cmake

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,47 @@ Configure CMake build types.
55
include_guard(GLOBAL)
66

77
block()
8-
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
9-
get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
8+
get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
109

10+
# Set default build type for single-config generators.
11+
if(NOT isMultiConfig AND NOT CMAKE_BUILD_TYPE)
12+
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY VALUE "Debug")
13+
endif()
14+
15+
if(PROJECT_IS_TOP_LEVEL)
1116
if(isMultiConfig)
1217
if(NOT "DebugAssertions" IN_LIST CMAKE_CONFIGURATION_TYPES)
1318
list(APPEND CMAKE_CONFIGURATION_TYPES DebugAssertions)
1419
endif()
1520
else()
1621
set(
1722
allowedBuildTypes
18-
Debug
19-
MinSizeRel
20-
Release
21-
RelWithDebInfo
22-
DebugAssertions # Custom build type with debug assertions enabled in
23-
# release mode.
23+
Debug # Debug info, assertions, not optimized.
24+
DebugAssertions # Custom PHP debug build type with assertions enabled
25+
# in the release mode. TODO: Adjust the flags.
26+
MinSizeRel # Optimized for size rather than speed.
27+
Release # No debug info, no assertions, optimized.
28+
RelWithDebInfo # Debug info, optimized, no assertions.
2429
)
2530

2631
set_property(
2732
CACHE CMAKE_BUILD_TYPE
2833
PROPERTY STRINGS "${allowedBuildTypes}"
2934
)
3035

31-
if(NOT CMAKE_BUILD_TYPE)
32-
set(CMAKE_BUILD_TYPE Debug CACHE STRING "" FORCE)
33-
elseif(NOT CMAKE_BUILD_TYPE IN_LIST allowedBuildTypes)
36+
set_property(
37+
CACHE CMAKE_BUILD_TYPE
38+
PROPERTY HELPSTRING
39+
"Choose the type of build, options are: ${allowedBuildTypes}"
40+
)
41+
42+
if(NOT CMAKE_BUILD_TYPE IN_LIST allowedBuildTypes)
3443
message(FATAL_ERROR "Unknown build type: ${CMAKE_BUILD_TYPE}")
3544
endif()
3645
endif()
3746
endif()
3847
endblock()
3948

40-
# TODO: Remove this in favor of generator expressions. Multi configuration
41-
# generators are otherwise not checked here like this.
42-
if(CMAKE_BUILD_TYPE MATCHES "^(Debug|DebugAssertions)$")
43-
set(PHP_DEBUG TRUE)
44-
set(ZEND_DEBUG 1 CACHE INTERNAL "Whether to enable debugging")
45-
endif()
46-
4749
target_compile_definitions(
4850
php_configuration
4951
INTERFACE

cmake/cmake/Configuration.cmake

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -217,25 +217,12 @@ block()
217217

218218
if(PHP_LAYOUT STREQUAL "GNU")
219219
set(extension_dir "${extension_dir}/${zend_module_api_no}")
220-
221-
# TODO: When apache2handler SAPI enforces the thread safe build (as done
222-
# in the Autotools), the PHP_THREAD_SAFETY variable isn't yet available.
223-
if(PHP_THREAD_SAFETY)
224-
set(extension_dir "${extension_dir}-zts")
225-
endif()
226-
227-
set(extension_dir "${extension_dir}$<IF:$<CONFIG:Debug>,-debug,>")
220+
set(extension_dir "${extension_dir}$<$<BOOL:$<TARGET_PROPERTY:php_configuration,PHP_THREAD_SAFETY>>:-zts>")
221+
set(extension_dir "${extension_dir}$<IF:$<CONFIG:Debug,DebugAssertions>,-debug,>")
228222
else()
229223
set(extension_dir "${extension_dir}/extensions")
230-
231-
set(extension_dir "${extension_dir}/$<IF:$<CONFIG:Debug>,debug,no-debug>")
232-
233-
if(PHP_THREAD_SAFETY)
234-
set(extension_dir "${extension_dir}-zts")
235-
else()
236-
set(extension_dir "${extension_dir}-non-zts")
237-
endif()
238-
224+
set(extension_dir "${extension_dir}/$<IF:$<CONFIG:Debug,DebugAssertions>,debug,no-debug>")
225+
set(extension_dir "${extension_dir}$<IF:$<BOOL:$<TARGET_PROPERTY:php_configuration,PHP_THREAD_SAFETY>>,-zts,-non-zts>")
239226
set(extension_dir "${extension_dir}-${zend_module_api_no}")
240227
endif()
241228

cmake/cmake/modules/PHP/Extensions.cmake

Lines changed: 60 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,54 @@ https://bugs.php.net/53141
3434
TODO: Improve this or simplify the sorting complexities in its entierity. PHP
3535
dependencies are handled very basically ATM.
3636
37-
Exposed macro:
37+
## Exposed macro
3838
3939
```cmake
4040
php_extensions_add(subdirectory)
4141
```
42+
43+
## Custom CMake properties
44+
45+
* `PHP_ALL_EXTENSIONS`
46+
47+
Global property with a list of all PHP extensions in the ext directory.
48+
49+
* `PHP_ALWAYS_ENABLED_EXTENSIONS`
50+
51+
This global property contains a list of always enabled PHP extensions which
52+
don't need the `HAVE_<extension-name>` preprocessor macros defined in the PHP
53+
configuration header and can be considered as part of the core PHP engine.
54+
55+
* `PHP_EXTENSIONS`
56+
57+
This global property contains a list of all enabled PHP extensions for the
58+
current configuration. Extensions are sorted by the directory priority (see
59+
`PHP_PRIORITY` property) and extension dependencies (added with CMake command
60+
`add_dependencies()`).
61+
62+
* `PHP_PRIORITY`
63+
64+
This optional directory property controls the order of the PHP extensions
65+
added with the `add_subdirectory()`. Directory added with `add_subdirectory()`
66+
won't be visible in the configuration phase for the directories added before.
67+
Priority number can be used to add the extension subdirectory prior (0..100)
68+
or later (\>100) to other extensions. By default extensions are sorted
69+
alphabetically and added in between. This enables having extension variables
70+
visible in depending extensions.
71+
72+
* `PHP_ZEND_EXTENSION`
73+
74+
Extensions can utilize this custom target property, which designates the
75+
extension as a Zend extension rather than a standard PHP extension. Zend
76+
extensions function similarly to regular PHP extensions, but they are loaded
77+
using the `zend_extension` INI directive and possess an internally distinct
78+
structure with additional hooks. Typically employed for advanced
79+
functionalities like debuggers and profilers, Zend extensions offer enhanced
80+
capabilities.
81+
82+
```cmake
83+
set_target_properties(php_<extension_name> PROPERTIES PHP_ZEND_EXTENSION TRUE)
84+
```
4285
#]=============================================================================]
4386

4487
include_guard(GLOBAL)
@@ -47,42 +90,16 @@ include_guard(GLOBAL)
4790
# CMake custom properties.
4891
################################################################################
4992

50-
define_property(
51-
DIRECTORY
52-
PROPERTY PHP_PRIORITY
53-
BRIEF_DOCS "Controls when to add subdirectory in the configuration phase"
54-
FULL_DOCS "This optional property controls the order of the extensions added "
55-
"with add_subdirectory(). Directory added with add_subdirectory() "
56-
"won't be visible in the configuration phase for the directories "
57-
"added before. Priority number can be used to add the extension "
58-
"subdirectory prior (0..100) or later (>100) to other extensions. "
59-
"By default extensions are sorted alphabetically and added in "
60-
"between. This enables having extension variables visible in "
61-
"depending extensions."
62-
)
63-
64-
define_property(
65-
TARGET
66-
PROPERTY PHP_ZEND_EXTENSION
67-
BRIEF_DOCS "Whether the extension target is Zend extension"
68-
)
69-
7093
define_property(
7194
GLOBAL
72-
PROPERTY PHP_EXTENSIONS
73-
BRIEF_DOCS "A list of all enabled extensions"
74-
FULL_DOCS "This property contains a list of all enabled extensions for the "
75-
"current configuration. Extensions are sorted by the directory "
76-
"priority and their dependencies."
95+
PROPERTY PHP_ALL_EXTENSIONS
96+
BRIEF_DOCS "A list of all extensions in the ext directory"
7797
)
7898

7999
define_property(
80100
GLOBAL
81101
PROPERTY PHP_ALWAYS_ENABLED_EXTENSIONS
82102
BRIEF_DOCS "A list of always enabled PHP extensions"
83-
FULL_DOCS "This property contains a list of always enabled PHP extensions "
84-
"which don't need HAVE_<extension-name> symbols and can be "
85-
"considered as part of the core PHP engine."
86103
)
87104

88105
set_property(GLOBAL PROPERTY PHP_ALWAYS_ENABLED_EXTENSIONS
@@ -98,8 +115,20 @@ set_property(GLOBAL PROPERTY PHP_ALWAYS_ENABLED_EXTENSIONS
98115

99116
define_property(
100117
GLOBAL
101-
PROPERTY PHP_ALL_EXTENSIONS
102-
BRIEF_DOCS "A list of all extensions in the ext directory"
118+
PROPERTY PHP_EXTENSIONS
119+
BRIEF_DOCS "A list of all enabled extensions"
120+
)
121+
122+
define_property(
123+
DIRECTORY
124+
PROPERTY PHP_PRIORITY
125+
BRIEF_DOCS "Controls when to add subdirectory in the configuration phase"
126+
)
127+
128+
define_property(
129+
TARGET
130+
PROPERTY PHP_ZEND_EXTENSION
131+
BRIEF_DOCS "Whether the extension target is Zend extension"
103132
)
104133

105134
################################################################################

cmake/cmake/modules/PHP/PkgConfigGenerator.cmake

Lines changed: 10 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ pkgconfig_generate_pc(
1919
<pc-template-file>
2020
<pc-file-output>
2121
TARGET <target>
22-
[INSTALL_DESTINATION <path>]
23-
[VARIABLES [<variable> <value>] [<variable_2>:BOOL <value_2>...] ...]
24-
[SKIP_BOOL_NORMALIZATION]
22+
[VARIABLES <variable> <value> ...]
2523
)
2624
```
2725
@@ -30,19 +28,16 @@ template.
3028
3129
* `TARGET`
3230
Name of the target for getting libraries.
33-
* `INSTALL_DESTINATION`
34-
Path to the pkgconfig directory where generated .pc file will be installed to.
35-
Usually it is `${CMAKE_INSTALL_LIBDIR}/pkgconfig`. If not provided, .pc file
36-
will not be installed.
3731
* `VARIABLES`
38-
Pairs of variable names and values. To pass booleans, append ':BOOL' to the
39-
variable name. For example:
32+
Pairs of variable names and values. Variable values support generator
33+
expressions. For example:
4034
4135
```cmake
4236
pkgconfig_generate_pc(
4337
...
4438
VARIABLES
45-
variable_name:BOOL "${variable_name}"
39+
debug "$<IF:$<CONFIG:Debug>,yes,no>"
40+
variable "$<IF:$<BOOL:${VARIABLE}>,yes,no>"
4641
)
4742
```
4843
@@ -54,13 +49,6 @@ template.
5449
The custom PHP specific `$<PHP_EXPAND:path>` generator expression can be used
5550
in variable values. It is automatically replaced to `<install-prefix>/path`
5651
if `path` is relative, or to just `path` if `path` is absolute.
57-
58-
* `SKIP_BOOL_NORMALIZATION`
59-
CMake booleans have values `yes`, `no`, `true`, `false`, `on`, `off`, `1`,
60-
`0`, they can even be case insensitive and so on. By default, all booleans
61-
(`var:BOOL`, see above) are normalized to values `yes` or `no`. If this option
62-
is given, boolean values are replaced in .pc template with the CMake format
63-
instead (they will be replaced to `ON` or `OFF` and similar).
6452
#]=============================================================================]
6553

6654
include_guard(GLOBAL)
@@ -97,20 +85,6 @@ function(_pkgconfig_parse_variables variables)
9785
endif()
9886
list(POP_FRONT variables var value)
9987

100-
# Normalize boolean values to either "yes" or "no".
101-
if(var MATCHES ".*:BOOL$" AND NOT parsed_SKIP_BOOL_NORMALIZATION)
102-
if(value)
103-
set(value "yes")
104-
else()
105-
set(value "no")
106-
endif()
107-
endif()
108-
109-
# Remove possible :<TYPE> part from the variable name.
110-
if(var MATCHES "(.*):BOOL$")
111-
set(var ${CMAKE_MATCH_1})
112-
endif()
113-
11488
list(APPEND result_variables ${var})
11589

11690
if(value MATCHES [[^\$<PHP_EXPAND:(.*)>.*]])
@@ -169,10 +143,10 @@ function(pkgconfig_generate_pc)
169143
cmake_parse_arguments(
170144
PARSE_ARGV
171145
2
172-
parsed # prefix
173-
"SKIP_BOOL_NORMALIZATION" # options
174-
"TARGET;INSTALL_DESTINATION" # one-value keywords
175-
"VARIABLES" # multi-value keywords
146+
parsed # prefix
147+
"" # options
148+
"TARGET" # one-value keywords
149+
"VARIABLES" # multi-value keywords
176150
)
177151

178152
if(parsed_UNPARSED_ARGUMENTS)
@@ -271,8 +245,6 @@ function(pkgconfig_generate_pc)
271245
COMMENT "[PkgConfig] Generating pkg-config ${filename} file"
272246
)
273247

274-
cmake_path(GET output FILENAME output_file)
275-
276248
install(CODE "
277249
block()
278250
set(result_variables ${result_variables})
@@ -284,17 +256,9 @@ function(pkgconfig_generate_pc)
284256
285257
configure_file(
286258
${template}
287-
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${output_file}
259+
${output}
288260
@ONLY
289261
)
290262
endblock()
291263
")
292-
293-
if(parsed_INSTALL_DESTINATION)
294-
install(
295-
FILES
296-
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${output_file}
297-
DESTINATION ${parsed_INSTALL_DESTINATION}
298-
)
299-
endif()
300264
endfunction()

cmake/cmake/modules/PHP/ThreadSafety.cmake

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,35 @@
11
#[=============================================================================[
22
Check for thread safety, a.k.a. ZTS (Zend thread safety) build.
33
4-
Cache variables:
4+
## Cache variables
55
66
* `ZTS`
7+
78
Whether PHP thread safety is enabled.
9+
10+
## Custom CMake properties
11+
12+
* `PHP_THREAD_SAFETY`
13+
14+
When thread safety is enabled (either by the configuration variable
15+
`PHP_THREAD_SAFETY` or automatically by the `apache2handler` PHP SAPI module),
16+
also a custom target property `PHP_THREAD_SAFETY` is added to the
17+
`PHP::configuration` target, which can be then used in generator expressions
18+
during the generation phase to determine thread safety enabled from the
19+
configuration phase. For example, the `PHP_EXTENSION_DIR` configuration
20+
variable needs to be set depending on the thread safety.
821
#]=============================================================================]
922

1023
include_guard(GLOBAL)
1124

1225
include(FeatureSummary)
1326

27+
define_property(
28+
TARGET
29+
PROPERTY PHP_THREAD_SAFETY
30+
BRIEF_DOCS "Whether the PHP has thread safety enabled"
31+
)
32+
1433
function(_php_thread_safety)
1534
message(CHECK_START "Checking whether to enable thread safety (ZTS)")
1635

@@ -49,6 +68,9 @@ function(_php_thread_safety)
4968
# directly available. For example, some Zend headers.
5069
target_compile_definitions(php_configuration INTERFACE ZTS)
5170

71+
# Set custom target property on the PHP configuration target.
72+
set_target_properties(php_configuration PROPERTIES PHP_THREAD_SAFETY ON)
73+
5274
# Add compile definitions for POSIX threads conformance.
5375
# TODO: Recheck these definitions since many of them are deprecated or
5476
# obsolete in favor of the compiler automatic definitions when using threading

0 commit comments

Comments
 (0)