diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index b638bb4d..d8c187fb 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 e34bae37..9d6dc9dc 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/Extensions.cmake b/cmake/cmake/Extensions.cmake index a36046b2..96f4b3fc 100644 --- a/cmake/cmake/Extensions.cmake +++ b/cmake/cmake/Extensions.cmake @@ -413,6 +413,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(file_sets "") diff --git a/cmake/ext/CMakeLists.txt b/cmake/ext/CMakeLists.txt index 8b1105bd..997e7f75 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 9c65d757..8d90f662 100644 --- a/cmake/ext/iconv/CMakeLists.txt +++ b/cmake/ext/iconv/CMakeLists.txt @@ -73,12 +73,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 4f1de0d9..54a98da4 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 3f2bfd9d..3e216eb6 100644 --- a/cmake/ext/pcre/CMakeLists.txt +++ b/cmake/ext/pcre/CMakeLists.txt @@ -202,8 +202,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 67865517..d96e1030 100644 --- a/cmake/ext/standard/CMakeLists.txt +++ b/cmake/ext/standard/CMakeLists.txt @@ -484,6 +484,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 a3a8bd12..42071cf0 100644 --- a/cmake/ext/tidy/CMakeLists.txt +++ b/cmake/ext/tidy/CMakeLists.txt @@ -70,12 +70,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 00624e88..e112be28 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 dd30d4c8..30221c92 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 000a2bbc..b367f959 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 14219fea..7ec69bf0 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 727f5729..b12284e0 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> ) @@ -191,7 +191,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 83159252..5c4adfd0 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 0af33b12..768d9382 100644 --- a/cmake/sapi/fpm/CMakeLists.txt +++ b/cmake/sapi/fpm/CMakeLists.txt @@ -232,7 +232,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 5c2a930f..57ea40ac 100644 --- a/cmake/sapi/fuzzer/CMakeLists.txt +++ b/cmake/sapi/fuzzer/CMakeLists.txt @@ -140,7 +140,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 10085715..f6467104 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 8135e0db..5c35c0d2 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 ed76ef3f..1530354d 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).