@@ -179,7 +179,7 @@ target_sources(
179179 $<TARGET_OBJECTS:php_main>
180180
181181 # Internal functions objects based on the SAPI type.
182- $<IF:$<BOOL :$<TARGET_PROPERTY:PHP_SAPI_CLI >>,$<TARGET_OBJECTS:php_main_internal_functions_cli>,$<TARGET_OBJECTS:php_main_internal_functions>>
182+ $<IF:$<BOOL :$<TARGET_PROPERTY:PHP_CLI >>,$<TARGET_OBJECTS:php_main_internal_functions_cli>,$<TARGET_OBJECTS:php_main_internal_functions>>
183183
184184 # If Zend is OBJECT library, add library objects as sources.
185185 $<$<STREQUAL :$<TARGET_PROPERTY:Zend::Zend,TYPE >,OBJECT_LIBRARY>:$<TARGET_OBJECTS:Zend::Zend>>
@@ -191,7 +191,7 @@ target_sources(
191191 $<$<TARGET_EXISTS:PHP::windows>:$<TARGET_OBJECTS:PHP::windows>>
192192
193193 # ext/standard functions objects based on the SAPI type.
194- $<IF:$<BOOL :$<TARGET_PROPERTY:PHP_SAPI_CLI >>,$<TARGET_OBJECTS:php_standard_functions_cli>,$<TARGET_OBJECTS:php_standard_functions>>
194+ $<IF:$<BOOL :$<TARGET_PROPERTY:PHP_CLI >>,$<TARGET_OBJECTS:php_standard_functions_cli>,$<TARGET_OBJECTS:php_standard_functions>>
195195)
196196
197197################################################################################
@@ -272,16 +272,16 @@ if(PHP_DMALLOC)
272272endif ()
273273
274274################################################################################
275- # Generate files and install headers.
275+ # Create main/internal_functions*.c files with a list of static enabled PHP
276+ # extensions based on the PHP SAPI type.
276277################################################################################
277278
278- # Create main/internal_functions*.c files based on the enabled extensions.
279- function (_php_main_create_internal_functions )
280- # Create main/internal_functions* files.
281- set (EXT_INCLUDE_CODE "" )
282- set (EXT_MODULE_PTRS "" )
279+ block()
280+ set (includes "" )
281+ set (includesCli "" )
282+ set (pointers "" )
283+ set (pointersCli "" )
283284
284- # Add artifacts of static enabled PHP extensions to symbol definitions.
285285 get_property (extensions GLOBAL PROPERTY PHP_EXTENSIONS)
286286 foreach (extension IN LISTS extensions)
287287 # Skip if extension is shared.
@@ -290,6 +290,8 @@ function(_php_main_create_internal_functions)
290290 continue ()
291291 endif ()
292292
293+ get_target_property (isCli php_${extension} PHP_CLI)
294+
293295 file (GLOB_RECURSE headers ${PHP_SOURCE_DIR} /ext /${extension} /*.h)
294296
295297 foreach (header IN LISTS headers)
@@ -298,29 +300,46 @@ function(_php_main_create_internal_functions)
298300
299301 if (NOT index EQUAL -1)
300302 cmake_path(GET header FILENAME filename)
301- string (
302- APPEND
303- EXT_INCLUDE_CODE
304- "#include \" ext/ ${extension} / ${filename} \"\n "
305- )
303+ set (code "#include \" ext/ ${extension} / ${filename} \"\n " )
304+ string ( APPEND includesCli " ${code} " )
305+ if ( NOT isCli)
306+ string ( APPEND includes " ${code} " )
307+ endif ( )
306308 endif ()
307309 endforeach ()
308310
309- set (EXT_MODULE_PTRS "${EXT_MODULE_PTRS} \n\t phpext_${extension} _ptr," )
311+ set (code "\n\t phpext_${extension} _ptr," )
312+ set (pointersCli "${pointersCli}${code} " )
313+ if (NOT isCli)
314+ set (pointers "${pointers}${code} " )
315+ endif ()
310316 endforeach ()
311317
312- message (STATUS "Creating main/internal_functions.c" )
313- configure_file (main/internal_functions.c.in main/internal_functions.c)
318+ cmake_path(
319+ RELATIVE_PATH
320+ CMAKE_CURRENT_BINARY_DIR
321+ BASE_DIRECTORY ${CMAKE_BINARY_DIR}
322+ OUTPUT_VARIABLE relativeDir
323+ )
324+
325+ set (EXT_INCLUDE_CODE "${includes} " )
326+ set (EXT_MODULE_PTRS "${pointers} " )
327+ message (STATUS "Creating ${relativeDir} /internal_functions.c" )
328+ configure_file (internal_functions.c.in internal_functions.c)
314329
315- message (STATUS "Creating main/internal_functions_cli.c" )
316- configure_file (main/internal_functions.c.in main/internal_functions_cli.c)
317- endfunction ()
330+ set (EXT_INCLUDE_CODE "${includesCli} " )
331+ set (EXT_MODULE_PTRS "${pointersCli} " )
332+ message (STATUS "Creating ${relativeDir} /internal_functions_cli.c" )
333+ configure_file (internal_functions.c.in internal_functions_cli.c)
334+ endblock()
335+
336+ ################################################################################
337+ # Generate configuration headers.
338+ ################################################################################
318339
319340# Run at the end of the configuration.
320341cmake_language(DEFER DIRECTORY ${PHP_SOURCE_DIR} CALL _php_main_create_files)
321342function (_php_main_create_files)
322- _php_main_create_internal_functions()
323-
324343 ##############################################################################
325344 # Map CMake variable names to names in PHP configuration headers where needed.
326345 ##############################################################################
@@ -512,6 +531,10 @@ function(_php_main_create_files)
512531 )
513532endfunction ()
514533
534+ ################################################################################
535+ # Configure installation.
536+ ################################################################################
537+
515538install (
516539 TARGETS php_main
517540 ARCHIVE EXCLUDE_FROM_ALL
0 commit comments