Skip to content

Commit 63fc00f

Browse files
committed
Fix shared extensions on Windows
This now enables building shared extensions also on Windows. - Added PHP_CORE target property.
1 parent 9db82a5 commit 63fc00f

File tree

23 files changed

+157
-61
lines changed

23 files changed

+157
-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
@@ -883,9 +883,10 @@ if(PHP_DTRACE)
883883
INCLUDES
884884
$<TARGET_PROPERTY:PHP::config,INTERFACE_INCLUDE_DIRECTORIES>
885885
)
886+
set_target_properties(php_dtrace PROPERTIES PHP_CORE TRUE)
886887

887888
target_link_libraries(php_config INTERFACE DTrace::DTrace)
888-
target_link_libraries(php_sapi INTERFACE php_dtrace)
889+
target_link_libraries(php_core_objects INTERFACE php_dtrace)
889890

890891
set(HAVE_DTRACE TRUE)
891892
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/cmake/presets/windows.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,36 @@
88
"binaryDir": "${sourceDir}/php-build/windows",
99
"installDir": "C:/temp",
1010
"cacheVariables": {
11+
"PHP_EXT_BCMATH": true,
12+
"PHP_EXT_CALENDAR": true,
1113
"PHP_EXT_COM_DOTNET": true,
1214
"PHP_EXT_CTYPE": true,
15+
"PHP_EXT_DL_TEST": true,
1316
"PHP_EXT_DOM": false,
1417
"PHP_EXT_FILEINFO": true,
1518
"PHP_EXT_FILTER": true,
19+
"PHP_EXT_FTP": true,
20+
"PHP_EXT_FTP_SSL": false,
1621
"PHP_EXT_ICONV": false,
1722
"PHP_EXT_LIBXML": false,
23+
"PHP_EXT_MBSTRING": false,
24+
"PHP_EXT_MBSTRING_MBREGEX": false,
1825
"PHP_EXT_OPCACHE": true,
1926
"PHP_EXT_PDO": true,
2027
"PHP_EXT_PDO_SQLITE": false,
2128
"PHP_EXT_PHAR": false,
2229
"PHP_EXT_POSIX": false,
2330
"PHP_EXT_SESSION": true,
31+
"PHP_EXT_SHMOP": true,
2432
"PHP_EXT_SIMPLEXML": false,
33+
"PHP_EXT_SOCKETS": true,
2534
"PHP_EXT_SQLITE3": false,
35+
"PHP_EXT_SYSVSHM": true,
2636
"PHP_EXT_TOKENIZER": true,
2737
"PHP_EXT_XML": false,
2838
"PHP_EXT_XMLREADER": false,
2939
"PHP_EXT_XMLWRITER": false,
40+
"PHP_EXT_ZEND_TEST": true,
3041

3142
"PHP_SAPI_CGI": true,
3243
"PHP_SAPI_PHPDBG": true,

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

cmake/ext/zlib/CMakeLists.txt

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

6969
get_target_property(type php_ext_zlib TYPE)
70-
if(
71-
CMAKE_SYSTEM_NAME STREQUAL "Windows"
72-
AND TARGET php_sapi
73-
AND NOT type MATCHES "^(MODULE|SHARED)_LIBRARY$"
74-
)
75-
target_sources(php_sapi INTERFACE php_zlib.def)
70+
if(TARGET php_windows AND type MATCHES "^(OBJECT|STATIC)_LIBRARY$")
71+
target_sources(php_windows PRIVATE php_zlib.def)
7672
endif()
7773

7874
target_compile_definitions(php_ext_zlib PRIVATE ZEND_ENABLE_STATIC_TSRMLS_CACHE)

cmake/main/CMakeLists.txt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,16 @@ target_sources(
104104
$<$<NOT:$<PLATFORM_ID:Windows>>:${PHP_BINARY_DIR}/$<CONFIG>/main/php_config.h>
105105
)
106106

107+
set_target_properties(php_main PROPERTIES PHP_CORE TRUE)
108+
107109
################################################################################
108110
# Add usage requirements to PHP interface targets.
109111
################################################################################
110112

111113
target_compile_definitions(
112114
php_config
113115
INTERFACE
114-
$<$<PLATFORM_ID:Windows>:SAPI_EXPORTS>
116+
$<$<AND:$<PLATFORM_ID:Windows>,$<BOOL:$<TARGET_PROPERTY:PHP_CORE>>>:SAPI_EXPORTS>
115117
)
116118

117119
target_include_directories(
@@ -123,16 +125,16 @@ target_include_directories(
123125
${CMAKE_CURRENT_SOURCE_DIR}
124126
)
125127

126-
target_link_libraries(php_sapi INTERFACE PHP::main)
127-
target_sources(php_sapi INTERFACE $<TARGET_OBJECTS:PHP::main>)
128+
target_link_libraries(php_core_objects INTERFACE PHP::main)
129+
target_sources(php_core_objects INTERFACE $<TARGET_OBJECTS:PHP::main>)
128130

129131
################################################################################
130132
# Add FastCGI target with objects for use in PHP SAPIs such as CGI and FPM.
131133
################################################################################
132134
add_library(php_main_fastcgi OBJECT fastcgi.c)
133135

134136
target_sources(
135-
php_sapi
137+
php_core
136138
INTERFACE
137139
$<$<BOOL:$<TARGET_PROPERTY:PHP_SAPI_FASTCGI>>:$<TARGET_OBJECTS:php_main_fastcgi>>
138140
)
@@ -144,9 +146,14 @@ target_sources(
144146

145147
add_library(php_main_internal_functions OBJECT internal_functions.c)
146148
add_library(php_main_internal_functions_cli OBJECT internal_functions_cli.c)
149+
set_target_properties(
150+
php_main_internal_functions
151+
php_main_internal_functions_cli
152+
PROPERTIES PHP_CORE TRUE
153+
)
147154

148155
target_sources(
149-
php_sapi
156+
php_core_objects
150157
INTERFACE
151158
$<IF:$<BOOL:$<TARGET_PROPERTY:PHP_CLI>>,$<TARGET_OBJECTS:php_main_internal_functions_cli>,$<TARGET_OBJECTS:php_main_internal_functions>>
152159
)

cmake/sapi/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ define_property(
2222

2323
list(APPEND CMAKE_MESSAGE_CONTEXT "sapi")
2424

25+
set(CMAKE_ENABLE_EXPORTS TRUE)
26+
2527
# Traverse CMakeLists.txt files of PHP SAPIs.
2628
file(GLOB sapis ${CMAKE_CURRENT_SOURCE_DIR}/*/CMakeLists.txt)
2729
list(TRANSFORM sapis REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/|/CMakeLists.txt" "")

cmake/sapi/apache2handler/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ set_package_properties(
7878
target_link_libraries(
7979
php_sapi_apache2handler
8080
PRIVATE
81-
$<BUILD_INTERFACE:PHP::sapi>
81+
$<BUILD_INTERFACE:PHP::core>
8282
Apache::Apache
8383
)
8484

cmake/sapi/cgi/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ target_compile_definitions(php_sapi_cgi PRIVATE ZEND_ENABLE_STATIC_TSRMLS_CACHE)
4141
target_link_libraries(
4242
php_sapi_cgi
4343
PRIVATE
44-
$<BUILD_INTERFACE:PHP::sapi>
44+
$<BUILD_INTERFACE:PHP::core>
4545
$<$<PLATFORM_ID:Windows>:ws2_32;kernel32;advapi32>
4646
)
4747

@@ -53,7 +53,6 @@ set_target_properties(
5353
php_sapi_cgi
5454
PROPERTIES
5555
OUTPUT_NAME ${PHP_PROGRAM_PREFIX}php-cgi${PHP_PROGRAM_SUFFIX}
56-
ENABLE_EXPORTS TRUE # TODO: Check if there's a better solution.
5756
PHP_CLI TRUE
5857
PHP_SAPI_FASTCGI TRUE
5958
)

cmake/sapi/cli/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ target_compile_definitions(
110110
target_link_libraries(
111111
php_sapi_cli
112112
PRIVATE
113-
$<BUILD_INTERFACE:PHP::sapi>
113+
$<BUILD_INTERFACE:PHP::core>
114114
$<$<PLATFORM_ID:Windows>:ws2_32;shell32>
115115
)
116116

@@ -122,7 +122,6 @@ set_target_properties(
122122
php_sapi_cli
123123
PROPERTIES
124124
OUTPUT_NAME ${PHP_PROGRAM_PREFIX}php${PHP_PROGRAM_SUFFIX}
125-
ENABLE_EXPORTS TRUE # TODO: Check if there's a better solution.
126125
PHP_CLI TRUE
127126
)
128127

@@ -182,7 +181,7 @@ if(PHP_SAPI_CLI_WIN_NO_CONSOLE)
182181
target_link_libraries(
183182
php_sapi_cli_win
184183
PRIVATE
185-
$<BUILD_INTERFACE:PHP::sapi>
184+
$<BUILD_INTERFACE:PHP::core>
186185
shell32
187186
)
188187

0 commit comments

Comments
 (0)