11#[=============================================================================[
22PHP 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
105include (FeatureSummary)
@@ -14,10 +9,7 @@ include(FeatureSummary)
149################################################################################
1510
1611add_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
2214target_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-
150116target_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+
299270block()
300271 set (includes "" )
301272 set (includesCli "" )
0 commit comments