diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 9fffa41de..bb49f2aa5 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -56,10 +56,24 @@ target_include_directories( ${PHP_SOURCE_DIR} ) -# 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::config) +# Create PHP core library that ties objects and configuration together for PHP +# SAPIs and shared extensions. On Windows (win32 directory) there is also a +# shared DLL created for shared extensions to have symbols available. +add_library(php_core INTERFACE) +add_library(PHP::core ALIAS php_core) + +add_library(php_core_objects INTERFACE) +add_library(PHP::core::objects ALIAS php_core_objects) +target_link_libraries( + php_core + INTERFACE + PHP::config + $<$>:PHP::core::objects> +) + +target_compile_definitions( + php_config INTERFACE +) ################################################################################ # Configure project. @@ -77,6 +91,14 @@ define_property( BRIEF_DOCS "Whether the PHP SAPI is FastCGI-based" ) +define_property( + TARGET + PROPERTY PHP_CORE + BRIEF_DOCS + "Whether the target should get compile properties dedicated to PHP core " + "objects (e.g, *_EXPORTS compile definitions, etc.)." +) + # Check whether IPO/LTO can be enabled. include(PHP/Optimization) @@ -101,6 +123,7 @@ include(cmake/ConfigureChecks.cmake) # Check compilation options. include(cmake/Flags.cmake) +add_subdirectory(win32) add_subdirectory(sapi) add_subdirectory(ext) add_subdirectory(Zend) @@ -112,7 +135,6 @@ message(STATUS "===============") message(STATUS "") add_subdirectory(pear) -add_subdirectory(win32) add_subdirectory(main) add_subdirectory(scripts) diff --git a/cmake/Zend/CMakeLists.txt b/cmake/Zend/CMakeLists.txt index b79118eb9..88aa2bbd4 100644 --- a/cmake/Zend/CMakeLists.txt +++ b/cmake/Zend/CMakeLists.txt @@ -318,7 +318,7 @@ target_compile_definitions( PRIVATE ZEND_ENABLE_STATIC_TSRMLS_CACHE PUBLIC - $<$:LIBZEND_EXPORTS> + $<$,$>>:LIBZEND_EXPORTS> ) set_target_properties( @@ -327,6 +327,7 @@ set_target_properties( VERSION ${Zend_VERSION} ZEND_EXTENSION_API_NO ${Zend_VERSION_EXTENSION_API_NO} ZEND_MODULE_API_NO ${Zend_VERSION_MODULE_API_NO} + PHP_CORE TRUE ) ################################################################################ @@ -334,8 +335,8 @@ set_target_properties( ################################################################################ target_link_libraries(php_config INTERFACE $) -target_link_libraries(php_sapi INTERFACE Zend::Zend) -target_sources(php_sapi INTERFACE $) +target_link_libraries(php_core_objects INTERFACE Zend::Zend) +target_sources(php_core_objects INTERFACE $) ################################################################################ # TSRM (Thread Safe Resource Manager) is a separate directory in php-src as it @@ -364,7 +365,11 @@ target_include_directories( $ ) -target_compile_definitions(zend PUBLIC $<$:TSRM_EXPORTS>) +target_compile_definitions( + zend + PUBLIC + $<$,$>>:TSRM_EXPORTS> +) install( TARGETS zend diff --git a/cmake/cmake/ConfigureChecks.cmake b/cmake/cmake/ConfigureChecks.cmake index 16dc79f1a..ded87d76b 100644 --- a/cmake/cmake/ConfigureChecks.cmake +++ b/cmake/cmake/ConfigureChecks.cmake @@ -887,9 +887,10 @@ if(PHP_DTRACE) INCLUDES $ ) + set_target_properties(php_dtrace PROPERTIES PHP_CORE TRUE) target_link_libraries(php_config INTERFACE DTrace::DTrace) - target_link_libraries(php_sapi INTERFACE php_dtrace) + target_link_libraries(php_core_objects INTERFACE php_dtrace) set(HAVE_DTRACE TRUE) endif() diff --git a/cmake/cmake/modules/PHP/Extensions.cmake b/cmake/cmake/modules/PHP/Extensions.cmake index 5b6dc93bb..a83b5d650 100644 --- a/cmake/cmake/modules/PHP/Extensions.cmake +++ b/cmake/cmake/modules/PHP/Extensions.cmake @@ -444,6 +444,14 @@ function(php_extensions_postconfigure extension) set_property(TARGET php_ext_${extension} PROPERTY OUTPUT_NAME ${extension}) endif() + # Set target output filename prefix "[]". + if(CMAKE_SYSTEM_NAME STREQUAL "Windows") + get_target_property(prefix php_ext_${extension} PREFIX) + if(NOT prefix) + set_property(TARGET php_ext_${extension} PROPERTY PREFIX "php_") + endif() + endif() + # Specify extension's default installation rules. get_target_property(sets php_ext_${extension} INTERFACE_HEADER_SETS) set(fileSets "") diff --git a/cmake/ext/CMakeLists.txt b/cmake/ext/CMakeLists.txt index 72eb6b13a..228292251 100644 --- a/cmake/ext/CMakeLists.txt +++ b/cmake/ext/CMakeLists.txt @@ -75,7 +75,14 @@ foreach(extension IN LISTS extensions) # Add usage requirements to PHP interface targets. # TODO: Should PHP_CLI extensions pass properties only to PHP_CLI SAPIs? get_target_property(type PHP::ext::${extension} TYPE) - if(NOT type MATCHES "^(MODULE|SHARED)_LIBRARY$") + if(type MATCHES "^(MODULE|SHARED)_LIBRARY$") + target_link_libraries( + php_ext_${extension} + PRIVATE $<$:$> + ) + else() + set_target_properties(php_ext_${extension} PROPERTIES PHP_CORE TRUE) + target_compile_definitions( php_config INTERFACE @@ -102,13 +109,13 @@ foreach(extension IN LISTS extensions) ) target_link_libraries( - php_sapi + php_core_objects INTERFACE $>>,$<$>:PHP::ext::${extension}>,PHP::ext::${extension}> ) target_sources( - php_sapi + php_core_objects INTERFACE $>>,$<$>:$>,$> ) diff --git a/cmake/ext/iconv/CMakeLists.txt b/cmake/ext/iconv/CMakeLists.txt index fe1251292..5afdb5673 100644 --- a/cmake/ext/iconv/CMakeLists.txt +++ b/cmake/ext/iconv/CMakeLists.txt @@ -72,12 +72,8 @@ target_sources( ) get_target_property(type php_ext_iconv TYPE) -if( - CMAKE_SYSTEM_NAME STREQUAL "Windows" - AND TARGET php_sapi - AND NOT type MATCHES "^(MODULE|SHARED)_LIBRARY$" -) - target_sources(php_sapi INTERFACE php_iconv.def) +if(TARGET php_windows AND type MATCHES "^(OBJECT|STATIC)_LIBRARY$") + target_sources(php_windows PRIVATE php_iconv.def) endif() target_compile_definitions( diff --git a/cmake/ext/libxml/CMakeLists.txt b/cmake/ext/libxml/CMakeLists.txt index cb7f4f4d4..c40749f67 100644 --- a/cmake/ext/libxml/CMakeLists.txt +++ b/cmake/ext/libxml/CMakeLists.txt @@ -53,8 +53,8 @@ target_sources( php_libxml.h ) -if(CMAKE_SYSTEM_NAME STREQUAL "Windows" AND TARGET php_sapi) - target_sources(php_sapi INTERFACE php_libxml2.def) +if(TARGET php_windows) + target_sources(php_windows PRIVATE php_libxml2.def) endif() target_compile_definitions( diff --git a/cmake/ext/pcre/CMakeLists.txt b/cmake/ext/pcre/CMakeLists.txt index 05c3d4809..c8bfa41c1 100644 --- a/cmake/ext/pcre/CMakeLists.txt +++ b/cmake/ext/pcre/CMakeLists.txt @@ -203,8 +203,8 @@ else() if(CMAKE_SYSTEM_NAME STREQUAL "Windows") set(PCRE2_STATIC TRUE) - if(TARGET php_sapi) - target_sources(php_sapi INTERFACE php_pcre.def) + if(TARGET php_windows) + target_sources(php_windows PRIVATE php_pcre.def) endif() endif() diff --git a/cmake/ext/standard/CMakeLists.txt b/cmake/ext/standard/CMakeLists.txt index aa06637f9..058e1c150 100644 --- a/cmake/ext/standard/CMakeLists.txt +++ b/cmake/ext/standard/CMakeLists.txt @@ -481,6 +481,7 @@ set_target_properties( INCLUDE_DIRECTORIES $ COMPILE_DEFINITIONS $ LINK_LIBRARIES $ + PHP_CORE TRUE ) target_compile_definitions( diff --git a/cmake/ext/tidy/CMakeLists.txt b/cmake/ext/tidy/CMakeLists.txt index c0f360049..0354cb2b4 100644 --- a/cmake/ext/tidy/CMakeLists.txt +++ b/cmake/ext/tidy/CMakeLists.txt @@ -68,12 +68,8 @@ target_sources( ) get_target_property(type php_ext_tidy TYPE) -if( - CMAKE_SYSTEM_NAME STREQUAL "Windows" - AND TARGET php_sapi - AND NOT type MATCHES "^(MODULE|SHARED)_LIBRARY$" -) - target_sources(php_sapi INTERFACE php_tidy.def) +if(TARGET php_windows AND type MATCHES "^(OBJECT|STATIC)_LIBRARY$") + target_sources(php_windows PRIVATE php_tidy.def) endif() # Add -Wno-ignored-qualifiers as this is an issue upstream. Fixed in tidy-html5 diff --git a/cmake/ext/zlib/CMakeLists.txt b/cmake/ext/zlib/CMakeLists.txt index dc17e3c51..d6bedb3b0 100644 --- a/cmake/ext/zlib/CMakeLists.txt +++ b/cmake/ext/zlib/CMakeLists.txt @@ -67,12 +67,8 @@ target_sources( ) get_target_property(type php_ext_zlib TYPE) -if( - CMAKE_SYSTEM_NAME STREQUAL "Windows" - AND TARGET php_sapi - AND NOT type MATCHES "^(MODULE|SHARED)_LIBRARY$" -) - target_sources(php_sapi INTERFACE php_zlib.def) +if(TARGET php_windows AND type MATCHES "^(OBJECT|STATIC)_LIBRARY$") + target_sources(php_windows PRIVATE php_zlib.def) endif() target_compile_definitions(php_ext_zlib PRIVATE ZEND_ENABLE_STATIC_TSRMLS_CACHE) diff --git a/cmake/main/CMakeLists.txt b/cmake/main/CMakeLists.txt index 30f20edb7..866955423 100644 --- a/cmake/main/CMakeLists.txt +++ b/cmake/main/CMakeLists.txt @@ -104,6 +104,8 @@ target_sources( $<$>:${PHP_BINARY_DIR}/$/main/php_config.h> ) +set_target_properties(php_main PROPERTIES PHP_CORE TRUE) + ################################################################################ # Add usage requirements to PHP interface targets. ################################################################################ @@ -111,7 +113,7 @@ target_sources( target_compile_definitions( php_config INTERFACE - $<$:SAPI_EXPORTS> + $<$,$>>:SAPI_EXPORTS> ) target_include_directories( @@ -123,8 +125,8 @@ target_include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ) -target_link_libraries(php_sapi INTERFACE PHP::main) -target_sources(php_sapi INTERFACE $) +target_link_libraries(php_core_objects INTERFACE PHP::main) +target_sources(php_core_objects INTERFACE $) ################################################################################ # Add FastCGI target with objects for use in PHP SAPIs such as CGI and FPM. @@ -132,7 +134,7 @@ target_sources(php_sapi INTERFACE $) add_library(php_main_fastcgi OBJECT fastcgi.c) target_sources( - php_sapi + php_core INTERFACE $<$>:$> ) @@ -144,9 +146,14 @@ target_sources( add_library(php_main_internal_functions OBJECT internal_functions.c) add_library(php_main_internal_functions_cli OBJECT internal_functions_cli.c) +set_target_properties( + php_main_internal_functions + php_main_internal_functions_cli + PROPERTIES PHP_CORE TRUE +) target_sources( - php_sapi + php_core_objects INTERFACE $>,$,$> ) diff --git a/cmake/sapi/CMakeLists.txt b/cmake/sapi/CMakeLists.txt index f554e123a..b802e5b52 100644 --- a/cmake/sapi/CMakeLists.txt +++ b/cmake/sapi/CMakeLists.txt @@ -22,6 +22,8 @@ define_property( list(APPEND CMAKE_MESSAGE_CONTEXT "sapi") +set(CMAKE_ENABLE_EXPORTS TRUE) + # Traverse CMakeLists.txt files of PHP SAPIs. file(GLOB sapis ${CMAKE_CURRENT_SOURCE_DIR}/*/CMakeLists.txt) list(TRANSFORM sapis REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/|/CMakeLists.txt" "") diff --git a/cmake/sapi/apache2handler/CMakeLists.txt b/cmake/sapi/apache2handler/CMakeLists.txt index 954f21892..01d931e41 100644 --- a/cmake/sapi/apache2handler/CMakeLists.txt +++ b/cmake/sapi/apache2handler/CMakeLists.txt @@ -78,7 +78,7 @@ set_package_properties( target_link_libraries( php_sapi_apache2handler PRIVATE - $ + $ Apache::Apache ) diff --git a/cmake/sapi/cgi/CMakeLists.txt b/cmake/sapi/cgi/CMakeLists.txt index f03abe261..f6fbde378 100644 --- a/cmake/sapi/cgi/CMakeLists.txt +++ b/cmake/sapi/cgi/CMakeLists.txt @@ -41,7 +41,7 @@ target_compile_definitions(php_sapi_cgi PRIVATE ZEND_ENABLE_STATIC_TSRMLS_CACHE) target_link_libraries( php_sapi_cgi PRIVATE - $ + $ $<$:ws2_32;kernel32;advapi32> ) @@ -53,7 +53,6 @@ set_target_properties( php_sapi_cgi PROPERTIES OUTPUT_NAME ${PHP_PROGRAM_PREFIX}php-cgi${PHP_PROGRAM_SUFFIX} - ENABLE_EXPORTS TRUE # TODO: Check if there's a better solution. PHP_CLI TRUE PHP_SAPI_FASTCGI TRUE ) diff --git a/cmake/sapi/cli/CMakeLists.txt b/cmake/sapi/cli/CMakeLists.txt index a2c3467e4..d89f7b057 100644 --- a/cmake/sapi/cli/CMakeLists.txt +++ b/cmake/sapi/cli/CMakeLists.txt @@ -110,7 +110,7 @@ target_compile_definitions( target_link_libraries( php_sapi_cli PRIVATE - $ + $ $<$:ws2_32;shell32> ) @@ -122,7 +122,6 @@ set_target_properties( php_sapi_cli PROPERTIES OUTPUT_NAME ${PHP_PROGRAM_PREFIX}php${PHP_PROGRAM_SUFFIX} - ENABLE_EXPORTS TRUE # TODO: Check if there's a better solution. PHP_CLI TRUE ) @@ -182,7 +181,7 @@ if(PHP_SAPI_CLI_WIN_NO_CONSOLE) target_link_libraries( php_sapi_cli_win PRIVATE - $ + $ shell32 ) diff --git a/cmake/sapi/embed/CMakeLists.txt b/cmake/sapi/embed/CMakeLists.txt index bc85129c2..da70eb803 100644 --- a/cmake/sapi/embed/CMakeLists.txt +++ b/cmake/sapi/embed/CMakeLists.txt @@ -53,7 +53,7 @@ target_sources( foreach(target IN ITEMS php_sapi_embed php_sapi_embed_shared) target_sources(${target} PRIVATE php_embed.c) - target_link_libraries(${target} PRIVATE $) + target_link_libraries(${target} PRIVATE $) target_compile_definitions(${target} PRIVATE ZEND_ENABLE_STATIC_TSRMLS_CACHE) @@ -76,7 +76,6 @@ foreach(target IN ITEMS php_sapi_embed php_sapi_embed_shared) set_target_properties( ${target} PROPERTIES - ENABLE_EXPORTS TRUE # TODO: Check if there's a better solution. PHP_CLI TRUE ) endforeach() diff --git a/cmake/sapi/fpm/CMakeLists.txt b/cmake/sapi/fpm/CMakeLists.txt index 67571a322..3b35b3dde 100644 --- a/cmake/sapi/fpm/CMakeLists.txt +++ b/cmake/sapi/fpm/CMakeLists.txt @@ -233,14 +233,13 @@ target_compile_definitions(php_sapi_fpm PRIVATE ZEND_ENABLE_STATIC_TSRMLS_CACHE) target_link_libraries( php_sapi_fpm PRIVATE - $ + $ ) set_target_properties( php_sapi_fpm PROPERTIES OUTPUT_NAME ${PHP_PROGRAM_PREFIX}php-fpm${PHP_PROGRAM_SUFFIX} - ENABLE_EXPORTS TRUE # TODO: Check if there's a better solution. PHP_SAPI_FASTCGI TRUE ) diff --git a/cmake/sapi/fuzzer/CMakeLists.txt b/cmake/sapi/fuzzer/CMakeLists.txt index 9b6847bd2..6247c63f2 100644 --- a/cmake/sapi/fuzzer/CMakeLists.txt +++ b/cmake/sapi/fuzzer/CMakeLists.txt @@ -139,7 +139,7 @@ set_target_properties( target_link_libraries( php_sapi_fuzzer PRIVATE - $ + $ ) install(TARGETS php_sapi_fuzzer RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/cmake/sapi/litespeed/CMakeLists.txt b/cmake/sapi/litespeed/CMakeLists.txt index 5dde80aa2..f64671046 100644 --- a/cmake/sapi/litespeed/CMakeLists.txt +++ b/cmake/sapi/litespeed/CMakeLists.txt @@ -46,14 +46,13 @@ target_sources( target_link_libraries( php_sapi_litespeed PRIVATE - $ + $ ) set_target_properties( php_sapi_litespeed PROPERTIES OUTPUT_NAME ${PHP_PROGRAM_PREFIX}lsphp${PHP_PROGRAM_SUFFIX} - ENABLE_EXPORTS TRUE # TODO: Check if there's a better solution. ) install( diff --git a/cmake/sapi/phpdbg/CMakeLists.txt b/cmake/sapi/phpdbg/CMakeLists.txt index 1ddd179de..443b7e192 100644 --- a/cmake/sapi/phpdbg/CMakeLists.txt +++ b/cmake/sapi/phpdbg/CMakeLists.txt @@ -156,7 +156,7 @@ foreach(target IN ITEMS php_sapi_phpdbg php_sapi_phpdbg_shared) target_link_libraries( ${target} PRIVATE - $ + $ $<$:ws2_32;user32> ) @@ -164,7 +164,6 @@ foreach(target IN ITEMS php_sapi_phpdbg php_sapi_phpdbg_shared) ${target} PROPERTIES OUTPUT_NAME ${PHP_PROGRAM_PREFIX}phpdbg${PHP_PROGRAM_SUFFIX} - ENABLE_EXPORTS TRUE # TODO: Check if there's a better solution. PHP_CLI TRUE ) endforeach() diff --git a/cmake/win32/CMakeLists.txt b/cmake/win32/CMakeLists.txt index ed76ef3fd..1530354d8 100644 --- a/cmake/win32/CMakeLists.txt +++ b/cmake/win32/CMakeLists.txt @@ -9,7 +9,7 @@ include(FeatureSummary) # Add library. ################################################################################ -add_library(php_windows OBJECT) +add_library(php_windows SHARED) add_library(PHP::windows ALIAS php_windows) target_sources( @@ -69,7 +69,35 @@ target_sources( ) target_include_directories(php_windows PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) -target_link_libraries(php_windows PRIVATE PHP::config) + +target_link_libraries( + php_windows + PRIVATE + PHP::config + PHP::core::objects +) + +set_target_properties(php_windows PROPERTIES OUTPUT_NAME php PHP_CORE TRUE) + +get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) +if(isMultiConfig) + set_target_properties( + php_windows + PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PHP_BINARY_DIR} + ) +else() + set_target_properties( + php_windows + PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PHP_BINARY_DIR}/$ + ) +endif() + +target_link_options( + php_windows + PRIVATE + /nodefaultlib:libcmt + /d2:-AllowCompatibleILVersions +) ################################################################################ # Add usage requirements to PHP interface targets. @@ -94,9 +122,13 @@ target_compile_definitions( # For Zend Engine, same as PHP_WIN32. ZEND_WIN32 + # Obsolete in favor of PHP_WIN32. + WINDOWS + _MBCS _USE_MATH_DEFINES - PHP_EXPORTS + + $<$>:PHP_EXPORTS> # The time_t defaults to 64-bit. Force 32-bit time_t on 32-bit architecture. # This was historically added to PHP as Visual Studio 2005 set 64-bit time_t @@ -104,6 +136,10 @@ target_compile_definitions( # compilers. This and duplicate definition in the configuration header # should be removed at some point. $<$:_USE_32BIT_TIME_T=1> + + $<$>:_USRDLL> + + $<$>:WINVER=0x0602> ) target_compile_options( @@ -112,10 +148,19 @@ target_compile_options( # MS deprecated ANSI stdio and similar functions. Disable warnings. $<$:/wd4996> $<$:/wd4996> + + $<$:/Zc:inline> + $<$:/Zc:__cplusplus> + $<$:/Zc:preprocessor> + $<$:/Zc:wchar_t> + + $<$:/FD> ) +# Add common libraries to PHP Windows core DLL library and shared extensions. +add_library(php_windows_common_libs INTERFACE IMPORTED GLOBAL) target_link_libraries( - php_config + php_windows_common_libs INTERFACE advapi32 bcrypt @@ -127,9 +172,14 @@ target_link_libraries( user32 ws2_32 ) +target_link_libraries( + php_config + INTERFACE + $<$>,$,MODULE_LIBRARY;SHARED_LIBRARY>>:php_windows_common_libs> +) +target_link_libraries(php_windows PRIVATE php_windows_common_libs) -target_link_libraries(php_sapi INTERFACE PHP::windows) -target_sources(php_sapi INTERFACE $) +target_link_libraries(php_core INTERFACE PHP::windows) ################################################################################ # Generate wsyslog.h file with message compiler (mc).