Skip to content

Commit a64e4fd

Browse files
committed
Refactor internal CMake modules
Modules located in the cmake/modules/PHP directory should ideally be useful not only in php-src but also in PHP extensions scope. This separates internal modules that are only used when building php-src. Additionally, investigated the deprecated/obsolete prehistoric _REENTRANT and _THREAD_SAFE compile definitions further and added notes in the comments.
1 parent 3195f18 commit a64e4fd

File tree

8 files changed

+177
-207
lines changed

8 files changed

+177
-207
lines changed

cmake/CMakeLists.txt

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,25 @@ check_pie_supported()
8989
# Configure build types.
9090
include(cmake/BuildTypes.cmake)
9191

92+
# Check unused linked libraries on executable and shared/module library targets.
93+
include(PHP/LinkWhatYouUse)
94+
95+
# Enable C and POSIX extensions. The system extensions configuration will be
96+
# defined in the configuration header main/php_config.h. The php-src code at the
97+
# time of writing doesn't include this header in order to utilize them
98+
# everywhere properly. The main/php_config.h should be the first inclusion
99+
# before including any system header. Perhaps in php.h file. Until then, the
100+
# compile definitions also need to be added when compiling and using PHP API.
101+
# Mainly the _GNU_SOURCE.
102+
include(PHP/SystemExtensions)
103+
target_link_libraries(php_config INTERFACE PHP::SystemExtensions)
104+
92105
# Detect C standard library implementation.
93106
include(PHP/StandardLibrary)
94107

108+
# Define GNU standard installation directories.
109+
include(GNUInstallDirs)
110+
95111
# Set platform-specific configuration.
96112
include(cmake/Platform.cmake)
97113

@@ -125,8 +141,8 @@ add_subdirectory(scripts)
125141
# Generate *_arginfo.h headers from *.stub.php sources.
126142
include(PHP/Stubs)
127143

128-
# Check thread safety.
129-
include(PHP/ThreadSafety)
144+
# Configure PHP thread safety.
145+
include(cmake/ThreadSafety.cmake)
130146

131147
################################################################################
132148
# Execute all deferred calls. Calls are additionally sorted with natural
@@ -148,7 +164,7 @@ endblock()
148164

149165
# Rebuild all targets as needed.
150166
if(NOT PHPSystem_EXECUTABLE)
151-
include(PHP/Rebuild)
167+
include(cmake/Rebuild.cmake)
152168
endif()
153169

154170
# Enable testing and configure test settings.
@@ -157,8 +173,8 @@ include(cmake/Testing.cmake)
157173
# Enable and configure CPack module.
158174
include(cmake/CPack.cmake)
159175

160-
include(PHP/FeatureSummary)
161-
php_feature_summary()
176+
# Print build configuration summary.
177+
include(cmake/Summary.cmake)
162178

163179
message(
164180
STATUS

cmake/cmake/modules/PHP/Extensions.cmake renamed to cmake/cmake/Extensions.cmake

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,46 @@
11
#[=============================================================================[
2-
# PHP/Extensions
3-
42
Configure PHP extensions.
53
6-
This module is responsible for parsing `CMakeLists.txt` files of PHP extensions
7-
and sorting extensions based on the dependencies listed in the
8-
`add_dependencies()`. If an extension has specified dependencies, it ensures
9-
that all dependencies are automatically enabled. If any of the dependencies are
10-
built as `SHARED` libraries, the extension must also be built as a `SHARED`
11-
library.
4+
This internal module is responsible for parsing CMakeLists.txt files of PHP
5+
extensions and sorting extensions based on the dependencies listed in the
6+
add_dependencies(). If an extension has specified dependencies, it ensures that
7+
all dependencies are automatically enabled. If any of the dependencies are built
8+
as SHARED libraries, the extension must also be built as a SHARED library.
129
1310
Dependencies can be specified on top of the CMake's built-in command
14-
`add_dependencies()`, which builds target dependencies before the target itself.
15-
This module reads the `add_dependencies()` invocations in extensions
16-
CMakeLists.txt files and automatically enables and configures them as `SHARED`
11+
add_dependencies(), which builds target dependencies before the target itself.
12+
This internal module reads the add_dependencies() invocations in extensions
13+
CMakeLists.txt files and automatically enables and configures them as SHARED
1714
depending on the configuration if they haven't been explicitly configured. If it
1815
fails to configure extension dependencies automatically it will result in a
1916
fatal error at the end of the configuration phase.
2017
2118
Order of the extensions is then also important in the generated
22-
`main/internal_functions*.c` files (for the list of `phpext_<extension>_ptr` in
23-
the `zend_module_entry php_builtin_extensions`). This is the order of how the
24-
modules are registered into the Zend hash table.
19+
'main/internal_functions*.c' files (for the list of 'phpext_<extension>_ptr' in
20+
the 'zend_module_entry php_builtin_extensions'). This is the order of how the
21+
PHP modules are registered into the Zend hash table.
2522
2623
PHP internal API also provides dependencies handling with the
27-
`ZEND_MOD_REQUIRED`, `ZEND_MOD_CONFLICTS`, and `ZEND_MOD_OPTIONAL`, which should
24+
'ZEND_MOD_REQUIRED', 'ZEND_MOD_CONFLICTS', and 'ZEND_MOD_OPTIONAL', which should
2825
be set in the extension code itself. PHP internally then sorts the extensions
29-
based on the `ZEND_MOD_REQUIRED` and `ZEND_MOD_OPTIONAL`, so build time sorting
26+
based on the 'ZEND_MOD_REQUIRED' and 'ZEND_MOD_OPTIONAL', so build time sorting
3027
shouldn't be taken for granted and is mostly used for php-src builds.
3128
32-
Example why setting dependencies with `ZEND_MOD_REQUIRED` might matter:
29+
Example why setting dependencies with 'ZEND_MOD_REQUIRED' might matter:
3330
https://bugs.php.net/53141
3431
35-
## Custom CMake properties
32+
Custom CMake properties:
3633
37-
* `PHP_EXTENSION`
34+
* PHP_EXTENSION
3835
3936
Target property that designates that the CMake target is a PHP extension.
4037
41-
* `PHP_ZEND_EXTENSION`
38+
* PHP_ZEND_EXTENSION
4239
4340
Extensions can utilize this custom target property, which designates the
4441
extension as a Zend extension rather than a standard PHP extension. Zend
4542
extensions function similarly to regular PHP extensions, but they are loaded
46-
using the `zend_extension` INI directive and possess an internally distinct
43+
using the 'zend_extension' INI directive and possess an internally distinct
4744
structure with additional hooks. Typically employed for advanced
4845
functionalities like debuggers and profilers, Zend extensions offer enhanced
4946
capabilities.
@@ -52,17 +49,10 @@ https://bugs.php.net/53141
5249
set_target_properties(php_ext_<extension_name> PROPERTIES PHP_ZEND_EXTENSION TRUE)
5350
```
5451
55-
* `PHP_EXTENSION_<extension>_DEPS`
52+
* PHP_EXTENSION_<extension>_DEPS
5653
5754
Global property with a list of all dependencies of <extension> (name of the
5855
extension as named in ext directory).
59-
60-
## Usage
61-
62-
```cmake
63-
# CMakeLists.txt
64-
include(PHP/Extensions)
65-
```
6656
#]=============================================================================]
6757

6858
include_guard(GLOBAL)

cmake/cmake/Platform.cmake

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,6 @@ Platform-specific configuration.
44

55
include_guard(GLOBAL)
66

7-
# Check unused linked libraries on executable and shared/module library targets.
8-
include(PHP/LinkWhatYouUse)
9-
10-
# Enable C and POSIX extensions.
11-
include(PHP/SystemExtensions)
12-
13-
# The above system extensions will be defined in the main/php_config.h. The
14-
# php-src code at the time of writing doesn't include C headers in order to
15-
# utilize them. The main/php_config.h should be the first inclusion before
16-
# including any system header. Perhaps in php.h file. Until then, the compile
17-
# definitions also need to be added when compiling and using PHP API. Mainly the
18-
# _GNU_SOURCE.
19-
target_link_libraries(php_config INTERFACE PHP::SystemExtensions)
20-
21-
# Define GNU standard installation directories.
22-
include(GNUInstallDirs)
23-
247
# Platform-specific configuration. When cross-compiling, the host and target can
258
# be different values with different configurations.
269
if(NOT CMAKE_HOST_SYSTEM_NAME EQUAL CMAKE_SYSTEM_NAME)

cmake/cmake/modules/PHP/Rebuild.cmake renamed to cmake/cmake/Rebuild.cmake

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
#[=============================================================================[
2-
# PHP/Rebuild
3-
42
Ensure all project targets are rebuilt as needed.
53
6-
When PHP is not found on the system, the `php_sapi_cli` (alias `PHP::sapi::cli`)
7-
target is used to generate certain files during development. This can lead to
8-
cyclic dependencies among targets if custom commands depend on the
9-
`PHP::sapi::cli` target. While such automatic rebuilding is not considered good
10-
practice, it ensures that all targets are kept up to date.
4+
When PHP executable is not found on the system, the 'php_sapi_cli' (aliased
5+
'PHP::sapi::cli') target is used to generate certain files during development.
6+
This can lead to cyclic dependencies among targets if custom commands depend on
7+
the 'PHP::sapi::cli' target. While such automatic rebuilding is not considered
8+
good practice, it ensures that all targets are kept up to date.
119
1210
TODO: This works only for a limited set of cases for now and will be refactored.
13-
14-
## Usage
15-
16-
```cmake
17-
# CMakeLists.txt
18-
include(PHP/Rebuild)
19-
```
2011
#]=============================================================================]
2112

2213
include_guard(GLOBAL)

cmake/cmake/modules/PHP/FeatureSummary.cmake renamed to cmake/cmake/Summary.cmake

Lines changed: 22 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,18 @@
11
#[=============================================================================[
2-
# PHP/FeatureSummary
3-
4-
Print summary of enabled/disabled features.
5-
6-
This is built on top of the CMake's `FeatureSummary` module. It sorts feature
2+
This is built on top of the CMake's FeatureSummary module. It sorts feature
73
summary alphabetically and categorizes enabled features into SAPIs, extensions,
84
and other global PHP features. Common misconfiguration issues are summarized
95
together with missing required system packages.
106
117
See also: https://cmake.org/cmake/help/latest/module/FeatureSummary.html
12-
13-
## Functions
14-
15-
Output PHP configuration summary:
16-
17-
```cmake
18-
php_feature_summary()
19-
```
20-
21-
## Usage
22-
23-
```cmake
24-
# CMakeLists.txt
25-
26-
# Include module and output configuration summary
27-
include(PHP/FeatureSummary)
28-
php_feature_summary()
29-
```
308
#]=============================================================================]
319

3210
include_guard(GLOBAL)
3311

3412
include(FeatureSummary)
3513

3614
# Add new item to the summary preamble with dotted leader.
37-
function(php_feature_summary_preamble_add_item label value output)
15+
function(_php_summary_preamble_add_item label value output)
3816
# Template helper to calculate column width.
3917
set(template " * <label> .................... : <value>")
4018
string(REGEX MATCH "^ \\\* ([^ ]+ [.]+)" _ "${template}")
@@ -60,14 +38,14 @@ function(php_feature_summary_preamble_add_item label value output)
6038
endfunction()
6139

6240
# Get summary preamble.
63-
function(php_feature_summary_preamble result)
64-
php_feature_summary_preamble_add_item(
41+
function(_php_summary_preamble result)
42+
_php_summary_preamble_add_item(
6543
"${PROJECT_NAME} version"
6644
"${${PROJECT_NAME}_VERSION}"
6745
preamble
6846
)
6947

70-
php_feature_summary_preamble_add_item(
48+
_php_summary_preamble_add_item(
7149
"PHP API version"
7250
"${PHP_API_VERSION}"
7351
preamble
@@ -77,17 +55,17 @@ function(php_feature_summary_preamble result)
7755
get_target_property(zendVersion Zend::Zend VERSION)
7856
get_target_property(zendExtensionApi Zend::Zend ZEND_EXTENSION_API_NO)
7957
get_target_property(zendModuleApi Zend::Zend ZEND_MODULE_API_NO)
80-
php_feature_summary_preamble_add_item(
58+
_php_summary_preamble_add_item(
8159
"Zend Engine version"
8260
"${zendVersion}"
8361
preamble
8462
)
85-
php_feature_summary_preamble_add_item(
63+
_php_summary_preamble_add_item(
8664
"Zend extension API number"
8765
"${zendExtensionApi}"
8866
preamble
8967
)
90-
php_feature_summary_preamble_add_item(
68+
_php_summary_preamble_add_item(
9169
"Zend module API number"
9270
"${zendModuleApi}"
9371
preamble
@@ -117,7 +95,7 @@ function(php_feature_summary_preamble result)
11795
else()
11896
string(APPEND compiler "${CMAKE_${language}_COMPILER}")
11997
endif()
120-
php_feature_summary_preamble_add_item(
98+
_php_summary_preamble_add_item(
12199
"${languageLabel} compiler"
122100
"${compiler}"
123101
preamble
@@ -139,45 +117,45 @@ function(php_feature_summary_preamble result)
139117
else()
140118
string(APPEND linker "${CMAKE_${language}_COMPILER_LINKER}")
141119
endif()
142-
php_feature_summary_preamble_add_item(
120+
_php_summary_preamble_add_item(
143121
"${languageLabel} linker"
144122
"${linker}"
145123
preamble
146124
)
147125
endif()
148126
endforeach()
149127

150-
php_feature_summary_preamble_add_item(
128+
_php_summary_preamble_add_item(
151129
"Building on (host system)"
152130
"${CMAKE_HOST_SYSTEM}"
153131
preamble
154132
)
155133

156-
php_feature_summary_preamble_add_item(
134+
_php_summary_preamble_add_item(
157135
"Host CPU"
158136
"${CMAKE_HOST_SYSTEM_PROCESSOR}"
159137
preamble
160138
)
161139

162-
php_feature_summary_preamble_add_item(
140+
_php_summary_preamble_add_item(
163141
"Building for (target system)"
164142
"${CMAKE_SYSTEM}"
165143
preamble
166144
)
167145

168-
php_feature_summary_preamble_add_item(
146+
_php_summary_preamble_add_item(
169147
"Target CPU"
170148
"${CMAKE_SYSTEM_PROCESSOR}"
171149
preamble
172150
)
173151

174-
php_feature_summary_preamble_add_item(
152+
_php_summary_preamble_add_item(
175153
"CMake version"
176154
"${CMAKE_VERSION}"
177155
preamble
178156
)
179157

180-
php_feature_summary_preamble_add_item(
158+
_php_summary_preamble_add_item(
181159
"CMake generator"
182160
"${CMAKE_GENERATOR}"
183161
preamble
@@ -192,15 +170,15 @@ function(php_feature_summary_preamble result)
192170
set(buildType "N/A")
193171
endif()
194172

195-
php_feature_summary_preamble_add_item("Build type" "${buildType}" preamble)
196-
php_feature_summary_preamble_add_item("Install prefix" "${CMAKE_INSTALL_PREFIX}" preamble)
173+
_php_summary_preamble_add_item("Build type" "${buildType}" preamble)
174+
_php_summary_preamble_add_item("Install prefix" "${CMAKE_INSTALL_PREFIX}" preamble)
197175

198176
set(${result} "${preamble}" PARENT_SCOPE)
199177
endfunction()
200178

201179
# Output configuration summary.
202-
function(php_feature_summary)
203-
php_feature_summary_preamble(preamble)
180+
function(_php_summary_print)
181+
_php_summary_preamble(preamble)
204182

205183
message(STATUS "")
206184
message(STATUS "")
@@ -374,3 +352,5 @@ function(php_feature_summary)
374352
DESCRIPTION "The following REQUIRED packages have not been found:\n"
375353
)
376354
endfunction()
355+
356+
_php_summary_print()

0 commit comments

Comments
 (0)