diff --git a/cmake/TSRM/CMakeLists.txt b/cmake/TSRM/CMakeLists.txt deleted file mode 100644 index 2044b7920..000000000 --- a/cmake/TSRM/CMakeLists.txt +++ /dev/null @@ -1,53 +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 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. -#]=============================================================================] - -add_library(tsrm_object OBJECT) -add_library(tsrm INTERFACE) -add_library(TSRM::TSRM ALIAS tsrm) - -target_link_libraries( - tsrm - INTERFACE - tsrm_object - $ -) - -target_sources( - tsrm_object - PRIVATE - $<$:tsrm_win32.c> - TSRM.c - PUBLIC - FILE_SET HEADERS - FILES - $<$:tsrm_win32.h> - TSRM.h -) - -target_link_libraries(tsrm_object PRIVATE PHP::configuration) - -target_include_directories( - tsrm_object - INTERFACE - $ - $ -) - -target_compile_definitions( - tsrm_object - PRIVATE - ZEND_ENABLE_STATIC_TSRMLS_CACHE=1 - PUBLIC - $<$:TSRM_EXPORTS> -) - -install( - TARGETS tsrm_object - 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..00136a374 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` @@ -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 @@ -352,18 +343,58 @@ 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 $) + target_link_libraries(php_configuration INTERFACE $) else() target_include_directories( php_configuration INTERFACE - $ + $ + ) + target_compile_definitions( + php_configuration + INTERFACE + $ ) 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/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..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 @@ -114,7 +118,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/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 fb42b11f9..e544ecd41 100644 --- a/cmake/main/CMakeLists.txt +++ b/cmake/main/CMakeLists.txt @@ -9,20 +9,16 @@ PHP main binding. include(FeatureSummary) -add_library(php INTERFACE) -add_library(PHP::PHP ALIAS php) +################################################################################ +# Add library. +################################################################################ add_library(php_main OBJECT) -add_library(PHP::main ALIAS 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_cli OBJECT internal_functions_cli.c) -# 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 @@ -113,23 +109,11 @@ target_sources( ) target_compile_definitions( - php_main_configuration - INTERFACE - ZEND_ENABLE_STATIC_TSRMLS_CACHE=1 + php_main + PUBLIC $<$:SAPI_EXPORTS> ) -target_link_libraries( - php_main_configuration - INTERFACE - PHP::configuration - $<$:PHP::win32 $> -) - -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_include_directories( php_main INTERFACE @@ -137,27 +121,71 @@ target_include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ) -# Add main PUBLIC/INTERFACE include directories to configuration. -target_include_directories( - php_configuration - INTERFACE - $ +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 $) +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 transitively depending on the SAPI type. - $,php_cgi;php_cli;php_embed;php_phpdbg>,php_main_internal_functions_cli $,php_main_internal_functions $> + php_main Zend::Zend - $ + $<$::PHP::windows> PHP::extensions ) +# 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. + $>,$,$> + $ + $<$:$> +) + +################################################################################ # Add DTrace. +################################################################################ + if(PHP_DTRACE) message(CHECK_START "Checking for DTrace support") @@ -196,7 +224,10 @@ add_feature_info( "performance analysis and troubleshooting" ) +################################################################################ # Add Dmalloc. +################################################################################ + if(PHP_DMALLOC) message(CHECK_START "Checking for Dmalloc support") @@ -211,7 +242,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/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 ec1189ad3..dcf293001 100644 --- a/cmake/win32/CMakeLists.txt +++ b/cmake/win32/CMakeLists.txt @@ -5,11 +5,15 @@ 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 ALIAS php_windows) target_sources( - php_win32 + php_windows PRIVATE codepage.c console.c @@ -85,7 +89,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 +105,10 @@ target_link_libraries( ws2_32 ) +################################################################################ # Generate wsyslog.h file with message compiler (mc). +################################################################################ + find_package(MC) set_package_properties( MC @@ -111,27 +118,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_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_executable(php_windows_encoding_map_generator cp_enc_map_gen.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