Skip to content

Commit 0fbbe8d

Browse files
committed
Add new global target php_sapis_config
This collects all usage requirements for PHP SAPIs.
1 parent 8ec2c72 commit 0fbbe8d

File tree

7 files changed

+76
-107
lines changed

7 files changed

+76
-107
lines changed

cmake/Zend/CMakeLists.txt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,23 +318,29 @@ set_target_properties(
318318
ZEND_MODULE_API_NO ${Zend_VERSION_MODULE_API_NO}
319319
)
320320

321-
# Add Zend PUBLIC/INTERFACE compile properties to configuration.
321+
################################################################################
322+
# Pass transitive compile and link properties to PHP configuration interface.
323+
################################################################################
324+
322325
# Cleaner COMPILE_ONLY generator expression is available in CMake >= 3.27.
323326
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.27)
324-
target_link_libraries(php_configuration INTERFACE $<COMPILE_ONLY:zend>)
327+
target_link_libraries(php_configuration INTERFACE $<COMPILE_ONLY:Zend::Zend>)
325328
else()
326329
target_include_directories(
327330
php_configuration
328331
INTERFACE
329-
$<TARGET_PROPERTY:zend,INTERFACE_INCLUDE_DIRECTORIES>
332+
$<TARGET_PROPERTY:Zend::Zend,INTERFACE_INCLUDE_DIRECTORIES>
330333
)
331334
target_compile_definitions(
332335
php_configuration
333336
INTERFACE
334-
$<TARGET_PROPERTY:zend,INTERFACE_COMPILE_DEFINITIONS>
337+
$<TARGET_PROPERTY:Zend::Zend,INTERFACE_COMPILE_DEFINITIONS>
335338
)
336339
endif()
337340

341+
target_link_libraries(php_sapis_config INTERFACE Zend::Zend)
342+
target_sources(php_sapis_config INTERFACE $<TARGET_OBJECTS:Zend::Zend>)
343+
338344
################################################################################
339345
# TSRM (Thread Safe Resource Manager) is a separate directory in php-src as it
340346
# was once a standalone project. Ideally, it should be moved into Zend Engine at

cmake/cmake/Bootstrap.cmake

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ include(PHP/InterproceduralOptimization)
3333
# Set CMAKE_POSITION_INDEPENDENT_CODE.
3434
include(PHP/PositionIndependentCode)
3535

36-
# Create a project wide INTERFACE library with project configuration.
36+
# INTERFACE library with usage requirements. All targets that need PHP compile
37+
# or link properties, such as include directories, global compile definitions,
38+
# or flags, should link to this target.
3739
add_library(php_configuration INTERFACE)
3840
add_library(PHP::configuration ALIAS php_configuration)
3941
target_include_directories(
@@ -43,6 +45,12 @@ target_include_directories(
4345
${PHP_SOURCE_DIR}
4446
)
4547

48+
# INTERFACE library that ties all target objects and configuration together.
49+
# Only PHP SAPI targets should link to it.
50+
add_library(php_sapis_config INTERFACE)
51+
add_library(PHP::PHP ALIAS php_sapis_config)
52+
target_link_libraries(php_sapis_config INTERFACE PHP::configuration)
53+
4654
# Create a custom target for generating files (parsers, lexers, etc.) manually:
4755
# cmake --build <dir> -t php_generate_files
4856
add_custom_target(php_generate_files)

cmake/cmake/modules/PHP/Extensions.cmake

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -396,13 +396,17 @@ function(php_extensions_postconfigure extension)
396396
"'ON'."
397397
)
398398

399-
set(
400-
EXT_${dependencyUpper}
401-
ON
402-
CACHE BOOL
403-
"Enable the ${dependency} extension"
404-
FORCE
405-
)
399+
if(DEFINED CACHE{EXT_${dependencyUpper}})
400+
set_property(CACHE EXT_${dependencyUpper} PROPERTY VALUE ON)
401+
else()
402+
set(
403+
EXT_${dependencyUpper}
404+
ON
405+
CACHE BOOL
406+
"Enable the ${dependency} extension"
407+
FORCE
408+
)
409+
endif()
406410
endforeach()
407411

408412
if(NOT TARGET PHP::${extension})

cmake/ext/CMakeLists.txt

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
#[=============================================================================[
22
Add subdirectories of PHP extensions.
3-
4-
## INTERFACE target
5-
6-
* `php_extensions` (alias `PHP::extensions`) is an INTERFACE library with all
7-
enabled extensions linked into for convenience.
83
#]=============================================================================]
94

105
include(PHP/Extensions)
@@ -57,9 +52,6 @@ set_property(GLOBAL PROPERTY PHP_ALL_EXTENSIONS ${extensions})
5752
# Sort and preconfigure extensions by their dependencies.
5853
php_extensions_preprocess(extensions)
5954

60-
add_library(php_extensions INTERFACE)
61-
add_library(PHP::extensions ALIAS php_extensions)
62-
6355
# Add subdirectories of extensions.
6456
foreach(extension IN LISTS extensions)
6557
list(APPEND CMAKE_MESSAGE_CONTEXT "${extension}")
@@ -80,8 +72,7 @@ foreach(extension IN LISTS extensions)
8072

8173
add_dependencies(php_${extension} Zend::Zend)
8274

83-
# Add extension's transitive compile and link properties to configuration.
84-
# The INTERFACE_SOURCES are propagated separately only to PHP::PHP.
75+
# Pass transitive compile and link properties to PHP configuration interface.
8576
# See: https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html
8677
# TODO: Should PHP_CLI extensions pass properties only to PHP_CLI SAPIs?
8778
get_target_property(type php_${extension} TYPE)
@@ -112,17 +103,15 @@ foreach(extension IN LISTS extensions)
112103
)
113104

114105
target_link_libraries(
115-
php_extensions
106+
php_sapis_config
116107
INTERFACE
117-
$<IF:$<BOOL:$<TARGET_GENEX_EVAL:PHP::${extension},$<TARGET_PROPERTY:PHP::${extension},PHP_CLI>>>,$<$<BOOL:$<TARGET_PROPERTY:PHP_CLI>>:$<LINK_ONLY:PHP::${extension}>>,$<LINK_ONLY:PHP::${extension}>>
108+
$<IF:$<BOOL:$<TARGET_GENEX_EVAL:PHP::${extension},$<TARGET_PROPERTY:PHP::${extension},PHP_CLI>>>,$<$<BOOL:$<TARGET_PROPERTY:PHP_CLI>>:PHP::${extension}>,PHP::${extension}>
118109
)
119110

120111
target_sources(
121-
php_extensions
112+
php_sapis_config
122113
INTERFACE
123114
$<IF:$<BOOL:$<TARGET_GENEX_EVAL:PHP::${extension},$<TARGET_PROPERTY:PHP::${extension},PHP_CLI>>>,$<$<BOOL:$<TARGET_PROPERTY:PHP_CLI>>:$<TARGET_OBJECTS:PHP::${extension}>>,$<TARGET_OBJECTS:PHP::${extension}>>
124-
125-
$<IF:$<BOOL:$<TARGET_GENEX_EVAL:PHP::${extension},$<TARGET_PROPERTY:PHP::${extension},PHP_CLI>>>,$<$<BOOL:$<TARGET_PROPERTY:PHP_CLI>>:$<TARGET_PROPERTY:PHP::${extension},INTERFACE_SOURCES>>,$<TARGET_PROPERTY:PHP::${extension},INTERFACE_SOURCES>>
126115
)
127116
endif()
128117

cmake/main/CMakeLists.txt

Lines changed: 39 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
#[=============================================================================[
22
PHP main binding.
3-
4-
## INTERFACE target
5-
6-
* `php` (alias `PHP::PHP`) is an INTERFACE library that ties PHP core, Zend
7-
Engine and PHP extensions together and can be easily linked to SAPIs.
83
#]=============================================================================]
94

105
include(FeatureSummary)
@@ -14,10 +9,7 @@ include(FeatureSummary)
149
################################################################################
1510

1611
add_library(php_main OBJECT)
17-
18-
# These contain a list of built-in extensions based on the SAPI types.
19-
add_library(php_main_internal_functions OBJECT internal_functions.c)
20-
add_library(php_main_internal_functions_cli OBJECT internal_functions_cli.c)
12+
add_library(PHP::main ALIAS php_main)
2113

2214
target_sources(
2315
php_main
@@ -121,76 +113,43 @@ target_include_directories(
121113
${CMAKE_CURRENT_SOURCE_DIR}
122114
)
123115

124-
set_property(
125-
TARGET
126-
php_main
127-
php_main_internal_functions
128-
php_main_internal_functions_cli
129-
APPEND
130-
PROPERTY COMPILE_DEFINITIONS ZEND_ENABLE_STATIC_TSRMLS_CACHE
131-
)
132-
133-
# Add main PUBLIC/INTERFACE compile properties to configuration.
134-
# Cleaner COMPILE_ONLY generator expression is available in CMake >= 3.27.
135-
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.27)
136-
target_link_libraries(php_configuration INTERFACE $<COMPILE_ONLY:php_main>)
137-
else()
138-
target_include_directories(
139-
php_configuration
140-
INTERFACE
141-
$<TARGET_PROPERTY:php_main,INTERFACE_INCLUDE_DIRECTORIES>
142-
)
143-
target_compile_definitions(
144-
php_configuration
145-
INTERFACE
146-
$<TARGET_PROPERTY:php_main,INTERFACE_COMPILE_DEFINITIONS>
147-
)
148-
endif()
149-
150116
target_link_libraries(php_main PRIVATE PHP::configuration)
151-
target_link_libraries(php_main_internal_functions PRIVATE PHP::configuration)
152-
target_link_libraries(php_main_internal_functions_cli PRIVATE PHP::configuration)
117+
118+
# Compile and link properties for all targets in this directory scope.
119+
add_compile_definitions(ZEND_ENABLE_STATIC_TSRMLS_CACHE)
153120

154121
################################################################################
155-
# Add PHP::PHP.
122+
# Add transitive compile and link properties to PHP interface targets.
156123
################################################################################
157124

158-
add_library(php INTERFACE)
159-
add_library(PHP::PHP ALIAS php)
160-
161-
target_link_libraries(
162-
php
125+
target_compile_definitions(
126+
php_configuration
163127
INTERFACE
164-
PHP::configuration
165-
php_main
166-
# If Zend is STATIC library link as whole archive, otherwise link normally.
167-
$<IF:$<STREQUAL:$<TARGET_PROPERTY:Zend::Zend,TYPE>,STATIC_LIBRARY>,$<LINK_LIBRARY:WHOLE_ARCHIVE,Zend::Zend>,Zend::Zend>
168-
$<$<TARGET_EXISTS:PHP::windows>:PHP::windows>
169-
PHP::extensions
128+
$<TARGET_PROPERTY:PHP::main,INTERFACE_COMPILE_DEFINITIONS>
170129
)
171130

172-
# OBJECT libraries propagate only compile properties to static libraries without
173-
# objects as there is no "linking" involved on the compiler level. This is a
174-
# workaround using interface target sources to make PHP::PHP more intuitive to
175-
# work with SAPIs.
176-
target_sources(
177-
php
131+
target_compile_options(
132+
php_configuration
178133
INTERFACE
179-
$<TARGET_OBJECTS:php_main>
180-
181-
# Internal functions objects based on the SAPI type.
182-
$<IF:$<BOOL:$<TARGET_PROPERTY:PHP_CLI>>,$<TARGET_OBJECTS:php_main_internal_functions_cli>,$<TARGET_OBJECTS:php_main_internal_functions>>
183-
184-
# If Zend is OBJECT library, add library objects as sources.
185-
$<$<STREQUAL:$<TARGET_PROPERTY:Zend::Zend,TYPE>,OBJECT_LIBRARY>:$<TARGET_OBJECTS:Zend::Zend>>
134+
$<TARGET_PROPERTY:PHP::main,INTERFACE_COMPILE_OPTIONS>
135+
)
186136

187-
# If Zend is STATIC library, and linking to a STATIC library (SAPI), add
188-
# library objects as sources.
189-
$<$<AND:$<STREQUAL:$<TARGET_PROPERTY:TYPE>,STATIC_LIBRARY>,$<STREQUAL:$<TARGET_PROPERTY:Zend::Zend,TYPE>,STATIC_LIBRARY>>:$<TARGET_OBJECTS:Zend::Zend>>
137+
target_compile_features(
138+
php_configuration
139+
INTERFACE
140+
$<TARGET_PROPERTY:PHP::main,INTERFACE_COMPILE_FEATURES>
141+
)
190142

191-
$<$<TARGET_EXISTS:PHP::windows>:$<TARGET_OBJECTS:PHP::windows>>
143+
target_include_directories(
144+
php_configuration
145+
INTERFACE
146+
$<TARGET_PROPERTY:PHP::main,INTERFACE_INCLUDE_DIRECTORIES>
147+
$<TARGET_PROPERTY:PHP::main,INTERFACE_SYSTEM_INCLUDE_DIRECTORIES>
192148
)
193149

150+
target_link_libraries(php_sapis_config INTERFACE PHP::main)
151+
target_sources(php_sapis_config INTERFACE $<TARGET_OBJECTS:PHP::main>)
152+
194153
################################################################################
195154
# Add DTrace.
196155
################################################################################
@@ -221,8 +180,8 @@ if(PHP_DTRACE)
221180
INCLUDES
222181
$<TARGET_PROPERTY:PHP::configuration,INTERFACE_INCLUDE_DIRECTORIES>
223182
)
224-
target_link_libraries(php_main PRIVATE DTrace::DTrace)
225-
target_link_libraries(php INTERFACE php_dtrace)
183+
target_link_libraries(php_main PUBLIC DTrace::DTrace)
184+
target_link_libraries(php_main INTERFACE php_dtrace)
226185

227186
set(HAVE_DTRACE TRUE PARENT_SCOPE)
228187

@@ -296,6 +255,18 @@ file(CONFIGURE OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/php_version.h CONTENT [[
296255
# extensions based on the PHP SAPI type.
297256
################################################################################
298257

258+
add_library(php_main_internal_functions OBJECT internal_functions.c)
259+
add_library(php_main_internal_functions_cli OBJECT internal_functions_cli.c)
260+
261+
target_sources(
262+
php_sapis_config
263+
INTERFACE
264+
$<IF:$<BOOL:$<TARGET_PROPERTY:PHP_CLI>>,$<TARGET_OBJECTS:php_main_internal_functions_cli>,$<TARGET_OBJECTS:php_main_internal_functions>>
265+
)
266+
267+
target_link_libraries(php_main_internal_functions PRIVATE PHP::configuration)
268+
target_link_libraries(php_main_internal_functions_cli PRIVATE PHP::configuration)
269+
299270
block()
300271
set(includes "")
301272
set(includesCli "")

cmake/sapi/phpdbg/CMakeLists.txt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -228,22 +228,10 @@ if(SAPI_PHPDBG_SHARED)
228228
php_phpdbg_shared
229229
PRIVATE
230230
ZEND_ENABLE_STATIC_TSRMLS_CACHE
231-
$<TARGET_PROPERTY:PHP::main,INTERFACE_COMPILE_DEFINITIONS>
232231
$<$<PLATFORM_ID:Windows>:YY_NO_UNISTD_H>
233232
$<IF:$<BOOL:${SAPI_PHPDBG_DEBUG}>,PHPDBG_DEBUG=1,PHPDBG_DEBUG=0>
234233
)
235234

236-
target_include_directories(
237-
php_phpdbg_shared
238-
PRIVATE
239-
$<TARGET_PROPERTY:PHP::main,INTERFACE_INCLUDE_DIRECTORIES>
240-
)
241-
242-
target_compile_options(
243-
php_phpdbg_shared
244-
PRIVATE $<TARGET_PROPERTY:PHP::main,INTERFACE_COMPILE_OPTIONS>
245-
)
246-
247235
target_link_libraries(
248236
php_phpdbg_shared
249237
PRIVATE

cmake/win32/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ target_link_libraries(
105105
ws2_32
106106
)
107107

108+
target_link_libraries(php_sapis_config INTERFACE PHP::windows)
109+
target_sources(php_sapis_config INTERFACE $<TARGET_OBJECTS:PHP::windows>)
110+
108111
################################################################################
109112
# Generate wsyslog.h file with message compiler (mc).
110113
################################################################################

0 commit comments

Comments
 (0)