@@ -9,20 +9,16 @@ PHP main binding.
99
1010include (FeatureSummary)
1111
12- add_library (php INTERFACE )
13- add_library (PHP::PHP ALIAS php)
12+ ################################################################################
13+ # Add library.
14+ ################################################################################
1415
1516add_library (php_main OBJECT)
16- add_library (PHP::main ALIAS php_main)
1717
1818# These contain a list of built-in extensions based on the SAPI types.
1919add_library (php_main_internal_functions OBJECT internal_functions.c)
2020add_library (php_main_internal_functions_cli OBJECT internal_functions_cli.c)
2121
22- # Configuration library to transitively pass build options to php_main* targets.
23- add_library (php_main_configuration INTERFACE )
24- add_library (PHP::mainConfiguration ALIAS php_main_configuration)
25-
2622target_sources (
2723 php_main
2824 PRIVATE
@@ -113,51 +109,83 @@ target_sources(
113109)
114110
115111target_compile_definitions (
116- php_main_configuration
117- INTERFACE
118- ZEND_ENABLE_STATIC_TSRMLS_CACHE=1
112+ php_main
113+ PUBLIC
119114 $<$<PLATFORM_ID:Windows>:SAPI_EXPORTS>
120115)
121116
122- target_link_libraries (
123- php_main_configuration
124- INTERFACE
125- PHP::configuration
126- $<$<TARGET_EXISTS:PHP::win32 >:PHP::win32 $<TARGET_OBJECTS:PHP::win32 >>
127- )
128-
129- target_link_libraries (php_main PRIVATE PHP::mainConfiguration)
130- target_link_libraries (php_main_internal_functions PRIVATE PHP::mainConfiguration)
131- target_link_libraries (php_main_internal_functions_cli PRIVATE PHP::mainConfiguration)
132-
133117target_include_directories (
134118 php_main
135119 INTERFACE
136120 ${CMAKE_CURRENT_BINARY_DIR}
137121 ${CMAKE_CURRENT_SOURCE_DIR}
138122)
139123
140- # Add main PUBLIC/INTERFACE include directories to configuration.
141- target_include_directories (
142- php_configuration
143- INTERFACE
144- $<TARGET_PROPERTY:PHP::main,INTERFACE_INCLUDE_DIRECTORIES >
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=1
145131)
146132
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+
150+ 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 )
153+
154+ ################################################################################
155+ # Add PHP::PHP.
156+ ################################################################################
157+
158+ add_library (php INTERFACE )
159+ add_library (PHP::PHP ALIAS php)
160+
147161target_link_libraries (
148162 php
149163 INTERFACE
150164 PHP::configuration
151- PHP::main
152- $<TARGET_OBJECTS:PHP::main>
153- # Pass transitively depending on the SAPI type.
154- $<IF:$<IN_LIST :$<TARGET_PROPERTY:NAME >,php_cgi;php_cli;php_embed;php_phpdbg>,php_main_internal_functions_cli $<TARGET_OBJECTS:php_main_internal_functions_cli>,php_main_internal_functions $<TARGET_OBJECTS:php_main_internal_functions>>
165+ php_main
155166 Zend::Zend
156- $<TARGET_OBJECTS:Zend::Zend >
167+ $<$<TARGET_EXISTS:PHP::windows>::PHP::windows >
157168 PHP::extensions
158169)
159170
171+ # OBJECT libraries propagate only compile properties to static libraries without
172+ # objects as there is no "linking" involved on the compiler level. This is a
173+ # workaround using interface target sources to make PHP::PHP more intuitive to
174+ # work with SAPIs.
175+ target_sources (
176+ php
177+ INTERFACE
178+ $<TARGET_OBJECTS:php_main>
179+ # Internal functions objects based on the SAPI type.
180+ $<IF:$<BOOL :$<TARGET_PROPERTY:PHP_SAPI_CLI>>,$<TARGET_OBJECTS:php_main_internal_functions_cli>,$<TARGET_OBJECTS:php_main_internal_functions>>
181+ $<TARGET_OBJECTS:Zend::Zend>
182+ $<$<TARGET_EXISTS:PHP::windows>:$<TARGET_OBJECTS:PHP::windows>>
183+ )
184+
185+ ################################################################################
160186# Add DTrace.
187+ ################################################################################
188+
161189if (PHP_DTRACE)
162190 message (CHECK_START "Checking for DTrace support" )
163191
@@ -196,7 +224,10 @@ add_feature_info(
196224 "performance analysis and troubleshooting"
197225)
198226
227+ ################################################################################
199228# Add Dmalloc.
229+ ################################################################################
230+
200231if (PHP_DMALLOC)
201232 message (CHECK_START "Checking for Dmalloc support" )
202233
@@ -211,7 +242,7 @@ if(PHP_DMALLOC)
211242 target_compile_definitions (
212243 php_configuration
213244 INTERFACE
214- $<$<COMPILE_LANGUAGE:ASM,C,CXX>:MALLOC_FUNC_CHECK >
245+ $<$<COMPILE_LANGUAGE:ASM,C,CXX>:DMALLOC_FUNC_CHECK >
215246 )
216247
217248 target_link_libraries (php_main PRIVATE Dmalloc::Dmalloc)
0 commit comments