Skip to content

Commit 2a3c98c

Browse files
committed
Fix shared extensions on Windows
This now enables building shared extensions also on Windows. - Added PHP_CORE target property.
1 parent ff81b54 commit 2a3c98c

File tree

22 files changed

+146
-61
lines changed

22 files changed

+146
-61
lines changed

cmake/CMakeLists.txt

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,24 @@ 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 (win32 directory) there is also a
61+
# shared DLL created for shared extensions 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+
target_link_libraries(
68+
php_core
69+
INTERFACE
70+
PHP::config
71+
$<$<NOT:$<PLATFORM_ID:Windows>>:PHP::core::objects>
72+
)
73+
74+
target_compile_definitions(
75+
php_config INTERFACE
76+
)
6377

6478
################################################################################
6579
# Configure project.
@@ -77,6 +91,14 @@ define_property(
7791
BRIEF_DOCS "Whether the PHP SAPI is FastCGI-based"
7892
)
7993

94+
define_property(
95+
TARGET
96+
PROPERTY PHP_CORE
97+
BRIEF_DOCS
98+
"Whether the target should get compile properties dedicated to PHP core "
99+
"objects (e.g, *_EXPORTS compile definitions, etc.)."
100+
)
101+
80102
# Check whether IPO/LTO can be enabled.
81103
include(PHP/Optimization)
82104

@@ -101,6 +123,7 @@ include(cmake/ConfigureChecks.cmake)
101123
# Check compilation options.
102124
include(cmake/Flags.cmake)
103125

126+
add_subdirectory(win32)
104127
add_subdirectory(sapi)
105128
add_subdirectory(ext)
106129
add_subdirectory(Zend)
@@ -112,7 +135,6 @@ message(STATUS "===============")
112135
message(STATUS "")
113136

114137
add_subdirectory(pear)
115-
add_subdirectory(win32)
116138
add_subdirectory(main)
117139
add_subdirectory(scripts)
118140

cmake/Zend/CMakeLists.txt

Lines changed: 9 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>,$<BOOL:$<TARGET_PROPERTY:PHP_CORE>>>:LIBZEND_EXPORTS>
322322
)
323323

324324
set_target_properties(
@@ -327,15 +327,16 @@ set_target_properties(
327327
VERSION ${Zend_VERSION}
328328
ZEND_EXTENSION_API_NO ${Zend_VERSION_EXTENSION_API_NO}
329329
ZEND_MODULE_API_NO ${Zend_VERSION_MODULE_API_NO}
330+
PHP_CORE TRUE
330331
)
331332

332333
################################################################################
333334
# Add usage requirements to PHP interface targets.
334335
################################################################################
335336

336337
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>)
338+
target_link_libraries(php_core_objects INTERFACE Zend::Zend)
339+
target_sources(php_core_objects INTERFACE $<TARGET_OBJECTS:Zend::Zend>)
339340

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

367-
target_compile_definitions(zend PUBLIC $<$<PLATFORM_ID:Windows>:TSRM_EXPORTS>)
368+
target_compile_definitions(
369+
zend
370+
PUBLIC
371+
$<$<AND:$<PLATFORM_ID:Windows>,$<BOOL:$<TARGET_PROPERTY:PHP_CORE>>>:TSRM_EXPORTS>
372+
)
368373

369374
install(
370375
TARGETS zend

cmake/cmake/ConfigureChecks.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,9 +887,10 @@ if(PHP_DTRACE)
887887
INCLUDES
888888
$<TARGET_PROPERTY:PHP::config,INTERFACE_INCLUDE_DIRECTORIES>
889889
)
890+
set_target_properties(php_dtrace PROPERTIES PHP_CORE TRUE)
890891

891892
target_link_libraries(php_config INTERFACE DTrace::DTrace)
892-
target_link_libraries(php_sapi INTERFACE php_dtrace)
893+
target_link_libraries(php_core_objects INTERFACE php_dtrace)
893894

894895
set(HAVE_DTRACE TRUE)
895896
endif()

cmake/cmake/modules/PHP/Extensions.cmake

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

447+
# Set target output filename prefix "[<prefix>]<extension>".
448+
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
449+
get_target_property(prefix php_ext_${extension} PREFIX)
450+
if(NOT prefix)
451+
set_property(TARGET php_ext_${extension} PROPERTY PREFIX "php_")
452+
endif()
453+
endif()
454+
447455
# Specify extension's default installation rules.
448456
get_target_property(sets php_ext_${extension} INTERFACE_HEADER_SETS)
449457
set(fileSets "")

cmake/ext/CMakeLists.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,14 @@ foreach(extension IN LISTS extensions)
7575
# Add usage requirements to PHP interface targets.
7676
# TODO: Should PHP_CLI extensions pass properties only to PHP_CLI SAPIs?
7777
get_target_property(type PHP::ext::${extension} TYPE)
78-
if(NOT type MATCHES "^(MODULE|SHARED)_LIBRARY$")
78+
if(type MATCHES "^(MODULE|SHARED)_LIBRARY$")
79+
target_link_libraries(
80+
php_ext_${extension}
81+
PRIVATE $<$<PLATFORM_ID:Windows>:$<TARGET_NAME_IF_EXISTS:PHP::core>>
82+
)
83+
else()
84+
set_target_properties(php_ext_${extension} PROPERTIES PHP_CORE TRUE)
85+
7986
target_compile_definitions(
8087
php_config
8188
INTERFACE
@@ -102,13 +109,13 @@ foreach(extension IN LISTS extensions)
102109
)
103110

104111
target_link_libraries(
105-
php_sapi
112+
php_core_objects
106113
INTERFACE
107114
$<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}>
108115
)
109116

110117
target_sources(
111-
php_sapi
118+
php_core_objects
112119
INTERFACE
113120
$<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}>>
114121
)

cmake/ext/iconv/CMakeLists.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,8 @@ target_sources(
7272
)
7373

7474
get_target_property(type php_ext_iconv TYPE)
75-
if(
76-
CMAKE_SYSTEM_NAME STREQUAL "Windows"
77-
AND TARGET php_sapi
78-
AND NOT type MATCHES "^(MODULE|SHARED)_LIBRARY$"
79-
)
80-
target_sources(php_sapi INTERFACE php_iconv.def)
75+
if(TARGET php_windows AND type MATCHES "^(OBJECT|STATIC)_LIBRARY$")
76+
target_sources(php_windows PRIVATE php_iconv.def)
8177
endif()
8278

8379
target_compile_definitions(

cmake/ext/libxml/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ target_sources(
5353
php_libxml.h
5454
)
5555

56-
if(CMAKE_SYSTEM_NAME STREQUAL "Windows" AND TARGET php_sapi)
57-
target_sources(php_sapi INTERFACE php_libxml2.def)
56+
if(TARGET php_windows)
57+
target_sources(php_windows PRIVATE php_libxml2.def)
5858
endif()
5959

6060
target_compile_definitions(

cmake/ext/pcre/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ else()
203203
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
204204
set(PCRE2_STATIC TRUE)
205205

206-
if(TARGET php_sapi)
207-
target_sources(php_sapi INTERFACE php_pcre.def)
206+
if(TARGET php_windows)
207+
target_sources(php_windows PRIVATE php_pcre.def)
208208
endif()
209209
endif()
210210

cmake/ext/standard/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ set_target_properties(
481481
INCLUDE_DIRECTORIES $<TARGET_PROPERTY:php_ext_standard,INCLUDE_DIRECTORIES>
482482
COMPILE_DEFINITIONS $<TARGET_PROPERTY:php_ext_standard,COMPILE_DEFINITIONS>
483483
LINK_LIBRARIES $<TARGET_PROPERTY:php_ext_standard,LINK_LIBRARIES>
484+
PHP_CORE TRUE
484485
)
485486

486487
target_compile_definitions(

cmake/ext/tidy/CMakeLists.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,8 @@ target_sources(
6868
)
6969

7070
get_target_property(type php_ext_tidy TYPE)
71-
if(
72-
CMAKE_SYSTEM_NAME STREQUAL "Windows"
73-
AND TARGET php_sapi
74-
AND NOT type MATCHES "^(MODULE|SHARED)_LIBRARY$"
75-
)
76-
target_sources(php_sapi INTERFACE php_tidy.def)
71+
if(TARGET php_windows AND type MATCHES "^(OBJECT|STATIC)_LIBRARY$")
72+
target_sources(php_windows PRIVATE php_tidy.def)
7773
endif()
7874

7975
# Add -Wno-ignored-qualifiers as this is an issue upstream. Fixed in tidy-html5

0 commit comments

Comments
 (0)