Skip to content

Fix shared extensions on Windows #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: PHP-8.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
$<$<NOT:$<PLATFORM_ID:Windows>>:PHP::core::objects>
)

target_compile_definitions(
php_config INTERFACE
)

################################################################################
# Configure project.
Expand All @@ -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)

Expand All @@ -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)
Expand All @@ -112,7 +135,6 @@ message(STATUS "===============")
message(STATUS "")

add_subdirectory(pear)
add_subdirectory(win32)
add_subdirectory(main)
add_subdirectory(scripts)

Expand Down
13 changes: 9 additions & 4 deletions cmake/Zend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ target_compile_definitions(
PRIVATE
ZEND_ENABLE_STATIC_TSRMLS_CACHE
PUBLIC
$<$<PLATFORM_ID:Windows>:LIBZEND_EXPORTS>
$<$<AND:$<PLATFORM_ID:Windows>,$<BOOL:$<TARGET_PROPERTY:PHP_CORE>>>:LIBZEND_EXPORTS>
)

set_target_properties(
Expand All @@ -327,15 +327,16 @@ 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
)

################################################################################
# Add usage requirements to PHP interface targets.
################################################################################

target_link_libraries(php_config INTERFACE $<COMPILE_ONLY:Zend::Zend>)
target_link_libraries(php_sapi INTERFACE Zend::Zend)
target_sources(php_sapi INTERFACE $<TARGET_OBJECTS:Zend::Zend>)
target_link_libraries(php_core_objects INTERFACE Zend::Zend)
target_sources(php_core_objects INTERFACE $<TARGET_OBJECTS:Zend::Zend>)

################################################################################
# TSRM (Thread Safe Resource Manager) is a separate directory in php-src as it
Expand Down Expand Up @@ -364,7 +365,11 @@ target_include_directories(
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PHP_INCLUDE_PREFIX}/TSRM>
)

target_compile_definitions(zend PUBLIC $<$<PLATFORM_ID:Windows>:TSRM_EXPORTS>)
target_compile_definitions(
zend
PUBLIC
$<$<AND:$<PLATFORM_ID:Windows>,$<BOOL:$<TARGET_PROPERTY:PHP_CORE>>>:TSRM_EXPORTS>
)

install(
TARGETS zend
Expand Down
3 changes: 2 additions & 1 deletion cmake/cmake/ConfigureChecks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -888,9 +888,10 @@ if(PHP_DTRACE)
INCLUDES
$<TARGET_PROPERTY:PHP::config,INTERFACE_INCLUDE_DIRECTORIES>
)
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()
Expand Down
8 changes: 8 additions & 0 deletions cmake/cmake/modules/PHP/Extensions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 "[<prefix>]<extension>".
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 "")
Expand Down
11 changes: 11 additions & 0 deletions cmake/cmake/presets/windows.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,36 @@
"binaryDir": "${sourceDir}/php-build/windows",
"installDir": "C:/temp",
"cacheVariables": {
"PHP_EXT_BCMATH": true,
"PHP_EXT_CALENDAR": true,
"PHP_EXT_COM_DOTNET": true,
"PHP_EXT_CTYPE": true,
"PHP_EXT_DL_TEST": true,
"PHP_EXT_DOM": false,
"PHP_EXT_FILEINFO": true,
"PHP_EXT_FILTER": true,
"PHP_EXT_FTP": true,
"PHP_EXT_FTP_SSL": false,
"PHP_EXT_ICONV": false,
"PHP_EXT_LIBXML": false,
"PHP_EXT_MBSTRING": false,
"PHP_EXT_MBSTRING_MBREGEX": false,
"PHP_EXT_OPCACHE": true,
"PHP_EXT_PDO": true,
"PHP_EXT_PDO_SQLITE": false,
"PHP_EXT_PHAR": false,
"PHP_EXT_POSIX": false,
"PHP_EXT_SESSION": true,
"PHP_EXT_SHMOP": true,
"PHP_EXT_SIMPLEXML": false,
"PHP_EXT_SOCKETS": true,
"PHP_EXT_SQLITE3": false,
"PHP_EXT_SYSVSHM": true,
"PHP_EXT_TOKENIZER": true,
"PHP_EXT_XML": false,
"PHP_EXT_XMLREADER": false,
"PHP_EXT_XMLWRITER": false,
"PHP_EXT_ZEND_TEST": true,

"PHP_SAPI_CGI": true,
"PHP_SAPI_PHPDBG": true,
Expand Down
13 changes: 10 additions & 3 deletions cmake/ext/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<$<PLATFORM_ID:Windows>:$<TARGET_NAME_IF_EXISTS:PHP::core>>
)
else()
set_target_properties(php_ext_${extension} PROPERTIES PHP_CORE TRUE)

target_compile_definitions(
php_config
INTERFACE
Expand All @@ -102,13 +109,13 @@ foreach(extension IN LISTS extensions)
)

target_link_libraries(
php_sapi
php_core_objects
INTERFACE
$<IF:$<BOOL:$<TARGET_GENEX_EVAL:PHP::ext::${extension},$<TARGET_PROPERTY:PHP::ext::${extension},PHP_CLI>>>,$<$<BOOL:$<TARGET_PROPERTY:PHP_CLI>>:PHP::ext::${extension}>,PHP::ext::${extension}>
)

target_sources(
php_sapi
php_core_objects
INTERFACE
$<IF:$<BOOL:$<TARGET_GENEX_EVAL:PHP::ext::${extension},$<TARGET_PROPERTY:PHP::ext::${extension},PHP_CLI>>>,$<$<BOOL:$<TARGET_PROPERTY:PHP_CLI>>:$<TARGET_OBJECTS:PHP::ext::${extension}>>,$<TARGET_OBJECTS:PHP::ext::${extension}>>
)
Expand Down
8 changes: 2 additions & 6 deletions cmake/ext/iconv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions cmake/ext/libxml/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions cmake/ext/pcre/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
1 change: 1 addition & 0 deletions cmake/ext/standard/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ set_target_properties(
INCLUDE_DIRECTORIES $<TARGET_PROPERTY:php_ext_standard,INCLUDE_DIRECTORIES>
COMPILE_DEFINITIONS $<TARGET_PROPERTY:php_ext_standard,COMPILE_DEFINITIONS>
LINK_LIBRARIES $<TARGET_PROPERTY:php_ext_standard,LINK_LIBRARIES>
PHP_CORE TRUE
)

target_compile_definitions(
Expand Down
8 changes: 2 additions & 6 deletions cmake/ext/tidy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions cmake/ext/zlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 12 additions & 5 deletions cmake/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,16 @@ target_sources(
$<$<NOT:$<PLATFORM_ID:Windows>>:${PHP_BINARY_DIR}/$<CONFIG>/main/php_config.h>
)

set_target_properties(php_main PROPERTIES PHP_CORE TRUE)

################################################################################
# Add usage requirements to PHP interface targets.
################################################################################

target_compile_definitions(
php_config
INTERFACE
$<$<PLATFORM_ID:Windows>:SAPI_EXPORTS>
$<$<AND:$<PLATFORM_ID:Windows>,$<BOOL:$<TARGET_PROPERTY:PHP_CORE>>>:SAPI_EXPORTS>
)

target_include_directories(
Expand All @@ -123,16 +125,16 @@ target_include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
)

target_link_libraries(php_sapi INTERFACE PHP::main)
target_sources(php_sapi INTERFACE $<TARGET_OBJECTS:PHP::main>)
target_link_libraries(php_core_objects INTERFACE PHP::main)
target_sources(php_core_objects INTERFACE $<TARGET_OBJECTS:PHP::main>)

################################################################################
# Add FastCGI target with objects for use in PHP SAPIs such as CGI and FPM.
################################################################################
add_library(php_main_fastcgi OBJECT fastcgi.c)

target_sources(
php_sapi
php_core
INTERFACE
$<$<BOOL:$<TARGET_PROPERTY:PHP_SAPI_FASTCGI>>:$<TARGET_OBJECTS:php_main_fastcgi>>
)
Expand All @@ -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
$<IF:$<BOOL:$<TARGET_PROPERTY:PHP_CLI>>,$<TARGET_OBJECTS:php_main_internal_functions_cli>,$<TARGET_OBJECTS:php_main_internal_functions>>
)
Expand Down
2 changes: 2 additions & 0 deletions cmake/sapi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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" "")
Expand Down
2 changes: 1 addition & 1 deletion cmake/sapi/apache2handler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ set_package_properties(
target_link_libraries(
php_sapi_apache2handler
PRIVATE
$<BUILD_INTERFACE:PHP::sapi>
$<BUILD_INTERFACE:PHP::core>
Apache::Apache
)

Expand Down
3 changes: 1 addition & 2 deletions cmake/sapi/cgi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ target_compile_definitions(php_sapi_cgi PRIVATE ZEND_ENABLE_STATIC_TSRMLS_CACHE)
target_link_libraries(
php_sapi_cgi
PRIVATE
$<BUILD_INTERFACE:PHP::sapi>
$<BUILD_INTERFACE:PHP::core>
$<$<PLATFORM_ID:Windows>:ws2_32;kernel32;advapi32>
)

Expand All @@ -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
)
Expand Down
5 changes: 2 additions & 3 deletions cmake/sapi/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ target_compile_definitions(
target_link_libraries(
php_sapi_cli
PRIVATE
$<BUILD_INTERFACE:PHP::sapi>
$<BUILD_INTERFACE:PHP::core>
$<$<PLATFORM_ID:Windows>:ws2_32;shell32>
)

Expand All @@ -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
)

Expand Down Expand Up @@ -182,7 +181,7 @@ if(PHP_SAPI_CLI_WIN_NO_CONSOLE)
target_link_libraries(
php_sapi_cli_win
PRIVATE
$<BUILD_INTERFACE:PHP::sapi>
$<BUILD_INTERFACE:PHP::core>
shell32
)

Expand Down
Loading
Loading