Skip to content

Commit 22a3055

Browse files
committed
Fix shared extensions on Windows
This now enables building shared extensions also on Windows. - Added PHP_CORE target property.
1 parent 34052f5 commit 22a3055

File tree

21 files changed

+144
-56
lines changed

21 files changed

+144
-56
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: 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/cmake/modules/PHP/Extension.cmake

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,14 @@ function(_php_extension_post_configure)
6464
set_property(TARGET php_ext_${extension} PROPERTY OUTPUT_NAME ${extension})
6565
endif()
6666

67+
# Set target output filename prefix "[<prefix>]<extension>".
6768
get_target_property(prefix php_ext_${extension} PREFIX)
6869
if(NOT prefix)
69-
set_property(TARGET php_ext_${extension} PROPERTY PREFIX "")
70+
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
71+
set_property(TARGET php_ext_${extension} PROPERTY PREFIX "php_")
72+
else()
73+
set_property(TARGET php_ext_${extension} PROPERTY PREFIX "")
74+
endif()
7075
endif()
7176

7277
##############################################################################

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
@@ -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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ else()
213213
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
214214
set(PCRE2_STATIC TRUE)
215215

216-
if(TARGET php_sapi)
217-
target_sources(php_sapi INTERFACE php_pcre.def)
216+
if(TARGET php_windows)
217+
target_sources(php_windows PRIVATE php_pcre.def)
218218
endif()
219219
endif()
220220

cmake/ext/standard/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ set_target_properties(
495495
PROPERTIES
496496
INCLUDE_DIRECTORIES $<TARGET_PROPERTY:php_ext_standard,INCLUDE_DIRECTORIES>
497497
COMPILE_DEFINITIONS $<TARGET_PROPERTY:php_ext_standard,COMPILE_DEFINITIONS>
498+
PHP_CORE TRUE
498499
)
499500

500501
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

0 commit comments

Comments
 (0)