diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index e95baf09..51ee2400 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -57,10 +57,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. @@ -78,6 +92,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) @@ -124,6 +146,7 @@ include(cmake/ConfigureChecks.cmake) # Check compilation options. include(cmake/Flags.cmake) +add_subdirectory(win32) add_subdirectory(sapi) add_subdirectory(ext) add_subdirectory(Zend) @@ -135,7 +158,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 44b32ef7..6a31a122 100644 --- a/cmake/Zend/CMakeLists.txt +++ b/cmake/Zend/CMakeLists.txt @@ -335,7 +335,7 @@ target_compile_definitions( PRIVATE ZEND_ENABLE_STATIC_TSRMLS_CACHE PUBLIC - $<$:LIBZEND_EXPORTS> + $<$,$>>:LIBZEND_EXPORTS> ) set_target_properties( @@ -344,6 +344,7 @@ set_target_properties( VERSION ${PHP_ZEND_VERSION} PHP_ZEND_EXTENSION_API_NO ${PHP_ZEND_VERSION_EXTENSION_API_NO} PHP_ZEND_MODULE_API_NO ${PHP_ZEND_VERSION_MODULE_API_NO} + PHP_CORE TRUE ) ################################################################################ @@ -351,8 +352,8 @@ set_target_properties( ################################################################################ target_link_libraries(php_config INTERFACE $) -target_link_libraries(php_sapi INTERFACE PHP::Zend) -target_sources(php_sapi INTERFACE $) +target_link_libraries(php_core_objects INTERFACE PHP::Zend) +target_sources(php_core_objects INTERFACE $) ################################################################################ # TSRM (Thread Safe Resource Manager) is a separate directory in php-src as it @@ -383,7 +384,8 @@ target_include_directories( target_compile_definitions( php_zend - PUBLIC $<$:TSRM_EXPORTS> + PUBLIC + $<$,$>>:TSRM_EXPORTS> ) install( diff --git a/cmake/cmake/ConfigureChecks.cmake b/cmake/cmake/ConfigureChecks.cmake index b2785769..5ebc95dc 100644 --- a/cmake/cmake/ConfigureChecks.cmake +++ b/cmake/cmake/ConfigureChecks.cmake @@ -1063,9 +1063,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/Extension.cmake b/cmake/cmake/modules/PHP/Extension.cmake index 888525b5..5d7fbda9 100644 --- a/cmake/cmake/modules/PHP/Extension.cmake +++ b/cmake/cmake/modules/PHP/Extension.cmake @@ -64,9 +64,14 @@ function(_php_extension_post_configure) set_property(TARGET php_ext_${extension} PROPERTY OUTPUT_NAME ${extension}) endif() + # Set target output filename prefix "[]". get_target_property(prefix php_ext_${extension} PREFIX) if(NOT prefix) - set_property(TARGET php_ext_${extension} PROPERTY PREFIX "") + if(CMAKE_SYSTEM_NAME STREQUAL "Windows") + set_property(TARGET php_ext_${extension} PROPERTY PREFIX "php_") + else() + set_property(TARGET php_ext_${extension} PROPERTY PREFIX "") + endif() endif() ############################################################################## diff --git a/cmake/ext/CMakeLists.txt b/cmake/ext/CMakeLists.txt index 9a0d9bf6..3d26e31c 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 d546df23..bbec2c9a 100644 --- a/cmake/ext/iconv/CMakeLists.txt +++ b/cmake/ext/iconv/CMakeLists.txt @@ -78,12 +78,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 3f0575fc..200c5413 100644 --- a/cmake/ext/libxml/CMakeLists.txt +++ b/cmake/ext/libxml/CMakeLists.txt @@ -58,8 +58,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 b30d7713..e5edb198 100644 --- a/cmake/ext/pcre/CMakeLists.txt +++ b/cmake/ext/pcre/CMakeLists.txt @@ -213,8 +213,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 b8ab1f65..da5b3fbc 100644 --- a/cmake/ext/standard/CMakeLists.txt +++ b/cmake/ext/standard/CMakeLists.txt @@ -495,6 +495,7 @@ set_target_properties( PROPERTIES INCLUDE_DIRECTORIES $ COMPILE_DEFINITIONS $ + PHP_CORE TRUE ) target_compile_definitions( diff --git a/cmake/ext/tidy/CMakeLists.txt b/cmake/ext/tidy/CMakeLists.txt index 8ca72b44..e252c4aa 100644 --- a/cmake/ext/tidy/CMakeLists.txt +++ b/cmake/ext/tidy/CMakeLists.txt @@ -75,12 +75,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 7bbcdad7..f906eb8c 100644 --- a/cmake/ext/zlib/CMakeLists.txt +++ b/cmake/ext/zlib/CMakeLists.txt @@ -72,12 +72,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 06bd0e37..da935579 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. @@ -133,7 +135,7 @@ add_library(php_main_fastcgi OBJECT fastcgi.c) add_dependencies(php_main_fastcgi php_main) target_sources( - php_sapi + php_core INTERFACE $<$>:$> ) @@ -148,8 +150,14 @@ add_library(php_main_internal_functions_cli OBJECT internal_functions_cli.c) add_dependencies(php_main_internal_functions php_main) add_dependencies(php_main_internal_functions_cli php_main) +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/apache2handler/CMakeLists.txt b/cmake/sapi/apache2handler/CMakeLists.txt index 7a15016c..e07a661d 100644 --- a/cmake/sapi/apache2handler/CMakeLists.txt +++ b/cmake/sapi/apache2handler/CMakeLists.txt @@ -119,7 +119,7 @@ endif() target_link_libraries( php_sapi_apache2handler PRIVATE - $ + $ Apache::Apache ) diff --git a/cmake/sapi/cgi/CMakeLists.txt b/cmake/sapi/cgi/CMakeLists.txt index 8c46a3e6..1ad1eaea 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> ) diff --git a/cmake/sapi/cli/CMakeLists.txt b/cmake/sapi/cli/CMakeLists.txt index 4eb99c5c..475b24fb 100644 --- a/cmake/sapi/cli/CMakeLists.txt +++ b/cmake/sapi/cli/CMakeLists.txt @@ -120,7 +120,7 @@ target_compile_definitions( target_link_libraries( php_sapi_cli PRIVATE - $ + $ $<$:ws2_32;shell32> ) @@ -205,7 +205,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 201b39c2..be57e341 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) diff --git a/cmake/sapi/fpm/CMakeLists.txt b/cmake/sapi/fpm/CMakeLists.txt index ab41cfab..94137ed8 100644 --- a/cmake/sapi/fpm/CMakeLists.txt +++ b/cmake/sapi/fpm/CMakeLists.txt @@ -224,7 +224,7 @@ target_compile_definitions(php_sapi_fpm PRIVATE ZEND_ENABLE_STATIC_TSRMLS_CACHE) target_link_libraries( php_sapi_fpm PRIVATE - $ + $ ) set_target_properties( diff --git a/cmake/sapi/fuzzer/CMakeLists.txt b/cmake/sapi/fuzzer/CMakeLists.txt index e8ae662f..2651584d 100644 --- a/cmake/sapi/fuzzer/CMakeLists.txt +++ b/cmake/sapi/fuzzer/CMakeLists.txt @@ -141,7 +141,7 @@ set_target_properties( target_link_libraries( php_sapi_fuzzer PRIVATE - $ + $ ) install( diff --git a/cmake/sapi/litespeed/CMakeLists.txt b/cmake/sapi/litespeed/CMakeLists.txt index e1a669f8..3ef68285 100644 --- a/cmake/sapi/litespeed/CMakeLists.txt +++ b/cmake/sapi/litespeed/CMakeLists.txt @@ -46,7 +46,7 @@ target_sources( target_link_libraries( php_sapi_litespeed PRIVATE - $ + $ ) set_target_properties( diff --git a/cmake/sapi/phpdbg/CMakeLists.txt b/cmake/sapi/phpdbg/CMakeLists.txt index a34e4cfb..254c0d1c 100644 --- a/cmake/sapi/phpdbg/CMakeLists.txt +++ b/cmake/sapi/phpdbg/CMakeLists.txt @@ -155,7 +155,7 @@ foreach(target IN ITEMS php_sapi_phpdbg php_sapi_phpdbg_shared) target_link_libraries( ${target} PRIVATE - $ + $ $<$:ws2_32;user32> ) diff --git a/cmake/win32/CMakeLists.txt b/cmake/win32/CMakeLists.txt index e875b32a..b7dd2d8f 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,20 @@ 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 @@ -128,8 +174,16 @@ target_link_libraries( ws2_32 ) -target_link_libraries(php_sapi INTERFACE PHP::windows) -target_sources(php_sapi INTERFACE $) +target_link_libraries( + php_extension + INTERFACE + $ + $,MODULE_LIBRARY;SHARED_LIBRARY>:php_windows_common_libs>> +) + +target_link_libraries(php_windows PRIVATE php_windows_common_libs) + +target_link_libraries(php_core INTERFACE PHP::windows) ################################################################################ # Generate wsyslog.h file with message compiler (mc).