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 5 commits 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>,$<IN_LIST:$<TARGET_PROPERTY:TYPE>,OBJECT_LIBRARY;STATIC_LIBRARY>>: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>,$<IN_LIST:$<TARGET_PROPERTY:TYPE>,OBJECT_LIBRARY;STATIC_LIBRARY>>: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 @@ -847,9 +847,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 @@ -431,6 +431,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
Loading
Loading