Skip to content

Commit 7e5ed0c

Browse files
committed
Fix shared extensions on Windows
This now enables building shared extensions also on Windows.
1 parent 82a09d9 commit 7e5ed0c

File tree

23 files changed

+666
-73
lines changed

23 files changed

+666
-73
lines changed

cmake/CMakeLists.txt

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,35 @@ target_include_directories(
5656
${PHP_SOURCE_DIR}
5757
)
5858

59-
# Interface library that ties objects and configuration together for PHP SAPIs.
60-
add_library(php_sapi INTERFACE)
61-
add_library(PHP::sapi ALIAS php_sapi)
62-
target_link_libraries(php_sapi INTERFACE PHP::config)
59+
# Create PHP core library that ties objects and configuration together for PHP
60+
# SAPIs and shared extensions. On Windows there is also a standalone shared DLL
61+
# created for shared extensions which need it linked to have symbols available.
62+
add_library(php_core INTERFACE)
63+
add_library(PHP::core ALIAS php_core)
64+
65+
add_library(php_core_objects INTERFACE)
66+
add_library(PHP::core::objects ALIAS php_core_objects)
67+
68+
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
69+
add_library(php_core_library SHARED)
70+
add_library(PHP::core::library ALIAS php_core_library)
71+
target_link_libraries(
72+
php_core_library
73+
PRIVATE
74+
PHP::config
75+
PHP::core::objects
76+
)
77+
target_compile_options(
78+
php_core_library
79+
PRIVATE
80+
/nodefaultlib:libcmt
81+
/d2:-AllowCompatibleILVersions
82+
)
83+
84+
target_link_libraries(php_core INTERFACE PHP::config PHP::core::library)
85+
else()
86+
target_link_libraries(php_core INTERFACE PHP::config PHP::core::objects)
87+
endif()
6388

6489
################################################################################
6590
# Configure project.

cmake/Zend/CMakeLists.txt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ target_compile_definitions(
318318
PRIVATE
319319
ZEND_ENABLE_STATIC_TSRMLS_CACHE
320320
PUBLIC
321-
$<$<PLATFORM_ID:Windows>:LIBZEND_EXPORTS>
321+
$<$<AND:$<PLATFORM_ID:Windows>,$<IN_LIST:$<TARGET_PROPERTY:TYPE>,OBJECT_LIBRARY;STATIC_LIBRARY>>:LIBZEND_EXPORTS>
322322
)
323323

324324
set_target_properties(
@@ -334,8 +334,8 @@ set_target_properties(
334334
################################################################################
335335

336336
target_link_libraries(php_config INTERFACE $<COMPILE_ONLY:Zend::Zend>)
337-
target_link_libraries(php_sapi INTERFACE Zend::Zend)
338-
target_sources(php_sapi INTERFACE $<TARGET_OBJECTS:Zend::Zend>)
337+
target_link_libraries(php_core_objects INTERFACE Zend::Zend)
338+
target_sources(php_core_objects INTERFACE $<TARGET_OBJECTS:Zend::Zend>)
339339

340340
################################################################################
341341
# TSRM (Thread Safe Resource Manager) is a separate directory in php-src as it
@@ -364,7 +364,11 @@ target_include_directories(
364364
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PHP_INCLUDE_PREFIX}/TSRM>
365365
)
366366

367-
target_compile_definitions(zend PUBLIC $<$<PLATFORM_ID:Windows>:TSRM_EXPORTS>)
367+
target_compile_definitions(
368+
zend
369+
PUBLIC
370+
$<$<AND:$<PLATFORM_ID:Windows>,$<IN_LIST:$<TARGET_PROPERTY:TYPE>,OBJECT_LIBRARY;STATIC_LIBRARY>>:TSRM_EXPORTS>
371+
)
368372

369373
install(
370374
TARGETS zend

cmake/cmake/ConfigureChecks.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ if(PHP_DTRACE)
854854
)
855855

856856
target_link_libraries(php_config INTERFACE DTrace::DTrace)
857-
target_link_libraries(php_sapi INTERFACE php_dtrace)
857+
target_link_libraries(php_core_objects INTERFACE php_dtrace)
858858

859859
set(HAVE_DTRACE TRUE)
860860
endif()

cmake/cmake/modules/PHP/Extensions.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,14 @@ function(php_extensions_postconfigure extension)
431431
set_property(TARGET php_ext_${extension} PROPERTY OUTPUT_NAME ${extension})
432432
endif()
433433

434+
# Set target output filename prefix "[<prefix>]<extension>".
435+
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
436+
get_target_property(prefix php_ext_${extension} PREFIX)
437+
if(NOT prefix)
438+
set_property(TARGET php_ext_${extension} PROPERTY PREFIX "php_")
439+
endif()
440+
endif()
441+
434442
# Specify extension's default installation rules.
435443
get_target_property(sets php_ext_${extension} INTERFACE_HEADER_SETS)
436444
set(fileSets "")

0 commit comments

Comments
 (0)