Skip to content

Commit 7265f03

Browse files
committed
Fix shared extensions on Windows
This now enables building shared extensions also on Windows. - Added PHP_CORE target property.
1 parent a2a639d commit 7265f03

File tree

22 files changed

+149
-61
lines changed

22 files changed

+149
-61
lines changed

cmake/CMakeLists.txt

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,24 @@ target_include_directories(
5757
${PHP_SOURCE_DIR}
5858
)
5959

60-
# Interface library that ties objects and configuration together for PHP SAPIs.
61-
add_library(php_sapi INTERFACE)
62-
add_library(PHP::sapi ALIAS php_sapi)
63-
target_link_libraries(php_sapi INTERFACE PHP::config)
60+
# Create PHP core library that ties objects and configuration together for PHP
61+
# SAPIs and shared extensions. On Windows (win32 directory) there is also a
62+
# shared DLL created for shared extensions to have symbols available.
63+
add_library(php_core INTERFACE)
64+
add_library(PHP::core ALIAS php_core)
65+
66+
add_library(php_core_objects INTERFACE)
67+
add_library(PHP::core::objects ALIAS php_core_objects)
68+
target_link_libraries(
69+
php_core
70+
INTERFACE
71+
PHP::config
72+
$<$<NOT:$<PLATFORM_ID:Windows>>:PHP::core::objects>
73+
)
74+
75+
target_compile_definitions(
76+
php_config INTERFACE
77+
)
6478

6579
################################################################################
6680
# Configure project.
@@ -78,6 +92,14 @@ define_property(
7892
BRIEF_DOCS "Whether the PHP SAPI is FastCGI-based"
7993
)
8094

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

@@ -124,6 +146,7 @@ include(cmake/ConfigureChecks.cmake)
124146
# Check compilation options.
125147
include(cmake/Flags.cmake)
126148

149+
add_subdirectory(win32)
127150
add_subdirectory(sapi)
128151
add_subdirectory(ext)
129152
add_subdirectory(Zend)
@@ -135,7 +158,6 @@ message(STATUS "===============")
135158
message(STATUS "")
136159

137160
add_subdirectory(pear)
138-
add_subdirectory(win32)
139161
add_subdirectory(main)
140162
add_subdirectory(scripts)
141163

cmake/Zend/CMakeLists.txt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ target_compile_definitions(
335335
PRIVATE
336336
ZEND_ENABLE_STATIC_TSRMLS_CACHE
337337
PUBLIC
338-
$<$<PLATFORM_ID:Windows>:LIBZEND_EXPORTS>
338+
$<$<AND:$<PLATFORM_ID:Windows>,$<BOOL:$<TARGET_PROPERTY:PHP_CORE>>>:LIBZEND_EXPORTS>
339339
)
340340

341341
set_target_properties(
@@ -344,15 +344,16 @@ set_target_properties(
344344
VERSION ${PHP_ZEND_VERSION}
345345
ZEND_EXTENSION_API_NO ${PHP_ZEND_VERSION_EXTENSION_API_NO}
346346
ZEND_MODULE_API_NO ${PHP_ZEND_VERSION_MODULE_API_NO}
347+
PHP_CORE TRUE
347348
)
348349

349350
################################################################################
350351
# Add usage requirements to PHP interface targets.
351352
################################################################################
352353

353354
target_link_libraries(php_config INTERFACE $<COMPILE_ONLY:Zend::Zend>)
354-
target_link_libraries(php_sapi INTERFACE Zend::Zend)
355-
target_sources(php_sapi INTERFACE $<TARGET_OBJECTS:Zend::Zend>)
355+
target_link_libraries(php_core_objects INTERFACE Zend::Zend)
356+
target_sources(php_core_objects INTERFACE $<TARGET_OBJECTS:Zend::Zend>)
356357

357358
################################################################################
358359
# TSRM (Thread Safe Resource Manager) is a separate directory in php-src as it
@@ -381,7 +382,11 @@ target_include_directories(
381382
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PHP_INCLUDE_PREFIX}/TSRM>
382383
)
383384

384-
target_compile_definitions(zend PUBLIC $<$<PLATFORM_ID:Windows>:TSRM_EXPORTS>)
385+
target_compile_definitions(
386+
zend
387+
PUBLIC
388+
$<$<AND:$<PLATFORM_ID:Windows>,$<BOOL:$<TARGET_PROPERTY:PHP_CORE>>>:TSRM_EXPORTS>
389+
)
385390

386391
install(
387392
TARGETS zend

cmake/cmake/ConfigureChecks.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1061,9 +1061,10 @@ if(PHP_DTRACE)
10611061
INCLUDES
10621062
$<TARGET_PROPERTY:PHP::config,INTERFACE_INCLUDE_DIRECTORIES>
10631063
)
1064+
set_target_properties(php_dtrace PROPERTIES PHP_CORE TRUE)
10641065

10651066
target_link_libraries(php_config INTERFACE DTrace::DTrace)
1066-
target_link_libraries(php_sapi INTERFACE php_dtrace)
1067+
target_link_libraries(php_core_objects INTERFACE php_dtrace)
10671068

10681069
set(HAVE_DTRACE TRUE)
10691070
endif()

cmake/cmake/Extensions.cmake

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

418+
# Set target output filename prefix "[<prefix>]<extension>".
419+
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
420+
get_target_property(prefix php_ext_${extension} PREFIX)
421+
if(NOT prefix)
422+
set_property(TARGET php_ext_${extension} PROPERTY PREFIX "php_")
423+
endif()
424+
endif()
425+
418426
# Specify extension's default installation rules.
419427
get_target_property(sets php_ext_${extension} INTERFACE_HEADER_SETS)
420428
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
@@ -73,12 +73,8 @@ target_sources(
7373
)
7474

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

8480
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
@@ -202,8 +202,8 @@ else()
202202
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
203203
set(PCRE2_STATIC TRUE)
204204

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

cmake/ext/standard/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ set_target_properties(
484484
PROPERTIES
485485
INCLUDE_DIRECTORIES $<TARGET_PROPERTY:php_ext_standard,INCLUDE_DIRECTORIES>
486486
COMPILE_DEFINITIONS $<TARGET_PROPERTY:php_ext_standard,COMPILE_DEFINITIONS>
487+
PHP_CORE TRUE
487488
)
488489

489490
target_compile_definitions(

cmake/ext/tidy/CMakeLists.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,8 @@ target_sources(
7070
)
7171

7272
get_target_property(type php_ext_tidy TYPE)
73-
if(
74-
CMAKE_SYSTEM_NAME STREQUAL "Windows"
75-
AND TARGET php_sapi
76-
AND NOT type MATCHES "^(MODULE|SHARED)_LIBRARY$"
77-
)
78-
target_sources(php_sapi INTERFACE php_tidy.def)
73+
if(TARGET php_windows AND type MATCHES "^(OBJECT|STATIC)_LIBRARY$")
74+
target_sources(php_windows PRIVATE php_tidy.def)
7975
endif()
8076

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

0 commit comments

Comments
 (0)