From 53a81e3cbfd405beec2ea6661cdd195e27a7fc2d Mon Sep 17 00:00:00 2001 From: Peter Kokot Date: Thu, 21 Nov 2024 01:06:57 +0100 Subject: [PATCH 1/5] Fix OBJECT libraries usage These fixes make using OBJECT libraries simpler and more intuitive according to the CMake recommendations at this state of the build system. Fixes: - A workaround a CMake bug/missing feature where ALIAS targets don't properly propagate when referring to INTERFACE libraries with `add_dependencies()`. - All current OBJECT libraries improved and wrapped into interface libraries. - Windows OBJECT library improved according to current build system level. - FindRE2C improved with VERBATIM and COMMAND_EXPAND_LISTS to hopefully make it behave the same across platforms. --- cmake/TSRM/CMakeLists.txt | 25 +++++++------- cmake/Zend/CMakeLists.txt | 13 +++++-- cmake/cmake/modules/FindRE2C.cmake | 2 ++ cmake/ext/CMakeLists.txt | 2 +- cmake/main/CMakeLists.txt | 44 ++++++++++++++++++++---- cmake/win32/CMakeLists.txt | 55 ++++++++++++++++++++++-------- 6 files changed, 105 insertions(+), 36 deletions(-) diff --git a/cmake/TSRM/CMakeLists.txt b/cmake/TSRM/CMakeLists.txt index 2044b7920..d166685c8 100644 --- a/cmake/TSRM/CMakeLists.txt +++ b/cmake/TSRM/CMakeLists.txt @@ -2,23 +2,22 @@ TSRM (Thread Safe Resource Manager) is a separate directory in php-src as it was once a standalone project. Ideally, it should be integrated into Zend Engine. -The TSRM::TSRM target is used to transitively pass the TSRM object(s) and +The `TSRM::TSRM` target is used to transitively pass the TSRM object(s) and compile options to Zend Engine, which propagates it further as needed. #]=============================================================================] -add_library(tsrm_object OBJECT) -add_library(tsrm INTERFACE) -add_library(TSRM::TSRM ALIAS tsrm) - +add_library(tsrm OBJECT) +add_library(tsrm_interface INTERFACE) +add_library(TSRM::TSRM ALIAS tsrm_interface) target_link_libraries( - tsrm + tsrm_interface INTERFACE - tsrm_object - $ + tsrm + $ ) target_sources( - tsrm_object + tsrm PRIVATE $<$:tsrm_win32.c> TSRM.c @@ -29,17 +28,17 @@ target_sources( TSRM.h ) -target_link_libraries(tsrm_object PRIVATE PHP::configuration) +target_link_libraries(tsrm PRIVATE PHP::configuration) target_include_directories( - tsrm_object + tsrm INTERFACE $ $ ) target_compile_definitions( - tsrm_object + tsrm PRIVATE ZEND_ENABLE_STATIC_TSRMLS_CACHE=1 PUBLIC @@ -47,7 +46,7 @@ target_compile_definitions( ) install( - TARGETS tsrm_object + TARGETS tsrm FILE_SET HEADERS DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PHP_INCLUDE_PREFIX}/TSRM ) diff --git a/cmake/Zend/CMakeLists.txt b/cmake/Zend/CMakeLists.txt index 9b7b715e2..8cf3329af 100644 --- a/cmake/Zend/CMakeLists.txt +++ b/cmake/Zend/CMakeLists.txt @@ -1,7 +1,7 @@ #[=============================================================================[ Zend Engine. -CMake target properties for the `Zend::Zend` (`zend`) target: +CMake target properties for the `Zend::Zend` target: * `VERSION` @@ -88,7 +88,16 @@ mark_as_advanced(ZEND_SIGNALS) ################################################################################ add_library(zend OBJECT) -add_library(Zend::Zend ALIAS zend) +add_library(zend_interface INTERFACE) +add_library(Zend::Zend ALIAS zend_interface) +target_link_libraries( + zend_interface + INTERFACE + zend + $ +) +# https://gitlab.kitware.com/cmake/cmake/-/issues/23402 workaround: +add_dependencies(zend_interface zend) target_sources( zend diff --git a/cmake/cmake/modules/FindRE2C.cmake b/cmake/cmake/modules/FindRE2C.cmake index 357923e78..4e21b8a6c 100644 --- a/cmake/cmake/modules/FindRE2C.cmake +++ b/cmake/cmake/modules/FindRE2C.cmake @@ -286,6 +286,8 @@ function(re2c_target) ${input} DEPENDS ${input} ${parsed_DEPENDS} COMMENT "[RE2C][${ARGV0}] Building lexer with re2c ${RE2C_VERSION}" + VERBATIM + COMMAND_EXPAND_LISTS ) add_custom_target( diff --git a/cmake/ext/CMakeLists.txt b/cmake/ext/CMakeLists.txt index 080f2b575..39bd740f7 100644 --- a/cmake/ext/CMakeLists.txt +++ b/cmake/ext/CMakeLists.txt @@ -114,7 +114,7 @@ foreach(extension IN LISTS extensions) $ ) - add_dependencies(php_${extension} zend) + add_dependencies(php_${extension} Zend::Zend) get_target_property(type php_${extension} TYPE) if(NOT type MATCHES "^(MODULE|SHARED)_LIBRARY$") diff --git a/cmake/main/CMakeLists.txt b/cmake/main/CMakeLists.txt index fb42b11f9..7a381a91c 100644 --- a/cmake/main/CMakeLists.txt +++ b/cmake/main/CMakeLists.txt @@ -9,15 +9,43 @@ PHP main binding. include(FeatureSummary) +################################################################################ +# Add library. +################################################################################ + add_library(php INTERFACE) add_library(PHP::PHP ALIAS php) add_library(php_main OBJECT) -add_library(PHP::main ALIAS php_main) +add_library(php_main_interface INTERFACE) +add_library(PHP::main ALIAS php_main_interface) +target_link_libraries( + php_main_interface + INTERFACE + php_main + $ +) # These contain a list of built-in extensions based on the SAPI types. add_library(php_main_internal_functions OBJECT internal_functions.c) +add_library(php_main_internal_functions_interface INTERFACE) +add_library(PHP::mainInternalFunctions ALIAS php_main_internal_functions_interface) +target_link_libraries( + php_main_internal_functions_interface + INTERFACE + php_main_internal_functions + $ +) + add_library(php_main_internal_functions_cli OBJECT internal_functions_cli.c) +add_library(php_main_internal_functions_cli_interface INTERFACE) +add_library(PHP::mainInternalFunctionsCli ALIAS php_main_internal_functions_cli_interface) +target_link_libraries( + php_main_internal_functions_cli_interface + INTERFACE + php_main_internal_functions_cli + $ +) # Configuration library to transitively pass build options to php_main* targets. add_library(php_main_configuration INTERFACE) @@ -123,7 +151,6 @@ target_link_libraries( php_main_configuration INTERFACE PHP::configuration - $<$:PHP::win32 $> ) target_link_libraries(php_main PRIVATE PHP::mainConfiguration) @@ -149,15 +176,17 @@ target_link_libraries( INTERFACE PHP::configuration PHP::main - $ - # Pass transitively depending on the SAPI type. - $,php_cgi;php_cli;php_embed;php_phpdbg>,php_main_internal_functions_cli $,php_main_internal_functions $> + # Pass internal functions objects transitively depending on the SAPI type. + $,php_cgi;php_cli;php_embed;php_phpdbg>,PHP::mainInternalFunctionsCli,PHP::mainInternalFunctions> Zend::Zend - $ PHP::extensions + $<$:PHP::windows> ) +################################################################################ # Add DTrace. +################################################################################ + if(PHP_DTRACE) message(CHECK_START "Checking for DTrace support") @@ -196,7 +225,10 @@ add_feature_info( "performance analysis and troubleshooting" ) +################################################################################ # Add Dmalloc. +################################################################################ + if(PHP_DMALLOC) message(CHECK_START "Checking for Dmalloc support") diff --git a/cmake/win32/CMakeLists.txt b/cmake/win32/CMakeLists.txt index ec1189ad3..1ba7bbe08 100644 --- a/cmake/win32/CMakeLists.txt +++ b/cmake/win32/CMakeLists.txt @@ -5,11 +5,22 @@ endif() include(FeatureSummary) -add_library(php_win32 OBJECT) -add_library(PHP::win32 ALIAS php_win32) +################################################################################ +# Add library. +################################################################################ + +add_library(php_windows OBJECT) +add_library(php_windows_interface INTERFACE) +add_library(PHP::windows ALIAS php_windows_interface) +target_link_libraries( + php_windows_interface + INTERFACE + php_windows + $ +) target_sources( - php_win32 + php_windows PRIVATE codepage.c console.c @@ -85,7 +96,7 @@ target_compile_options( $<$:/wd4996> ) -target_link_libraries(php_win32 PRIVATE PHP::configuration) +target_link_libraries(php_windows PRIVATE PHP::configuration) target_link_libraries( php_configuration @@ -101,7 +112,9 @@ target_link_libraries( ws2_32 ) +################################################################################ # Generate wsyslog.h file with message compiler (mc). +################################################################################ find_package(MC) set_package_properties( MC @@ -111,27 +124,41 @@ set_package_properties( ) mc_target( - NAME php_win32_wsyslog + NAME php_windows_wsyslog INPUT build/wsyslog.mc XDBG_DIR ${CMAKE_CURRENT_BINARY_DIR} ) -add_dependencies(php_win32 php_win32_wsyslog) +add_dependencies(php_windows php_windows_wsyslog) +################################################################################ # Generate cp_enc_map.c. -add_executable(php_win32_encoding_map_generator cp_enc_map_gen.c) +################################################################################ + +add_executable(php_windows_encoding_map_generator cp_enc_map_gen.c) -add_custom_target( - php_win32_encoding_map - DEPENDS php_win32_encoding_map_generator - COMMAND php_win32_encoding_map_generator > cp_enc_map.c - COMMENT "Generating win32/cp_enc_map.c" +add_custom_command( + OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/cp_enc_map.c + COMMAND php_windows_encoding_map_generator > cp_enc_map.c + VERBATIM + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT "[win32] Generating win32/cp_enc_map.c" +) + +target_sources(php_windows PRIVATE cp_enc_map.c) + +set_source_files_properties( + ${CMAKE_CURRENT_SOURCE_DIR}/cp_enc_map.c + PROPERTIES + HEADER_FILE_ONLY ON ) -add_dependencies(php_win32 php_win32_encoding_map) +################################################################################ +# Configure installation. +################################################################################ install( - TARGETS php_win32 + TARGETS php_windows ARCHIVE EXCLUDE_FROM_ALL FILE_SET HEADERS DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PHP_INCLUDE_PREFIX}/win32 From 1605b136b2607ca513f082d6c5c66c7911a610c9 Mon Sep 17 00:00:00 2001 From: Peter Kokot Date: Thu, 21 Nov 2024 02:03:34 +0100 Subject: [PATCH 2/5] Add fixes and adjustments --- cmake/Zend/CMakeLists.txt | 7 ++++- cmake/ext/CMakeLists.txt | 6 +++- cmake/main/CMakeLists.txt | 56 ++++++++++++++++++++++---------------- cmake/win32/CMakeLists.txt | 2 +- 4 files changed, 44 insertions(+), 27 deletions(-) diff --git a/cmake/Zend/CMakeLists.txt b/cmake/Zend/CMakeLists.txt index 8cf3329af..806ab64d4 100644 --- a/cmake/Zend/CMakeLists.txt +++ b/cmake/Zend/CMakeLists.txt @@ -361,7 +361,7 @@ block() ) endblock() -# Add Zend PUBLIC/INTERFACE compile options to configuration. +# Add Zend PUBLIC/INTERFACE compile properties to configuration. # Cleaner COMPILE_ONLY generator expression is available in CMake >= 3.27. if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.27) target_link_libraries(php_configuration INTERFACE $) @@ -371,6 +371,11 @@ else() INTERFACE $ ) + target_compile_definitions( + php_configuration + INTERFACE + $ + ) endif() ################################################################################ diff --git a/cmake/ext/CMakeLists.txt b/cmake/ext/CMakeLists.txt index 39bd740f7..266b70282 100644 --- a/cmake/ext/CMakeLists.txt +++ b/cmake/ext/CMakeLists.txt @@ -89,7 +89,7 @@ foreach(extension IN LISTS extensions) if(TARGET php_${extension}) set_property(GLOBAL APPEND PROPERTY PHP_EXTENSIONS ${extension}) - # Add extension's PUBLIC/INTERFACE compile options to configuration. + # Add extension's PUBLIC/INTERFACE compile properties to configuration. # Cleaner COMPILE_ONLY generator expression is available in CMake >= 3.27. if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.27) target_link_libraries( @@ -98,6 +98,10 @@ foreach(extension IN LISTS extensions) $ ) else() + # TODO: Fix this better. Either require 3.27, or limit/adjust compile + # properties propagated globally. Also, shared extensions shouldn't + # propagate globally. + # https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#id36 target_include_directories( php_configuration INTERFACE diff --git a/cmake/main/CMakeLists.txt b/cmake/main/CMakeLists.txt index 7a381a91c..2869cb778 100644 --- a/cmake/main/CMakeLists.txt +++ b/cmake/main/CMakeLists.txt @@ -43,14 +43,10 @@ add_library(PHP::mainInternalFunctionsCli ALIAS php_main_internal_functions_cli_ target_link_libraries( php_main_internal_functions_cli_interface INTERFACE - php_main_internal_functions_cli + php_main_internal_functions_cli $ ) -# Configuration library to transitively pass build options to php_main* targets. -add_library(php_main_configuration INTERFACE) -add_library(PHP::mainConfiguration ALIAS php_main_configuration) - target_sources( php_main PRIVATE @@ -140,22 +136,24 @@ target_sources( $<$>:${CMAKE_CURRENT_BINARY_DIR}/php_config.h> ) -target_compile_definitions( - php_main_configuration - INTERFACE - ZEND_ENABLE_STATIC_TSRMLS_CACHE=1 - $<$:SAPI_EXPORTS> +set_property( + TARGET + php_main + php_main_internal_functions + php_main_internal_functions_cli + APPEND + PROPERTY COMPILE_DEFINITIONS ZEND_ENABLE_STATIC_TSRMLS_CACHE=1 ) -target_link_libraries( - php_main_configuration - INTERFACE - PHP::configuration +target_compile_definitions( + php_main + PUBLIC + $<$:SAPI_EXPORTS> ) -target_link_libraries(php_main PRIVATE PHP::mainConfiguration) -target_link_libraries(php_main_internal_functions PRIVATE PHP::mainConfiguration) -target_link_libraries(php_main_internal_functions_cli PRIVATE PHP::mainConfiguration) +target_link_libraries(php_main PRIVATE PHP::configuration) +target_link_libraries(php_main_internal_functions PRIVATE PHP::configuration) +target_link_libraries(php_main_internal_functions_cli PRIVATE PHP::configuration) target_include_directories( php_main @@ -164,12 +162,22 @@ target_include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ) -# Add main PUBLIC/INTERFACE include directories to configuration. -target_include_directories( - php_configuration - INTERFACE - $ -) +# Add main PUBLIC/INTERFACE compile properties to configuration. +# Cleaner COMPILE_ONLY generator expression is available in CMake >= 3.27. +if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.27) + target_link_libraries(php_configuration INTERFACE $) +else() + target_include_directories( + php_configuration + INTERFACE + $ + ) + target_compile_definitions( + php_configuration + INTERFACE + $ + ) +endif() target_link_libraries( php @@ -243,7 +251,7 @@ if(PHP_DMALLOC) target_compile_definitions( php_configuration INTERFACE - $<$:MALLOC_FUNC_CHECK> + $<$:DMALLOC_FUNC_CHECK> ) target_link_libraries(php_main PRIVATE Dmalloc::Dmalloc) diff --git a/cmake/win32/CMakeLists.txt b/cmake/win32/CMakeLists.txt index 1ba7bbe08..5cdba1d3d 100644 --- a/cmake/win32/CMakeLists.txt +++ b/cmake/win32/CMakeLists.txt @@ -15,7 +15,7 @@ add_library(PHP::windows ALIAS php_windows_interface) target_link_libraries( php_windows_interface INTERFACE - php_windows + php_windows $ ) From a3bb6c3941964f7175f0cb7c0278e2e2210c0fe2 Mon Sep 17 00:00:00 2001 From: Peter Kokot Date: Thu, 21 Nov 2024 18:03:18 +0100 Subject: [PATCH 3/5] Simplify OBJECT libraries This links target objects on a single place. --- cmake/Zend/CMakeLists.txt | 17 ++---- cmake/ext/pcntl/CMakeLists.txt | 2 +- cmake/ext/readline/CMakeLists.txt | 2 +- cmake/main/CMakeLists.txt | 88 ++++++++++++++----------------- cmake/sapi/CMakeLists.txt | 12 +++++ cmake/sapi/cgi/CMakeLists.txt | 1 + cmake/sapi/cli/CMakeLists.txt | 1 + cmake/sapi/embed/CMakeLists.txt | 1 + cmake/sapi/phpdbg/CMakeLists.txt | 1 + cmake/win32/CMakeLists.txt | 9 +--- 10 files changed, 63 insertions(+), 71 deletions(-) diff --git a/cmake/Zend/CMakeLists.txt b/cmake/Zend/CMakeLists.txt index 806ab64d4..bd96dad4f 100644 --- a/cmake/Zend/CMakeLists.txt +++ b/cmake/Zend/CMakeLists.txt @@ -88,16 +88,7 @@ mark_as_advanced(ZEND_SIGNALS) ################################################################################ add_library(zend OBJECT) -add_library(zend_interface INTERFACE) -add_library(Zend::Zend ALIAS zend_interface) -target_link_libraries( - zend_interface - INTERFACE - zend - $ -) -# https://gitlab.kitware.com/cmake/cmake/-/issues/23402 workaround: -add_dependencies(zend_interface zend) +add_library(Zend::Zend ALIAS zend) target_sources( zend @@ -364,17 +355,17 @@ endblock() # Add Zend PUBLIC/INTERFACE compile properties to configuration. # Cleaner COMPILE_ONLY generator expression is available in CMake >= 3.27. if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.27) - target_link_libraries(php_configuration INTERFACE $) + target_link_libraries(php_configuration INTERFACE $) else() target_include_directories( php_configuration INTERFACE - $ + $ ) target_compile_definitions( php_configuration INTERFACE - $ + $ ) endif() diff --git a/cmake/ext/pcntl/CMakeLists.txt b/cmake/ext/pcntl/CMakeLists.txt index 6f5448c85..e6b8d7ba7 100644 --- a/cmake/ext/pcntl/CMakeLists.txt +++ b/cmake/ext/pcntl/CMakeLists.txt @@ -9,7 +9,7 @@ This extension provides support for process control support. > This extension is available only on \*nix systems. > [!IMPORTANT] -> This extension should be used only with cgi, cli, embed, or phpdbg SAPI. +> This extension should be used only with CLI-based PHP SAPIs. ## EXT_PCNTL diff --git a/cmake/ext/readline/CMakeLists.txt b/cmake/ext/readline/CMakeLists.txt index 147ff7395..e02abf988 100644 --- a/cmake/ext/readline/CMakeLists.txt +++ b/cmake/ext/readline/CMakeLists.txt @@ -6,7 +6,7 @@ Configure the `readline` extension. This extension provides interface for using Editline library. > [!IMPORTANT] -> This extension should be used only with cgi, cli, embed, or phpdbg SAPI. +> This extension should be used only with CLI-based PHP SAPIs. ## EXT_READLINE diff --git a/cmake/main/CMakeLists.txt b/cmake/main/CMakeLists.txt index 2869cb778..6b915e89b 100644 --- a/cmake/main/CMakeLists.txt +++ b/cmake/main/CMakeLists.txt @@ -13,39 +13,11 @@ include(FeatureSummary) # Add library. ################################################################################ -add_library(php INTERFACE) -add_library(PHP::PHP ALIAS php) - add_library(php_main OBJECT) -add_library(php_main_interface INTERFACE) -add_library(PHP::main ALIAS php_main_interface) -target_link_libraries( - php_main_interface - INTERFACE - php_main - $ -) # These contain a list of built-in extensions based on the SAPI types. add_library(php_main_internal_functions OBJECT internal_functions.c) -add_library(php_main_internal_functions_interface INTERFACE) -add_library(PHP::mainInternalFunctions ALIAS php_main_internal_functions_interface) -target_link_libraries( - php_main_internal_functions_interface - INTERFACE - php_main_internal_functions - $ -) - add_library(php_main_internal_functions_cli OBJECT internal_functions_cli.c) -add_library(php_main_internal_functions_cli_interface INTERFACE) -add_library(PHP::mainInternalFunctionsCli ALIAS php_main_internal_functions_cli_interface) -target_link_libraries( - php_main_internal_functions_cli_interface - INTERFACE - php_main_internal_functions_cli - $ -) target_sources( php_main @@ -136,25 +108,12 @@ target_sources( $<$>:${CMAKE_CURRENT_BINARY_DIR}/php_config.h> ) -set_property( - TARGET - php_main - php_main_internal_functions - php_main_internal_functions_cli - APPEND - PROPERTY COMPILE_DEFINITIONS ZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -) - target_compile_definitions( php_main PUBLIC $<$:SAPI_EXPORTS> ) -target_link_libraries(php_main PRIVATE PHP::configuration) -target_link_libraries(php_main_internal_functions PRIVATE PHP::configuration) -target_link_libraries(php_main_internal_functions_cli PRIVATE PHP::configuration) - target_include_directories( php_main INTERFACE @@ -162,33 +121,66 @@ target_include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ) +set_property( + TARGET + php_main + php_main_internal_functions + php_main_internal_functions_cli + APPEND + PROPERTY COMPILE_DEFINITIONS ZEND_ENABLE_STATIC_TSRMLS_CACHE=1 +) + # Add main PUBLIC/INTERFACE compile properties to configuration. # Cleaner COMPILE_ONLY generator expression is available in CMake >= 3.27. if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.27) - target_link_libraries(php_configuration INTERFACE $) + target_link_libraries(php_configuration INTERFACE $) else() target_include_directories( php_configuration INTERFACE - $ + $ ) target_compile_definitions( php_configuration INTERFACE - $ + $ ) endif() +target_link_libraries(php_main PRIVATE PHP::configuration) +target_link_libraries(php_main_internal_functions PRIVATE PHP::configuration) +target_link_libraries(php_main_internal_functions_cli PRIVATE PHP::configuration) + +################################################################################ +# Add PHP::PHP. +################################################################################ + +add_library(php INTERFACE) +add_library(PHP::PHP ALIAS php) + target_link_libraries( php INTERFACE PHP::configuration - PHP::main - # Pass internal functions objects transitively depending on the SAPI type. - $,php_cgi;php_cli;php_embed;php_phpdbg>,PHP::mainInternalFunctionsCli,PHP::mainInternalFunctions> + php_main Zend::Zend + $<$::PHP::windows> PHP::extensions - $<$:PHP::windows> +) + +# OBJECT libraries propagate only compile properties to static libraries without +# objects as there is no "linking" involved on the compiler level. This is a +# workaround using interface target sources to make PHP::PHP more intuitive to +# work with SAPIs. +target_sources( + php + INTERFACE + $ + $ + $ + # Internal functions objects based on the SAPI type. + $>,$,$> + $<$:$> ) ################################################################################ diff --git a/cmake/sapi/CMakeLists.txt b/cmake/sapi/CMakeLists.txt index 5faed0b24..b3565efb8 100644 --- a/cmake/sapi/CMakeLists.txt +++ b/cmake/sapi/CMakeLists.txt @@ -10,6 +10,12 @@ Add subdirectories of PHP SAPIs. * `PHP_SAPIS` Global property with a list of all enabled PHP SAPIs. + +* `PHP_SAPI_CLI` + + Target property that designates PHP SAPI as CLI-based. These SAPIs can utilize + CLI-based PHP extensions (for example, pcntl) and include + main/internal_functions_cli.c object instead of the main/internal_functions.c. #]=============================================================================] message(STATUS "----------------------------") @@ -28,6 +34,12 @@ define_property( BRIEF_DOCS "A list of all enabled PHP SAPIs" ) +define_property( + TARGET + PROPERTY PHP_SAPI_CLI + BRIEF_DOCS "Whether the PHP SAPI is CLI-based to run in a CLI environment" +) + list(APPEND CMAKE_MESSAGE_CONTEXT "sapi") # Traverse CMakeLists.txt files of PHP SAPIs. diff --git a/cmake/sapi/cgi/CMakeLists.txt b/cmake/sapi/cgi/CMakeLists.txt index 01850b085..4144d58ff 100644 --- a/cmake/sapi/cgi/CMakeLists.txt +++ b/cmake/sapi/cgi/CMakeLists.txt @@ -57,6 +57,7 @@ set_target_properties( OUTPUT_NAME ${PHP_PROGRAM_PREFIX}php-cgi${PHP_PROGRAM_SUFFIX} # TODO: Check if there's a better solution here: ENABLE_EXPORTS TRUE + PHP_SAPI_CLI TRUE ) # BSD systems. diff --git a/cmake/sapi/cli/CMakeLists.txt b/cmake/sapi/cli/CMakeLists.txt index d8055578a..48bad1751 100644 --- a/cmake/sapi/cli/CMakeLists.txt +++ b/cmake/sapi/cli/CMakeLists.txt @@ -118,6 +118,7 @@ set_target_properties( OUTPUT_NAME ${PHP_PROGRAM_PREFIX}php${PHP_PROGRAM_SUFFIX} # TODO: Check if there's a better solution here: ENABLE_EXPORTS TRUE + PHP_SAPI_CLI TRUE ) if(CMAKE_SYSTEM_NAME STREQUAL "Windows") diff --git a/cmake/sapi/embed/CMakeLists.txt b/cmake/sapi/embed/CMakeLists.txt index 414905311..839071c46 100644 --- a/cmake/sapi/embed/CMakeLists.txt +++ b/cmake/sapi/embed/CMakeLists.txt @@ -57,6 +57,7 @@ set_target_properties( OUTPUT_NAME libphp # TODO: Check if there's a better solution here: ENABLE_EXPORTS TRUE + PHP_SAPI_CLI TRUE ) # Configure pkg-config php-embed.pc metadata file. diff --git a/cmake/sapi/phpdbg/CMakeLists.txt b/cmake/sapi/phpdbg/CMakeLists.txt index bb7e08b95..d0153360a 100644 --- a/cmake/sapi/phpdbg/CMakeLists.txt +++ b/cmake/sapi/phpdbg/CMakeLists.txt @@ -144,6 +144,7 @@ set_target_properties( OUTPUT_NAME ${PHP_PROGRAM_PREFIX}phpdbg${PHP_PROGRAM_SUFFIX} # TODO: Check if there's a better solution here: ENABLE_EXPORTS TRUE + PHP_SAPI_CLI TRUE ) ################################################################################ diff --git a/cmake/win32/CMakeLists.txt b/cmake/win32/CMakeLists.txt index 5cdba1d3d..18bfb0dee 100644 --- a/cmake/win32/CMakeLists.txt +++ b/cmake/win32/CMakeLists.txt @@ -10,14 +10,7 @@ include(FeatureSummary) ################################################################################ add_library(php_windows OBJECT) -add_library(php_windows_interface INTERFACE) -add_library(PHP::windows ALIAS php_windows_interface) -target_link_libraries( - php_windows_interface - INTERFACE - php_windows - $ -) +add_library(PHP::windows ALIAS php_windows) target_sources( php_windows From 4f30500b9293e2c04b25475a3fec3ddcb0ce3c74 Mon Sep 17 00:00:00 2001 From: Peter Kokot Date: Thu, 21 Nov 2024 22:37:26 +0100 Subject: [PATCH 4/5] Move TSRM configuration around --- cmake/CMakeLists.txt | 1 + cmake/TSRM/CMakeLists.txt | 32 ++++++++++++++++++++------------ cmake/Zend/CMakeLists.txt | 11 +---------- cmake/main/CMakeLists.txt | 5 +++-- cmake/win32/CMakeLists.txt | 1 + 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 40f609725..2878b03d2 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -29,6 +29,7 @@ include(cmake/Bootstrap.cmake) add_subdirectory(sapi) add_subdirectory(ext) +add_subdirectory(TSRM) add_subdirectory(Zend) message(STATUS "---------------") diff --git a/cmake/TSRM/CMakeLists.txt b/cmake/TSRM/CMakeLists.txt index d166685c8..9be4999b3 100644 --- a/cmake/TSRM/CMakeLists.txt +++ b/cmake/TSRM/CMakeLists.txt @@ -1,20 +1,11 @@ #[=============================================================================[ TSRM (Thread Safe Resource Manager) is a separate directory in php-src as it was -once a standalone project. Ideally, it should be integrated into Zend Engine. - -The `TSRM::TSRM` target is used to transitively pass the TSRM object(s) and -compile options to Zend Engine, which propagates it further as needed. +once a standalone project. Ideally, it should be moved into Zend Engine at some +point. #]=============================================================================] add_library(tsrm OBJECT) -add_library(tsrm_interface INTERFACE) -add_library(TSRM::TSRM ALIAS tsrm_interface) -target_link_libraries( - tsrm_interface - INTERFACE - tsrm - $ -) +add_library(TSRM::TSRM ALIAS tsrm) target_sources( tsrm @@ -45,6 +36,23 @@ target_compile_definitions( $<$:TSRM_EXPORTS> ) +# Add TSRM PUBLIC/INTERFACE compile properties to configuration. +# Cleaner COMPILE_ONLY generator expression is available in CMake >= 3.27. +if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.27) + target_link_libraries(php_configuration INTERFACE $) +else() + target_include_directories( + php_configuration + INTERFACE + $ + ) + target_compile_definitions( + php_configuration + INTERFACE + $ + ) +endif() + install( TARGETS tsrm FILE_SET HEADERS diff --git a/cmake/Zend/CMakeLists.txt b/cmake/Zend/CMakeLists.txt index bd96dad4f..816ad364c 100644 --- a/cmake/Zend/CMakeLists.txt +++ b/cmake/Zend/CMakeLists.txt @@ -298,16 +298,7 @@ target_sources( $<$>:${CMAKE_CURRENT_BINARY_DIR}/zend_config.h> ) -# Add TSRM. -add_subdirectory(../TSRM ../TSRM) - -target_link_libraries( - zend - PRIVATE - PHP::configuration - PUBLIC - TSRM::TSRM -) +target_link_libraries(zend PRIVATE PHP::configuration) target_include_directories( zend diff --git a/cmake/main/CMakeLists.txt b/cmake/main/CMakeLists.txt index 6b915e89b..5a684139d 100644 --- a/cmake/main/CMakeLists.txt +++ b/cmake/main/CMakeLists.txt @@ -164,6 +164,7 @@ target_link_libraries( PHP::configuration php_main Zend::Zend + TSRM::TSRM $<$::PHP::windows> PHP::extensions ) @@ -175,11 +176,11 @@ target_link_libraries( target_sources( php INTERFACE - $ - $ $ # Internal functions objects based on the SAPI type. $>,$,$> + $ + $ $<$:$> ) diff --git a/cmake/win32/CMakeLists.txt b/cmake/win32/CMakeLists.txt index 18bfb0dee..dcf293001 100644 --- a/cmake/win32/CMakeLists.txt +++ b/cmake/win32/CMakeLists.txt @@ -108,6 +108,7 @@ target_link_libraries( ################################################################################ # Generate wsyslog.h file with message compiler (mc). ################################################################################ + find_package(MC) set_package_properties( MC From 99618eea92d7108cc9be2988a26ef608c9e870fe Mon Sep 17 00:00:00 2001 From: Peter Kokot Date: Thu, 21 Nov 2024 23:06:06 +0100 Subject: [PATCH 5/5] Move TSRM to Zend Engine --- cmake/CMakeLists.txt | 1 - cmake/TSRM/CMakeLists.txt | 60 --------------------------------------- cmake/Zend/CMakeLists.txt | 35 +++++++++++++++++++++++ cmake/main/CMakeLists.txt | 2 -- 4 files changed, 35 insertions(+), 63 deletions(-) delete mode 100644 cmake/TSRM/CMakeLists.txt diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 2878b03d2..40f609725 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -29,7 +29,6 @@ include(cmake/Bootstrap.cmake) add_subdirectory(sapi) add_subdirectory(ext) -add_subdirectory(TSRM) add_subdirectory(Zend) message(STATUS "---------------") diff --git a/cmake/TSRM/CMakeLists.txt b/cmake/TSRM/CMakeLists.txt deleted file mode 100644 index 9be4999b3..000000000 --- a/cmake/TSRM/CMakeLists.txt +++ /dev/null @@ -1,60 +0,0 @@ -#[=============================================================================[ -TSRM (Thread Safe Resource Manager) is a separate directory in php-src as it was -once a standalone project. Ideally, it should be moved into Zend Engine at some -point. -#]=============================================================================] - -add_library(tsrm OBJECT) -add_library(TSRM::TSRM ALIAS tsrm) - -target_sources( - tsrm - PRIVATE - $<$:tsrm_win32.c> - TSRM.c - PUBLIC - FILE_SET HEADERS - FILES - $<$:tsrm_win32.h> - TSRM.h -) - -target_link_libraries(tsrm PRIVATE PHP::configuration) - -target_include_directories( - tsrm - INTERFACE - $ - $ -) - -target_compile_definitions( - tsrm - PRIVATE - ZEND_ENABLE_STATIC_TSRMLS_CACHE=1 - PUBLIC - $<$:TSRM_EXPORTS> -) - -# Add TSRM PUBLIC/INTERFACE compile properties to configuration. -# Cleaner COMPILE_ONLY generator expression is available in CMake >= 3.27. -if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.27) - target_link_libraries(php_configuration INTERFACE $) -else() - target_include_directories( - php_configuration - INTERFACE - $ - ) - target_compile_definitions( - php_configuration - INTERFACE - $ - ) -endif() - -install( - TARGETS tsrm - FILE_SET HEADERS - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PHP_INCLUDE_PREFIX}/TSRM -) diff --git a/cmake/Zend/CMakeLists.txt b/cmake/Zend/CMakeLists.txt index 816ad364c..00136a374 100644 --- a/cmake/Zend/CMakeLists.txt +++ b/cmake/Zend/CMakeLists.txt @@ -360,6 +360,41 @@ else() ) endif() +################################################################################ +# TSRM (Thread Safe Resource Manager) is a separate directory in php-src as it +# was once a standalone project. Ideally, it should be moved into Zend Engine at +# some point. +################################################################################ + +target_sources( + zend + PRIVATE + $<$:${CMAKE_CURRENT_SOURCE_DIR}/../TSRM/tsrm_win32.c> + ${CMAKE_CURRENT_SOURCE_DIR}/../TSRM/TSRM.c + PUBLIC + FILE_SET tsrm + TYPE HEADERS + BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../TSRM + FILES + $<$:${CMAKE_CURRENT_SOURCE_DIR}/../TSRM/tsrm_win32.h> + ${CMAKE_CURRENT_SOURCE_DIR}/../TSRM/TSRM.h +) + +target_include_directories( + zend + INTERFACE + $ + $ +) + +target_compile_definitions(zend PUBLIC $<$:TSRM_EXPORTS>) + +install( + TARGETS zend + FILE_SET tsrm + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PHP_INCLUDE_PREFIX}/TSRM +) + ################################################################################ # Configuration checks. ################################################################################ diff --git a/cmake/main/CMakeLists.txt b/cmake/main/CMakeLists.txt index 5a684139d..e544ecd41 100644 --- a/cmake/main/CMakeLists.txt +++ b/cmake/main/CMakeLists.txt @@ -164,7 +164,6 @@ target_link_libraries( PHP::configuration php_main Zend::Zend - TSRM::TSRM $<$::PHP::windows> PHP::extensions ) @@ -179,7 +178,6 @@ target_sources( $ # Internal functions objects based on the SAPI type. $>,$,$> - $ $ $<$:$> )