From 0fbbe8d52c054cdecba537996d0887eee1d9d18d Mon Sep 17 00:00:00 2001 From: Peter Kokot Date: Fri, 13 Dec 2024 23:03:08 +0100 Subject: [PATCH 1/5] Add new global target php_sapis_config This collects all usage requirements for PHP SAPIs. --- cmake/Zend/CMakeLists.txt | 14 ++- cmake/cmake/Bootstrap.cmake | 10 ++- cmake/cmake/modules/PHP/Extensions.cmake | 18 ++-- cmake/ext/CMakeLists.txt | 19 +--- cmake/main/CMakeLists.txt | 107 +++++++++-------------- cmake/sapi/phpdbg/CMakeLists.txt | 12 --- cmake/win32/CMakeLists.txt | 3 + 7 files changed, 76 insertions(+), 107 deletions(-) diff --git a/cmake/Zend/CMakeLists.txt b/cmake/Zend/CMakeLists.txt index e98a14ff8..e09a0eadb 100644 --- a/cmake/Zend/CMakeLists.txt +++ b/cmake/Zend/CMakeLists.txt @@ -318,23 +318,29 @@ set_target_properties( ZEND_MODULE_API_NO ${Zend_VERSION_MODULE_API_NO} ) -# Add Zend PUBLIC/INTERFACE compile properties to configuration. +################################################################################ +# Pass transitive compile and link properties to PHP configuration interface. +################################################################################ + # 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_sapis_config INTERFACE Zend::Zend) +target_sources(php_sapis_config INTERFACE $) + ################################################################################ # 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 diff --git a/cmake/cmake/Bootstrap.cmake b/cmake/cmake/Bootstrap.cmake index 6558f79f5..d2056fdca 100644 --- a/cmake/cmake/Bootstrap.cmake +++ b/cmake/cmake/Bootstrap.cmake @@ -33,7 +33,9 @@ include(PHP/InterproceduralOptimization) # Set CMAKE_POSITION_INDEPENDENT_CODE. include(PHP/PositionIndependentCode) -# Create a project wide INTERFACE library with project configuration. +# INTERFACE library with usage requirements. All targets that need PHP compile +# or link properties, such as include directories, global compile definitions, +# or flags, should link to this target. add_library(php_configuration INTERFACE) add_library(PHP::configuration ALIAS php_configuration) target_include_directories( @@ -43,6 +45,12 @@ target_include_directories( ${PHP_SOURCE_DIR} ) +# INTERFACE library that ties all target objects and configuration together. +# Only PHP SAPI targets should link to it. +add_library(php_sapis_config INTERFACE) +add_library(PHP::PHP ALIAS php_sapis_config) +target_link_libraries(php_sapis_config INTERFACE PHP::configuration) + # Create a custom target for generating files (parsers, lexers, etc.) manually: # cmake --build -t php_generate_files add_custom_target(php_generate_files) diff --git a/cmake/cmake/modules/PHP/Extensions.cmake b/cmake/cmake/modules/PHP/Extensions.cmake index 97ec16a85..9056d273a 100644 --- a/cmake/cmake/modules/PHP/Extensions.cmake +++ b/cmake/cmake/modules/PHP/Extensions.cmake @@ -396,13 +396,17 @@ function(php_extensions_postconfigure extension) "'ON'." ) - set( - EXT_${dependencyUpper} - ON - CACHE BOOL - "Enable the ${dependency} extension" - FORCE - ) + if(DEFINED CACHE{EXT_${dependencyUpper}}) + set_property(CACHE EXT_${dependencyUpper} PROPERTY VALUE ON) + else() + set( + EXT_${dependencyUpper} + ON + CACHE BOOL + "Enable the ${dependency} extension" + FORCE + ) + endif() endforeach() if(NOT TARGET PHP::${extension}) diff --git a/cmake/ext/CMakeLists.txt b/cmake/ext/CMakeLists.txt index 136617379..d861218b1 100644 --- a/cmake/ext/CMakeLists.txt +++ b/cmake/ext/CMakeLists.txt @@ -1,10 +1,5 @@ #[=============================================================================[ Add subdirectories of PHP extensions. - -## INTERFACE target - -* `php_extensions` (alias `PHP::extensions`) is an INTERFACE library with all - enabled extensions linked into for convenience. #]=============================================================================] include(PHP/Extensions) @@ -57,9 +52,6 @@ set_property(GLOBAL PROPERTY PHP_ALL_EXTENSIONS ${extensions}) # Sort and preconfigure extensions by their dependencies. php_extensions_preprocess(extensions) -add_library(php_extensions INTERFACE) -add_library(PHP::extensions ALIAS php_extensions) - # Add subdirectories of extensions. foreach(extension IN LISTS extensions) list(APPEND CMAKE_MESSAGE_CONTEXT "${extension}") @@ -80,8 +72,7 @@ foreach(extension IN LISTS extensions) add_dependencies(php_${extension} Zend::Zend) - # Add extension's transitive compile and link properties to configuration. - # The INTERFACE_SOURCES are propagated separately only to PHP::PHP. + # Pass transitive compile and link properties to PHP configuration interface. # See: https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html # TODO: Should PHP_CLI extensions pass properties only to PHP_CLI SAPIs? get_target_property(type php_${extension} TYPE) @@ -112,17 +103,15 @@ foreach(extension IN LISTS extensions) ) target_link_libraries( - php_extensions + php_sapis_config INTERFACE - $>>,$<$>:$>,$> + $>>,$<$>:PHP::${extension}>,PHP::${extension}> ) target_sources( - php_extensions + php_sapis_config INTERFACE $>>,$<$>:$>,$> - - $>>,$<$>:$>,$> ) endif() diff --git a/cmake/main/CMakeLists.txt b/cmake/main/CMakeLists.txt index 1744790bd..e942b2d58 100644 --- a/cmake/main/CMakeLists.txt +++ b/cmake/main/CMakeLists.txt @@ -1,10 +1,5 @@ #[=============================================================================[ PHP main binding. - -## INTERFACE target - -* `php` (alias `PHP::PHP`) is an INTERFACE library that ties PHP core, Zend - Engine and PHP extensions together and can be easily linked to SAPIs. #]=============================================================================] include(FeatureSummary) @@ -14,10 +9,7 @@ include(FeatureSummary) ################################################################################ add_library(php_main OBJECT) - -# 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) +add_library(PHP::main ALIAS php_main) target_sources( php_main @@ -121,76 +113,43 @@ 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 -) - -# 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) + +# Compile and link properties for all targets in this directory scope. +add_compile_definitions(ZEND_ENABLE_STATIC_TSRMLS_CACHE) ################################################################################ -# Add PHP::PHP. +# Add transitive compile and link properties to PHP interface targets. ################################################################################ -add_library(php INTERFACE) -add_library(PHP::PHP ALIAS php) - -target_link_libraries( - php +target_compile_definitions( + php_configuration INTERFACE - PHP::configuration - php_main - # If Zend is STATIC library link as whole archive, otherwise link normally. - $,STATIC_LIBRARY>,$,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 +target_compile_options( + php_configuration INTERFACE - $ - - # Internal functions objects based on the SAPI type. - $>,$,$> - - # If Zend is OBJECT library, add library objects as sources. - $<$,OBJECT_LIBRARY>:$> + $ +) - # If Zend is STATIC library, and linking to a STATIC library (SAPI), add - # library objects as sources. - $<$,STATIC_LIBRARY>,$,STATIC_LIBRARY>>:$> +target_compile_features( + php_configuration + INTERFACE + $ +) - $<$:$> +target_include_directories( + php_configuration + INTERFACE + $ + $ ) +target_link_libraries(php_sapis_config INTERFACE PHP::main) +target_sources(php_sapis_config INTERFACE $) + ################################################################################ # Add DTrace. ################################################################################ @@ -221,8 +180,8 @@ if(PHP_DTRACE) INCLUDES $ ) - target_link_libraries(php_main PRIVATE DTrace::DTrace) - target_link_libraries(php INTERFACE php_dtrace) + target_link_libraries(php_main PUBLIC DTrace::DTrace) + target_link_libraries(php_main INTERFACE php_dtrace) set(HAVE_DTRACE TRUE PARENT_SCOPE) @@ -296,6 +255,18 @@ file(CONFIGURE OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/php_version.h CONTENT [[ # extensions based on the PHP SAPI type. ################################################################################ +add_library(php_main_internal_functions OBJECT internal_functions.c) +add_library(php_main_internal_functions_cli OBJECT internal_functions_cli.c) + +target_sources( + php_sapis_config + INTERFACE + $>,$,$> +) + +target_link_libraries(php_main_internal_functions PRIVATE PHP::configuration) +target_link_libraries(php_main_internal_functions_cli PRIVATE PHP::configuration) + block() set(includes "") set(includesCli "") diff --git a/cmake/sapi/phpdbg/CMakeLists.txt b/cmake/sapi/phpdbg/CMakeLists.txt index 974bbfdbb..9fc1a2bea 100644 --- a/cmake/sapi/phpdbg/CMakeLists.txt +++ b/cmake/sapi/phpdbg/CMakeLists.txt @@ -228,22 +228,10 @@ if(SAPI_PHPDBG_SHARED) php_phpdbg_shared PRIVATE ZEND_ENABLE_STATIC_TSRMLS_CACHE - $ $<$:YY_NO_UNISTD_H> $,PHPDBG_DEBUG=1,PHPDBG_DEBUG=0> ) - target_include_directories( - php_phpdbg_shared - PRIVATE - $ - ) - - target_compile_options( - php_phpdbg_shared - PRIVATE $ - ) - target_link_libraries( php_phpdbg_shared PRIVATE diff --git a/cmake/win32/CMakeLists.txt b/cmake/win32/CMakeLists.txt index dcf293001..ad38f421e 100644 --- a/cmake/win32/CMakeLists.txt +++ b/cmake/win32/CMakeLists.txt @@ -105,6 +105,9 @@ target_link_libraries( ws2_32 ) +target_link_libraries(php_sapis_config INTERFACE PHP::windows) +target_sources(php_sapis_config INTERFACE $) + ################################################################################ # Generate wsyslog.h file with message compiler (mc). ################################################################################ From 2949e236f3efad111d032654cdb3f727dc37ebee Mon Sep 17 00:00:00 2001 From: Peter Kokot Date: Fri, 13 Dec 2024 23:37:35 +0100 Subject: [PATCH 2/5] Configure dependencies between ext/standard targets --- cmake/ext/standard/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmake/ext/standard/CMakeLists.txt b/cmake/ext/standard/CMakeLists.txt index 6b6e7b4ba..ea806d918 100644 --- a/cmake/ext/standard/CMakeLists.txt +++ b/cmake/ext/standard/CMakeLists.txt @@ -578,6 +578,9 @@ target_sources( $>,$,$> ) +add_dependencies(php_standard_functions php_standard) +add_dependencies(php_standard_functions_cli php_standard) + ################################################################################ # Configuration header ################################################################################ From bc9b2bd2987f3d7a73d6d85c10819065bc296403 Mon Sep 17 00:00:00 2001 From: Peter Kokot Date: Sat, 14 Dec 2024 00:08:32 +0100 Subject: [PATCH 3/5] Move docs link --- cmake/cmake/Bootstrap.cmake | 1 + cmake/ext/CMakeLists.txt | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/cmake/Bootstrap.cmake b/cmake/cmake/Bootstrap.cmake index d2056fdca..25769f28c 100644 --- a/cmake/cmake/Bootstrap.cmake +++ b/cmake/cmake/Bootstrap.cmake @@ -47,6 +47,7 @@ target_include_directories( # INTERFACE library that ties all target objects and configuration together. # Only PHP SAPI targets should link to it. +# See: https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html add_library(php_sapis_config INTERFACE) add_library(PHP::PHP ALIAS php_sapis_config) target_link_libraries(php_sapis_config INTERFACE PHP::configuration) diff --git a/cmake/ext/CMakeLists.txt b/cmake/ext/CMakeLists.txt index d861218b1..7d07ad11f 100644 --- a/cmake/ext/CMakeLists.txt +++ b/cmake/ext/CMakeLists.txt @@ -73,7 +73,6 @@ foreach(extension IN LISTS extensions) add_dependencies(php_${extension} Zend::Zend) # Pass transitive compile and link properties to PHP configuration interface. - # See: https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html # TODO: Should PHP_CLI extensions pass properties only to PHP_CLI SAPIs? get_target_property(type php_${extension} TYPE) if(NOT type MATCHES "^(MODULE|SHARED)_LIBRARY$") From d6927122d086476f458e0f8cb8771515ba85b19f Mon Sep 17 00:00:00 2001 From: Peter Kokot Date: Sat, 14 Dec 2024 01:09:07 +0100 Subject: [PATCH 4/5] Rename php_sapis_config to php_sapi (PHP::SAPI) --- cmake/Zend/CMakeLists.txt | 20 ++++++-- cmake/cmake/Bootstrap.cmake | 14 ++---- cmake/cmake/modules/FindGcov.cmake | 16 +++--- cmake/ext/CMakeLists.txt | 6 +-- .../ext/skeleton/cmake/modules/FindPHP.cmake | 2 +- cmake/main/CMakeLists.txt | 8 +-- cmake/sapi/apache2handler/CMakeLists.txt | 2 +- cmake/sapi/cgi/CMakeLists.txt | 2 +- cmake/sapi/cli/CMakeLists.txt | 4 +- cmake/sapi/embed/CMakeLists.txt | 2 +- cmake/sapi/fpm/CMakeLists.txt | 4 +- cmake/sapi/fuzzer/CMakeLists.txt | 2 +- cmake/sapi/litespeed/CMakeLists.txt | 2 +- cmake/sapi/phpdbg/CMakeLists.txt | 6 +-- cmake/win32/CMakeLists.txt | 50 +++++++++++++++---- 15 files changed, 89 insertions(+), 51 deletions(-) diff --git a/cmake/Zend/CMakeLists.txt b/cmake/Zend/CMakeLists.txt index e09a0eadb..68ab188df 100644 --- a/cmake/Zend/CMakeLists.txt +++ b/cmake/Zend/CMakeLists.txt @@ -319,27 +319,37 @@ set_target_properties( ) ################################################################################ -# Pass transitive compile and link properties to PHP configuration interface. +# Add transitive compile and link properties to PHP configuration interface. ################################################################################ # 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_compile_definitions( + php_configuration + INTERFACE + $ + ) + target_compile_options( + php_configuration + INTERFACE + $ + ) target_include_directories( php_configuration INTERFACE $ ) - target_compile_definitions( + target_link_libraries( php_configuration INTERFACE - $ + $ ) endif() -target_link_libraries(php_sapis_config INTERFACE Zend::Zend) -target_sources(php_sapis_config INTERFACE $) +target_link_libraries(php_sapi INTERFACE Zend::Zend) +target_sources(php_sapi INTERFACE $) ################################################################################ # TSRM (Thread Safe Resource Manager) is a separate directory in php-src as it diff --git a/cmake/cmake/Bootstrap.cmake b/cmake/cmake/Bootstrap.cmake index 25769f28c..c23ba94e5 100644 --- a/cmake/cmake/Bootstrap.cmake +++ b/cmake/cmake/Bootstrap.cmake @@ -33,9 +33,7 @@ include(PHP/InterproceduralOptimization) # Set CMAKE_POSITION_INDEPENDENT_CODE. include(PHP/PositionIndependentCode) -# INTERFACE library with usage requirements. All targets that need PHP compile -# or link properties, such as include directories, global compile definitions, -# or flags, should link to this target. +# INTERFACE library with usage requirements. add_library(php_configuration INTERFACE) add_library(PHP::configuration ALIAS php_configuration) target_include_directories( @@ -45,12 +43,10 @@ target_include_directories( ${PHP_SOURCE_DIR} ) -# INTERFACE library that ties all target objects and configuration together. -# Only PHP SAPI targets should link to it. -# See: https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html -add_library(php_sapis_config INTERFACE) -add_library(PHP::PHP ALIAS php_sapis_config) -target_link_libraries(php_sapis_config INTERFACE PHP::configuration) +# INTERFACE library that ties objects and configuration together for PHP SAPIs. +add_library(php_sapi INTERFACE) +add_library(PHP::SAPI ALIAS php_sapi) +target_link_libraries(php_sapi INTERFACE PHP::configuration) # Create a custom target for generating files (parsers, lexers, etc.) manually: # cmake --build -t php_generate_files diff --git a/cmake/cmake/modules/FindGcov.cmake b/cmake/cmake/modules/FindGcov.cmake index 54a1d2fde..8cd810e88 100644 --- a/cmake/cmake/modules/FindGcov.cmake +++ b/cmake/cmake/modules/FindGcov.cmake @@ -188,27 +188,29 @@ macro(gcov_generate_report) ) # Create a list of PHP SAPIs with genex for usage in the add_custom_command. - block(PROPAGATE php_sapis) - set(php_sapis "") + block(PROPAGATE sapis) + set(sapis "") file(GLOB directories ${PROJECT_SOURCE_DIR}/sapi/*) foreach(dir ${directories}) cmake_path(GET dir FILENAME sapi) - list(APPEND php_sapis "$") + list(APPEND sapis "$") endforeach() endblock() add_custom_command( OUTPUT ${PROJECT_BINARY_DIR}/php_lcov.info COMMAND ${CMAKE_COMMAND} -P "CMakeFiles/GenerateGcovReport.cmake" - DEPENDS - ${php_sapis} + DEPENDS ${sapis} COMMENT "[GCOV] Generating GCOV coverage report" + VERBATIM + COMMAND_EXPAND_LISTS ) - unset(php_sapis) + unset(sapis) # Create target which consumes the command via DEPENDS. - add_custom_target(gcov ALL + add_custom_target( + gcov ALL DEPENDS ${PROJECT_BINARY_DIR}/php_lcov.info COMMENT "[GCOV] Generating GCOV files" ) diff --git a/cmake/ext/CMakeLists.txt b/cmake/ext/CMakeLists.txt index 7d07ad11f..f4c14c9ac 100644 --- a/cmake/ext/CMakeLists.txt +++ b/cmake/ext/CMakeLists.txt @@ -72,7 +72,7 @@ foreach(extension IN LISTS extensions) add_dependencies(php_${extension} Zend::Zend) - # Pass transitive compile and link properties to PHP configuration interface. + # Add transitive compile and link properties to PHP configuration interface. # TODO: Should PHP_CLI extensions pass properties only to PHP_CLI SAPIs? get_target_property(type php_${extension} TYPE) if(NOT type MATCHES "^(MODULE|SHARED)_LIBRARY$") @@ -102,13 +102,13 @@ foreach(extension IN LISTS extensions) ) target_link_libraries( - php_sapis_config + php_sapi INTERFACE $>>,$<$>:PHP::${extension}>,PHP::${extension}> ) target_sources( - php_sapis_config + php_sapi INTERFACE $>>,$<$>:$>,$> ) diff --git a/cmake/ext/skeleton/cmake/modules/FindPHP.cmake b/cmake/ext/skeleton/cmake/modules/FindPHP.cmake index 685eedb19..b22206dcf 100644 --- a/cmake/ext/skeleton/cmake/modules/FindPHP.cmake +++ b/cmake/ext/skeleton/cmake/modules/FindPHP.cmake @@ -13,7 +13,7 @@ Components: Module defines the following `IMPORTED` target(s): * `PHP::php` - The PHP package `IMPORTED` target, if found. -* `PHP:embed` - The PHP embed SAPI, if found. +* `PHP::embed` - The PHP embed SAPI, if found. ## Result variables diff --git a/cmake/main/CMakeLists.txt b/cmake/main/CMakeLists.txt index e942b2d58..e34b5e770 100644 --- a/cmake/main/CMakeLists.txt +++ b/cmake/main/CMakeLists.txt @@ -119,7 +119,7 @@ target_link_libraries(php_main PRIVATE PHP::configuration) add_compile_definitions(ZEND_ENABLE_STATIC_TSRMLS_CACHE) ################################################################################ -# Add transitive compile and link properties to PHP interface targets. +# Add transitive compile and link properties to PHP configuration interface. ################################################################################ target_compile_definitions( @@ -147,8 +147,8 @@ target_include_directories( $ ) -target_link_libraries(php_sapis_config INTERFACE PHP::main) -target_sources(php_sapis_config INTERFACE $) +target_link_libraries(php_sapi INTERFACE PHP::main) +target_sources(php_sapi INTERFACE $) ################################################################################ # Add DTrace. @@ -259,7 +259,7 @@ add_library(php_main_internal_functions OBJECT internal_functions.c) add_library(php_main_internal_functions_cli OBJECT internal_functions_cli.c) target_sources( - php_sapis_config + php_sapi INTERFACE $>,$,$> ) diff --git a/cmake/sapi/apache2handler/CMakeLists.txt b/cmake/sapi/apache2handler/CMakeLists.txt index 438aabb1c..e3602ddcf 100644 --- a/cmake/sapi/apache2handler/CMakeLists.txt +++ b/cmake/sapi/apache2handler/CMakeLists.txt @@ -109,7 +109,7 @@ endif() target_link_libraries( php_apache2handler PRIVATE - PHP::PHP + PHP::SAPI Apache::Apache ) diff --git a/cmake/sapi/cgi/CMakeLists.txt b/cmake/sapi/cgi/CMakeLists.txt index e03a3e4b7..4eec0cdd1 100644 --- a/cmake/sapi/cgi/CMakeLists.txt +++ b/cmake/sapi/cgi/CMakeLists.txt @@ -41,7 +41,7 @@ target_compile_definitions(php_cgi PRIVATE ZEND_ENABLE_STATIC_TSRMLS_CACHE) target_link_libraries( php_cgi PRIVATE - PHP::PHP + PHP::SAPI $<$:ws2_32;kernel32;advapi32> ) diff --git a/cmake/sapi/cli/CMakeLists.txt b/cmake/sapi/cli/CMakeLists.txt index 00ae99bab..437cdc4cb 100644 --- a/cmake/sapi/cli/CMakeLists.txt +++ b/cmake/sapi/cli/CMakeLists.txt @@ -102,7 +102,7 @@ target_compile_definitions( target_link_libraries( php_cli PRIVATE - PHP::PHP + PHP::SAPI $<$:ws2_32;shell32> ) @@ -158,7 +158,7 @@ if(SAPI_CLI_WIN_NO_CONSOLE) target_link_libraries( php_cli_win_no_console PRIVATE - PHP::PHP + PHP::SAPI shell32 ) diff --git a/cmake/sapi/embed/CMakeLists.txt b/cmake/sapi/embed/CMakeLists.txt index 0265e9a30..7e9fb1aac 100644 --- a/cmake/sapi/embed/CMakeLists.txt +++ b/cmake/sapi/embed/CMakeLists.txt @@ -47,7 +47,7 @@ target_sources( target_link_libraries( php_embed PRIVATE - PHP::PHP + PHP::SAPI ) target_compile_definitions(php_embed PRIVATE ZEND_ENABLE_STATIC_TSRMLS_CACHE) diff --git a/cmake/sapi/fpm/CMakeLists.txt b/cmake/sapi/fpm/CMakeLists.txt index 6e7af9159..89aee6967 100644 --- a/cmake/sapi/fpm/CMakeLists.txt +++ b/cmake/sapi/fpm/CMakeLists.txt @@ -188,7 +188,7 @@ endif() ################################################################################ add_executable(php_fpm) -add_executable(PHP:fpm ALIAS php_fpm) +add_executable(PHP::fpm ALIAS php_fpm) target_sources( php_fpm @@ -235,7 +235,7 @@ target_compile_definitions(php_fpm PRIVATE ZEND_ENABLE_STATIC_TSRMLS_CACHE) target_link_libraries( php_fpm PRIVATE - PHP::PHP + PHP::SAPI ) set_target_properties( diff --git a/cmake/sapi/fuzzer/CMakeLists.txt b/cmake/sapi/fuzzer/CMakeLists.txt index 99af7074e..b8b686b0e 100644 --- a/cmake/sapi/fuzzer/CMakeLists.txt +++ b/cmake/sapi/fuzzer/CMakeLists.txt @@ -139,7 +139,7 @@ set_target_properties( target_link_libraries( php_fuzzer PRIVATE - PHP::PHP + PHP::SAPI ) install(TARGETS php_fuzzer RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/cmake/sapi/litespeed/CMakeLists.txt b/cmake/sapi/litespeed/CMakeLists.txt index 55ab68f4b..5b9ab223a 100644 --- a/cmake/sapi/litespeed/CMakeLists.txt +++ b/cmake/sapi/litespeed/CMakeLists.txt @@ -46,7 +46,7 @@ target_sourceS( target_link_libraries( php_litespeed PRIVATE - PHP::PHP + PHP::SAPI ) set_target_properties( diff --git a/cmake/sapi/phpdbg/CMakeLists.txt b/cmake/sapi/phpdbg/CMakeLists.txt index 9fc1a2bea..0d2744e72 100644 --- a/cmake/sapi/phpdbg/CMakeLists.txt +++ b/cmake/sapi/phpdbg/CMakeLists.txt @@ -125,7 +125,7 @@ set(php_phpdbg_sources ) add_executable(php_phpdbg ${php_phpdbg_sources}) -add_executable(PHP:phpdbg ALIAS php_phpdbg) +add_executable(PHP::phpdbg ALIAS php_phpdbg) target_compile_definitions( php_phpdbg @@ -138,7 +138,7 @@ target_compile_definitions( target_link_libraries( php_phpdbg PRIVATE - PHP::PHP + PHP::SAPI $<$:ws2_32;user32> ) @@ -236,7 +236,7 @@ if(SAPI_PHPDBG_SHARED) php_phpdbg_shared PRIVATE # TODO: fix this better in the future (building with -fPIC etc). - PHP::PHP + PHP::SAPI $<$:ws2_32;user32> ) endif() diff --git a/cmake/win32/CMakeLists.txt b/cmake/win32/CMakeLists.txt index ad38f421e..aceb99ae9 100644 --- a/cmake/win32/CMakeLists.txt +++ b/cmake/win32/CMakeLists.txt @@ -68,8 +68,8 @@ target_sources( ) target_compile_definitions( - php_configuration - INTERFACE + php_windows + PUBLIC _MBCS _USE_MATH_DEFINES PHP_EXPORTS @@ -83,17 +83,17 @@ target_compile_definitions( # MS deprecated ANSI stdio and similar functions. Disable warnings. target_compile_options( - php_configuration - INTERFACE + php_windows + PUBLIC $<$:/wd4996> $<$:/wd4996> ) -target_link_libraries(php_windows PRIVATE PHP::configuration) - target_link_libraries( - php_configuration - INTERFACE + php_windows + PRIVATE + PHP::configuration + PUBLIC advapi32 bcrypt Dnsapi @@ -105,8 +105,38 @@ target_link_libraries( ws2_32 ) -target_link_libraries(php_sapis_config INTERFACE PHP::windows) -target_sources(php_sapis_config INTERFACE $) +################################################################################ +# Add transitive compile and link properties to PHP configuration interface. +################################################################################ + +# 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_compile_definitions( + php_configuration + INTERFACE + $ + ) + target_compile_options( + php_configuration + INTERFACE + $ + ) + target_include_directories( + php_configuration + INTERFACE + $ + ) + target_link_libraries( + php_configuration + INTERFACE + $ + ) +endif() + +target_link_libraries(php_sapi INTERFACE PHP::windows) +target_sources(php_sapi INTERFACE $) ################################################################################ # Generate wsyslog.h file with message compiler (mc). From 2b1782d2678b7344b42c154097c0b30f0640dba8 Mon Sep 17 00:00:00 2001 From: Peter Kokot Date: Sat, 14 Dec 2024 14:53:49 +0100 Subject: [PATCH 5/5] Refactor targets and usage requirements - MAX_EXECUTION_TIMERS don't need to be set in PARENT_SCOPE anymore - Reorder some include directories - DTrace and Dmalloc checks moved to configure checks - usage requirements in main and win32 collected through interface targets directly otherwise cyclic dependencies quickly pop up --- cmake/Zend/CMakeLists.txt | 10 +- cmake/Zend/cmake/MaxExecutionTimers.cmake | 7 - cmake/cmake/ConfigureChecks.cmake | 80 ++++++++++- cmake/ext/CMakeLists.txt | 2 +- cmake/ext/standard/CMakeLists.txt | 32 ++--- cmake/main/CMakeLists.txt | 168 ++++------------------ cmake/win32/CMakeLists.txt | 50 ++----- 7 files changed, 132 insertions(+), 217 deletions(-) diff --git a/cmake/Zend/CMakeLists.txt b/cmake/Zend/CMakeLists.txt index 68ab188df..41b60efc5 100644 --- a/cmake/Zend/CMakeLists.txt +++ b/cmake/Zend/CMakeLists.txt @@ -298,8 +298,8 @@ target_link_libraries(zend PRIVATE PHP::configuration) target_include_directories( zend INTERFACE - ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR} ) target_compile_definitions( @@ -319,7 +319,7 @@ set_target_properties( ) ################################################################################ -# Add transitive compile and link properties to PHP configuration interface. +# Add usage requirements to PHP interface targets. ################################################################################ # Cleaner COMPILE_ONLY generator expression is available in CMake >= 3.27. @@ -340,11 +340,7 @@ else() php_configuration INTERFACE $ - ) - target_link_libraries( - php_configuration - INTERFACE - $ + $ ) endif() diff --git a/cmake/Zend/cmake/MaxExecutionTimers.cmake b/cmake/Zend/cmake/MaxExecutionTimers.cmake index 86a1e8576..b540ddd96 100644 --- a/cmake/Zend/cmake/MaxExecutionTimers.cmake +++ b/cmake/Zend/cmake/MaxExecutionTimers.cmake @@ -86,13 +86,6 @@ add_feature_info( "enhanced timeout and signal handling" ) -# Set the result variable also in the PARENT_SCOPE, to make it available for the -# parent project PHP in its configuration headers. This module is included in -# the Zend Engine which is added with add_subdirectory() in the PHP project. -if(NOT PROJECT_IS_TOP_LEVEL) - set(ZEND_MAX_EXECUTION_TIMERS ${ZEND_MAX_EXECUTION_TIMERS} PARENT_SCOPE) -endif() - add_library(Zend::MaxExecutionTimers INTERFACE IMPORTED GLOBAL) if(libraryForTimerCreate) target_link_libraries( diff --git a/cmake/cmake/ConfigureChecks.cmake b/cmake/cmake/ConfigureChecks.cmake index f0c1f7d1b..04a1e455f 100644 --- a/cmake/cmake/ConfigureChecks.cmake +++ b/cmake/cmake/ConfigureChecks.cmake @@ -818,7 +818,7 @@ if(PHP_GCOV) endif() endif() -# Check Valgrind. +# Valgrind. if(PHP_VALGRIND) find_package(Valgrind) set_package_properties( @@ -836,6 +836,82 @@ if(PHP_VALGRIND) endif() add_feature_info( "Valgrind" - PHP_VALGRIND + HAVE_VALGRIND "dynamic analysis" ) + +# DTrace. +if(PHP_DTRACE) + message(CHECK_START "Checking for DTrace support") + + find_package(DTrace) + set_package_properties( + DTrace + PROPERTIES + TYPE REQUIRED + PURPOSE "Necessary to enable the DTrace support." + ) + + if(DTrace_FOUND) + dtrace_target( + php_dtrace + INPUT ${PHP_SOURCE_DIR}/Zend/zend_dtrace.d + HEADER ${PHP_BINARY_DIR}/Zend/zend_dtrace_gen.h + SOURCES + ${PHP_SOURCE_DIR}/main/main.c + ${PHP_SOURCE_DIR}/Zend/zend_API.c + ${PHP_SOURCE_DIR}/Zend/zend_dtrace.c + ${PHP_SOURCE_DIR}/Zend/zend_exceptions.c + ${PHP_SOURCE_DIR}/Zend/zend_execute.c + ${PHP_SOURCE_DIR}/Zend/zend.c + INCLUDES + $ + ) + target_link_libraries(php_configuration INTERFACE DTrace::DTrace) + target_link_libraries(php_sapi INTERFACE php_dtrace) + + set(HAVE_DTRACE TRUE) + + message(CHECK_PASS "yes") + else() + message(CHECK_FAIL "no") + endif() +endif() +add_feature_info( + "DTrace" + HAVE_DTRACE + "performance analysis and troubleshooting" +) + +# Dmalloc. +if(PHP_DMALLOC) + message(CHECK_START "Checking for Dmalloc support") + + find_package(Dmalloc) + set_package_properties( + Dmalloc + PROPERTIES + TYPE REQUIRED + PURPOSE "Necessary to use Dmalloc memory debugger." + ) + + target_compile_definitions( + php_configuration + INTERFACE + $<$:DMALLOC_FUNC_CHECK> + ) + + target_link_libraries(php_configuration INTERFACE Dmalloc::Dmalloc) + + if(Dmalloc_FOUND) + message(CHECK_PASS "yes") + set(HAVE_DMALLOC TRUE) + else() + message(CHECK_FAIL "no") + endif() +endif() +add_feature_info( + "Dmalloc" + HAVE_DMALLOC + "memory debugging" +) diff --git a/cmake/ext/CMakeLists.txt b/cmake/ext/CMakeLists.txt index f4c14c9ac..d4bc512f2 100644 --- a/cmake/ext/CMakeLists.txt +++ b/cmake/ext/CMakeLists.txt @@ -72,7 +72,7 @@ foreach(extension IN LISTS extensions) add_dependencies(php_${extension} Zend::Zend) - # Add transitive compile and link properties to PHP configuration interface. + # Add usage requirements to PHP interface targets. # TODO: Should PHP_CLI extensions pass properties only to PHP_CLI SAPIs? get_target_property(type php_${extension} TYPE) if(NOT type MATCHES "^(MODULE|SHARED)_LIBRARY$") diff --git a/cmake/ext/standard/CMakeLists.txt b/cmake/ext/standard/CMakeLists.txt index ea806d918..378440009 100644 --- a/cmake/ext/standard/CMakeLists.txt +++ b/cmake/ext/standard/CMakeLists.txt @@ -534,42 +534,26 @@ endblock() check_symbol_exists(chroot "unistd.h" HAVE_CHROOT) -add_library(php_standard_functions_cli OBJECT) add_library(php_standard_functions OBJECT) +add_library(php_standard_functions_cli OBJECT) -target_sources(php_standard_functions_cli PRIVATE basic_functions.c dir.c) target_sources(php_standard_functions PRIVATE basic_functions.c dir.c) +target_sources(php_standard_functions_cli PRIVATE basic_functions.c dir.c) -target_include_directories( - php_standard_functions_cli - PRIVATE - $ -) -target_include_directories( +set_target_properties( php_standard_functions - PRIVATE - $ + php_standard_functions_cli + PROPERTIES + INCLUDE_DIRECTORIES $ + COMPILE_DEFINITIONS $ + LINK_LIBRARIES $ ) target_compile_definitions( php_standard_functions_cli PRIVATE - $ $<$>:ENABLE_CHROOT_FUNC> ) -target_compile_definitions( - php_standard_functions - PRIVATE $ -) - -target_link_libraries( - php_standard_functions_cli - PRIVATE $ -) -target_link_libraries( - php_standard_functions - PRIVATE $ -) # ext/standard functions objects based on the SAPI type. target_sources( diff --git a/cmake/main/CMakeLists.txt b/cmake/main/CMakeLists.txt index e34b5e770..2527498d7 100644 --- a/cmake/main/CMakeLists.txt +++ b/cmake/main/CMakeLists.txt @@ -2,7 +2,9 @@ PHP main binding. #]=============================================================================] -include(FeatureSummary) +# Compile and link properties for all targets in this directory scope. +add_compile_definitions(ZEND_ENABLE_STATIC_TSRMLS_CACHE) +link_libraries(PHP::configuration) ################################################################################ # Add library. @@ -100,156 +102,26 @@ target_sources( $<$>:${CMAKE_CURRENT_BINARY_DIR}/php_config.h> ) -target_compile_definitions( - php_main - PUBLIC - $<$:SAPI_EXPORTS> -) - -target_include_directories( - php_main - INTERFACE - ${CMAKE_CURRENT_BINARY_DIR} - ${CMAKE_CURRENT_SOURCE_DIR} -) - -target_link_libraries(php_main PRIVATE PHP::configuration) - -# Compile and link properties for all targets in this directory scope. -add_compile_definitions(ZEND_ENABLE_STATIC_TSRMLS_CACHE) - ################################################################################ -# Add transitive compile and link properties to PHP configuration interface. +# Add usage requirements to PHP interface targets. ################################################################################ target_compile_definitions( php_configuration INTERFACE - $ -) - -target_compile_options( - php_configuration - INTERFACE - $ -) - -target_compile_features( - php_configuration - INTERFACE - $ + $<$:SAPI_EXPORTS> ) target_include_directories( php_configuration INTERFACE - $ - $ + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR} ) target_link_libraries(php_sapi INTERFACE PHP::main) target_sources(php_sapi INTERFACE $) -################################################################################ -# Add DTrace. -################################################################################ - -if(PHP_DTRACE) - message(CHECK_START "Checking for DTrace support") - - find_package(DTrace) - set_package_properties( - DTrace - PROPERTIES - TYPE REQUIRED - PURPOSE "Necessary to enable the DTrace support." - ) - - if(DTrace_FOUND) - dtrace_target( - php_dtrace - INPUT ${PHP_SOURCE_DIR}/Zend/zend_dtrace.d - HEADER ${PHP_BINARY_DIR}/Zend/zend_dtrace_gen.h - SOURCES - main.c - ${PHP_SOURCE_DIR}/Zend/zend_API.c - ${PHP_SOURCE_DIR}/Zend/zend_dtrace.c - ${PHP_SOURCE_DIR}/Zend/zend_exceptions.c - ${PHP_SOURCE_DIR}/Zend/zend_execute.c - ${PHP_SOURCE_DIR}/Zend/zend.c - INCLUDES - $ - ) - target_link_libraries(php_main PUBLIC DTrace::DTrace) - target_link_libraries(php_main INTERFACE php_dtrace) - - set(HAVE_DTRACE TRUE PARENT_SCOPE) - - message(CHECK_PASS "yes") - else() - message(CHECK_FAIL "no") - endif() -endif() -add_feature_info( - "DTrace" - PHP_DTRACE - "performance analysis and troubleshooting" -) - -################################################################################ -# Add Dmalloc. -################################################################################ - -if(PHP_DMALLOC) - message(CHECK_START "Checking for Dmalloc support") - - find_package(Dmalloc) - set_package_properties( - Dmalloc - PROPERTIES - TYPE REQUIRED - PURPOSE "Necessary to use Dmalloc memory debugger." - ) - - target_compile_definitions( - php_configuration - INTERFACE - $<$:DMALLOC_FUNC_CHECK> - ) - - target_link_libraries(php_main PRIVATE Dmalloc::Dmalloc) - - if(Dmalloc_FOUND) - message(CHECK_PASS "yes") - set(HAVE_DMALLOC TRUE PARENT_SCOPE) - else() - message(CHECK_FAIL "no") - endif() -endif() - -################################################################################ -# Create main/php_version.h. Template is based on the configure.ac. -################################################################################ - -cmake_path( - RELATIVE_PATH - CMAKE_CURRENT_SOURCE_DIR - BASE_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_VARIABLE relativeSourceDir -) - -message(STATUS "Creating ${relativeSourceDir}/php_version.h") -file(CONFIGURE OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/php_version.h CONTENT [[ -/* automatically generated by configure */ -/* edit configure.ac to change version number */ -#define PHP_MAJOR_VERSION @PHP_VERSION_MAJOR@ -#define PHP_MINOR_VERSION @PHP_VERSION_MINOR@ -#define PHP_RELEASE_VERSION @PHP_VERSION_PATCH@ -#define PHP_EXTRA_VERSION "@PHP_VERSION_LABEL@" -#define PHP_VERSION "@PHP_VERSION@" -#define PHP_VERSION_ID @PHP_VERSION_ID@ -]]) - ################################################################################ # Create main/internal_functions*.c files with a list of static enabled PHP # extensions based on the PHP SAPI type. @@ -264,9 +136,6 @@ target_sources( $>,$,$> ) -target_link_libraries(php_main_internal_functions PRIVATE PHP::configuration) -target_link_libraries(php_main_internal_functions_cli PRIVATE PHP::configuration) - block() set(includes "") set(includesCli "") @@ -322,6 +191,29 @@ block() file(GENERATE OUTPUT internal_functions_cli.c CONTENT "${content}") endblock() +################################################################################ +# Create main/php_version.h. Template is based on the configure.ac. +################################################################################ + +cmake_path( + RELATIVE_PATH + CMAKE_CURRENT_SOURCE_DIR + BASE_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE relativeSourceDir +) + +message(STATUS "Creating ${relativeSourceDir}/php_version.h") +file(CONFIGURE OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/php_version.h CONTENT [[ +/* automatically generated by configure */ +/* edit configure.ac to change version number */ +#define PHP_MAJOR_VERSION @PHP_VERSION_MAJOR@ +#define PHP_MINOR_VERSION @PHP_VERSION_MINOR@ +#define PHP_RELEASE_VERSION @PHP_VERSION_PATCH@ +#define PHP_EXTRA_VERSION "@PHP_VERSION_LABEL@" +#define PHP_VERSION "@PHP_VERSION@" +#define PHP_VERSION_ID @PHP_VERSION_ID@ +]]) + ################################################################################ # Generate configuration headers. ################################################################################ diff --git a/cmake/win32/CMakeLists.txt b/cmake/win32/CMakeLists.txt index aceb99ae9..e2b608edd 100644 --- a/cmake/win32/CMakeLists.txt +++ b/cmake/win32/CMakeLists.txt @@ -67,9 +67,15 @@ target_sources( ${CMAKE_CURRENT_BINARY_DIR}/wsyslog.h ) +target_link_libraries(php_windows PRIVATE PHP::configuration) + +################################################################################ +# Add usage requirements to PHP interface targets. +################################################################################ + target_compile_definitions( - php_windows - PUBLIC + php_configuration + INTERFACE _MBCS _USE_MATH_DEFINES PHP_EXPORTS @@ -83,17 +89,15 @@ target_compile_definitions( # MS deprecated ANSI stdio and similar functions. Disable warnings. target_compile_options( - php_windows - PUBLIC + php_configuration + INTERFACE $<$:/wd4996> $<$:/wd4996> ) target_link_libraries( - php_windows - PRIVATE - PHP::configuration - PUBLIC + php_configuration + INTERFACE advapi32 bcrypt Dnsapi @@ -105,36 +109,6 @@ target_link_libraries( ws2_32 ) -################################################################################ -# Add transitive compile and link properties to PHP configuration interface. -################################################################################ - -# 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_compile_definitions( - php_configuration - INTERFACE - $ - ) - target_compile_options( - php_configuration - INTERFACE - $ - ) - target_include_directories( - php_configuration - INTERFACE - $ - ) - target_link_libraries( - php_configuration - INTERFACE - $ - ) -endif() - target_link_libraries(php_sapi INTERFACE PHP::windows) target_sources(php_sapi INTERFACE $)