Skip to content

Commit f6dec44

Browse files
committed
Fix shared extensions on Windows
This now enables building shared extensions also on Windows. - Added PHP_CORE target property.
1 parent 865623b commit f6dec44

20 files changed

Lines changed: 135 additions & 59 deletions

cmake/CMakeLists.txt

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,24 @@ target_include_directories(
6060
${PHP_SOURCE_DIR}
6161
)
6262

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

6882
# Interface library encapsulating the usage requirements for PHP extensions.
6983
add_library(php_extension INTERFACE)
@@ -100,6 +114,14 @@ define_property(
100114
BRIEF_DOCS "Whether the PHP SAPI is FastCGI-based"
101115
)
102116

117+
define_property(
118+
TARGET
119+
PROPERTY PHP_CORE
120+
BRIEF_DOCS
121+
"Whether the target should get compile properties dedicated to PHP core "
122+
"objects (e.g, *_EXPORTS compile definitions, etc.)."
123+
)
124+
103125
# Check whether IPO/LTO can be enabled.
104126
include(PHP/Core/Optimization)
105127

@@ -159,6 +181,7 @@ if(PHP_TESTING)
159181
php_testing_add()
160182
endif()
161183

184+
add_subdirectory(win32)
162185
add_subdirectory(sapi)
163186
add_subdirectory(ext)
164187
add_subdirectory(Zend)
@@ -170,7 +193,6 @@ message(STATUS "===============")
170193
message(STATUS "")
171194

172195
add_subdirectory(pear)
173-
add_subdirectory(win32)
174196
add_subdirectory(main)
175197
add_subdirectory(scripts)
176198

cmake/Zend/CMakeLists.txt

Lines changed: 6 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
PHP_ZEND_EXTENSION_API_NO ${PHP_ZEND_VERSION_EXTENSION_API_NO}
346346
PHP_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:PHP::Zend>)
354-
target_link_libraries(php_sapi INTERFACE PHP::Zend)
355-
target_sources(php_sapi INTERFACE $<TARGET_OBJECTS:PHP::Zend>)
355+
target_link_libraries(php_core_objects INTERFACE PHP::Zend)
356+
target_sources(php_core_objects INTERFACE $<TARGET_OBJECTS:PHP::Zend>)
356357

357358
################################################################################
358359
# TSRM (Thread Safe Resource Manager) is a separate directory in php-src as it
@@ -383,7 +384,8 @@ target_include_directories(
383384

384385
target_compile_definitions(
385386
php_zend
386-
PUBLIC $<$<PLATFORM_ID:Windows>:TSRM_EXPORTS>
387+
PUBLIC
388+
$<$<AND:$<PLATFORM_ID:Windows>,$<BOOL:$<TARGET_PROPERTY:PHP_CORE>>>:TSRM_EXPORTS>
387389
)
388390

389391
install(

cmake/cmake/ConfigureChecks.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,9 +1063,10 @@ if(PHP_DTRACE)
10631063
INCLUDES
10641064
$<TARGET_PROPERTY:PHP::config,INTERFACE_INCLUDE_DIRECTORIES>
10651065
)
1066+
set_target_properties(php_dtrace PROPERTIES PHP_CORE TRUE)
10661067

10671068
target_link_libraries(php_config INTERFACE DTrace::DTrace)
1068-
target_link_libraries(php_sapi INTERFACE php_dtrace)
1069+
target_link_libraries(php_core_objects INTERFACE php_dtrace)
10691070

10701071
set(HAVE_DTRACE TRUE)
10711072
endif()

cmake/ext/CMakeLists.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,14 @@ foreach(extension IN LISTS extensions)
8585
# Add usage requirements to PHP interface targets.
8686
# TODO: Should PHP_CLI extensions pass properties only to PHP_CLI SAPIs?
8787
get_target_property(type PHP::ext::${extension} TYPE)
88-
if(NOT type MATCHES "^(MODULE|SHARED)_LIBRARY$")
88+
if(type MATCHES "^(MODULE|SHARED)_LIBRARY$")
89+
target_link_libraries(
90+
php_ext_${extension}
91+
PRIVATE $<$<PLATFORM_ID:Windows>:$<TARGET_NAME_IF_EXISTS:PHP::core>>
92+
)
93+
else()
94+
set_target_properties(php_ext_${extension} PROPERTIES PHP_CORE TRUE)
95+
8996
target_compile_definitions(
9097
php_config
9198
INTERFACE
@@ -112,13 +119,13 @@ foreach(extension IN LISTS extensions)
112119
)
113120

114121
target_link_libraries(
115-
php_sapi
122+
php_core_objects
116123
INTERFACE
117124
$<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}>
118125
)
119126

120127
target_sources(
121-
php_sapi
128+
php_core_objects
122129
INTERFACE
123130
$<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}>>
124131
)

cmake/ext/iconv/CMakeLists.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,8 @@ target_sources(
7878
)
7979

8080
get_target_property(type php_ext_iconv TYPE)
81-
if(
82-
CMAKE_SYSTEM_NAME STREQUAL "Windows"
83-
AND TARGET php_sapi
84-
AND NOT type MATCHES "^(MODULE|SHARED)_LIBRARY$"
85-
)
86-
target_sources(php_sapi INTERFACE php_iconv.def)
81+
if(TARGET php_windows AND type MATCHES "^(OBJECT|STATIC)_LIBRARY$")
82+
target_sources(php_windows PRIVATE php_iconv.def)
8783
endif()
8884

8985
target_compile_definitions(

cmake/ext/libxml/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ target_sources(
5858
php_libxml.h
5959
)
6060

61-
if(CMAKE_SYSTEM_NAME STREQUAL "Windows" AND TARGET php_sapi)
62-
target_sources(php_sapi INTERFACE php_libxml2.def)
61+
if(TARGET php_windows)
62+
target_sources(php_windows PRIVATE php_libxml2.def)
6363
endif()
6464

6565
target_compile_definitions(

cmake/ext/pcre/CMakeLists.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,8 @@ else()
263263
set(PCRE2_STATIC TRUE)
264264

265265
get_target_property(type php_ext_pcre TYPE)
266-
if(
267-
CMAKE_SYSTEM_NAME STREQUAL "Windows"
268-
AND TARGET php_sapi
269-
AND NOT type MATCHES "^(MODULE|SHARED)_LIBRARY$"
270-
)
271-
target_sources(php_sapi INTERFACE php_pcre.def)
266+
if(TARGET php_windows AND type MATCHES "^(OBJECT|STATIC)_LIBRARY$")
267+
target_sources(php_windows PRIVATE php_pcre.def)
272268
endif()
273269
endif()
274270

cmake/ext/standard/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ set_target_properties(
496496
INCLUDE_DIRECTORIES $<TARGET_PROPERTY:php_ext_standard,INCLUDE_DIRECTORIES>
497497
COMPILE_DEFINITIONS $<TARGET_PROPERTY:php_ext_standard,COMPILE_DEFINITIONS>
498498
COMPILE_OPTIONS $<TARGET_PROPERTY:php_ext_standard,COMPILE_OPTIONS>
499+
PHP_CORE TRUE
499500
)
500501

501502
target_compile_definitions(

cmake/ext/tidy/CMakeLists.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,8 @@ target_sources(
7575
)
7676

7777
get_target_property(type php_ext_tidy TYPE)
78-
if(
79-
CMAKE_SYSTEM_NAME STREQUAL "Windows"
80-
AND TARGET php_sapi
81-
AND NOT type MATCHES "^(MODULE|SHARED)_LIBRARY$"
82-
)
83-
target_sources(php_sapi INTERFACE php_tidy.def)
78+
if(TARGET php_windows AND type MATCHES "^(OBJECT|STATIC)_LIBRARY$")
79+
target_sources(php_windows PRIVATE php_tidy.def)
8480
endif()
8581

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

cmake/ext/zlib/CMakeLists.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,8 @@ target_sources(
102102
)
103103

104104
get_target_property(type php_ext_zlib TYPE)
105-
if(
106-
CMAKE_SYSTEM_NAME STREQUAL "Windows"
107-
AND TARGET php_sapi
108-
AND NOT type MATCHES "^(MODULE|SHARED)_LIBRARY$"
109-
)
110-
target_sources(php_sapi INTERFACE php_zlib.def)
105+
if(TARGET php_windows AND type MATCHES "^(OBJECT|STATIC)_LIBRARY$")
106+
target_sources(php_windows PRIVATE php_zlib.def)
111107
endif()
112108

113109
target_compile_definitions(php_ext_zlib PRIVATE ZEND_ENABLE_STATIC_TSRMLS_CACHE)

0 commit comments

Comments
 (0)