Skip to content

Commit e9694bc

Browse files
committed
Merge branch 'PHP-8.4'
2 parents 864966f + b963fb8 commit e9694bc

File tree

7 files changed

+198
-94
lines changed

7 files changed

+198
-94
lines changed

bin/check-cmake.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ function getProjectModules(): array
152152
'CheckLanguage' => ['check_language'],
153153
'CheckLibraryExists' => ['check_library_exists'],
154154
'CheckLinkerFlag' => ['check_linker_flag'],
155+
'CheckPIESupported' => ['check_pie_supported'],
155156
'CheckPrototypeDefinition' => ['check_prototype_definition'],
156157
'CheckSourceCompiles' => ['check_source_compiles'],
157158
'CheckSourceRuns' => ['check_source_runs'],

cmake/cmake/modules/PHP/PositionIndependentCode.cmake

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,31 @@
44
Check whether to enable the `POSITION_INDEPENDENT_CODE` or not for all targets.
55
The SHARED and MODULE targets have PIC enabled regardless of this option.
66
7+
TODO: This unconditionally enables position independent code globally, to be
8+
able to build shared apache2handler, embed, and phpdbg SAPIs. Probably could be
9+
fine tuned in the future better but it can exponentially complicate the build
10+
system code or the build usability.
11+
712
https://cmake.org/cmake/help/latest/variable/CMAKE_POSITION_INDEPENDENT_CODE.html
813
#]=============================================================================]
914

1015
include_guard(GLOBAL)
1116

12-
if(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_SIZEOF_VOID_P EQUAL 4)
13-
# On 32-bit *nix (Linux and FreeBSD at least) when using Clang, the PIC is
14-
# required.
17+
block()
18+
include(CheckPIESupported)
19+
check_pie_supported(OUTPUT_VARIABLE output)
20+
if(NOT CMAKE_C_LINK_PIE_SUPPORTED)
21+
message(
22+
WARNING
23+
"Position independent executable (PIE) is not supported at link time: "
24+
"${output}.\n"
25+
"PIE link options will not be passed to linker."
26+
)
27+
endif()
28+
endblock()
29+
30+
if(NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE)
1531
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
16-
else()
17-
set(CMAKE_POSITION_INDEPENDENT_CODE OFF)
1832
endif()
1933

2034
message(

cmake/sapi/apache2handler/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ target_sources(
5858
set_target_properties(
5959
php_sapi_apache2handler
6060
PROPERTIES
61-
OUTPUT_NAME apache
61+
OUTPUT_NAME mod_${PHP_PROGRAM_PREFIX}php${PHP_PROGRAM_SUFFIX}
6262
)
6363

6464
target_compile_definitions(
@@ -132,5 +132,8 @@ endif()
132132

133133
install(
134134
TARGETS php_sapi_apache2handler
135-
DESTINATION ${CMAKE_INSTALL_LIBDIR}
135+
LIBRARY
136+
DESTINATION ${Apache_LIBEXECDIR}
137+
RUNTIME
138+
DESTINATION ${Apache_LIBEXECDIR}
136139
)

cmake/sapi/embed/CMakeLists.txt

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,38 +34,39 @@ endif()
3434
add_library(php_sapi_embed STATIC)
3535
add_library(PHP::sapi::embed ALIAS php_sapi_embed)
3636

37+
add_library(php_sapi_embed_shared SHARED)
38+
add_library(PHP::sapi::embed_shared ALIAS php_sapi_embed_shared)
39+
3740
target_sources(
3841
php_sapi_embed
39-
PRIVATE
40-
php_embed.c
4142
PUBLIC
4243
FILE_SET HEADERS
4344
FILES
4445
php_embed.h
4546
)
4647

47-
target_link_libraries(
48-
php_sapi_embed
49-
PRIVATE
50-
$<BUILD_INTERFACE:PHP::sapi>
51-
)
48+
foreach(target IN ITEMS php_sapi_embed php_sapi_embed_shared)
49+
target_sources(${target} PRIVATE php_embed.c)
5250

53-
target_compile_definitions(php_sapi_embed PRIVATE ZEND_ENABLE_STATIC_TSRMLS_CACHE)
51+
target_link_libraries(${target} PRIVATE $<BUILD_INTERFACE:PHP::sapi>)
5452

55-
set_target_properties(
56-
php_sapi_embed
57-
PROPERTIES
58-
OUTPUT_NAME libphp
59-
ENABLE_EXPORTS TRUE # TODO: Check if there's a better solution.
60-
PHP_CLI TRUE
61-
)
53+
target_compile_definitions(${target} PRIVATE ZEND_ENABLE_STATIC_TSRMLS_CACHE)
54+
55+
set_target_properties(
56+
${target}
57+
PROPERTIES
58+
OUTPUT_NAME libphp
59+
ENABLE_EXPORTS TRUE # TODO: Check if there's a better solution.
60+
PHP_CLI TRUE
61+
)
62+
endforeach()
6263

6364
# Configure pkg-config php-embed.pc metadata file.
6465
include(PHP/PkgConfig)
6566
php_pkgconfig_generate_pc(
6667
php-embed.pc.in
6768
php-embed.pc
68-
TARGET PHP::sapi::embed
69+
TARGET PHP::sapi::embed_shared
6970
VARIABLES
7071
prefix "$<INSTALL_PREFIX>"
7172
exec_prefix "$<INSTALL_PREFIX>"
@@ -83,7 +84,9 @@ php_pkgconfig_generate_pc(
8384
)
8485

8586
install(
86-
TARGETS php_sapi_embed
87+
TARGETS php_sapi_embed php_sapi_embed_shared
88+
ARCHIVE
89+
DESTINATION ${CMAKE_INSTALL_LIBDIR}
8790
RUNTIME
8891
DESTINATION ${CMAKE_INSTALL_LIBDIR}
8992
LIBRARY

cmake/sapi/phpdbg/CMakeLists.txt

Lines changed: 110 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -100,47 +100,68 @@ endif()
100100
# Executable and library.
101101
################################################################################
102102

103-
set(phpdbgSources
104-
phpdbg_bp.c
105-
phpdbg_break.c
106-
phpdbg_btree.c
107-
phpdbg_cmd.c
108-
phpdbg_frame.c
109-
phpdbg_help.c
110-
phpdbg_info.c
111-
phpdbg_io.c
112-
phpdbg_lexer.c
113-
phpdbg_list.c
114-
phpdbg_out.c
115-
phpdbg_parser.c
116-
phpdbg_print.c
117-
phpdbg.stub.php
118-
phpdbg_prompt.c
119-
phpdbg_set.c
120-
phpdbg_sigsafe.c
121-
phpdbg_utils.c
122-
phpdbg_watch.c
123-
$<$<PLATFORM_ID:Windows>:phpdbg_win.c>
124-
phpdbg.c
125-
)
126-
127-
add_executable(php_sapi_phpdbg ${phpdbgSources})
103+
add_executable(php_sapi_phpdbg)
128104
add_executable(PHP::sapi::phpdbg ALIAS php_sapi_phpdbg)
129105

130-
target_compile_definitions(
131-
php_sapi_phpdbg
132-
PRIVATE
133-
ZEND_ENABLE_STATIC_TSRMLS_CACHE
134-
$<$<PLATFORM_ID:Windows>:YY_NO_UNISTD_H>
135-
$<$<BOOL:${PHP_SAPI_PHPDBG_DEBUG}>:PHPDBG_DEBUG=1>
136-
)
106+
if(PHP_SAPI_PHPDBG_SHARED)
107+
add_library(php_sapi_phpdbg_shared SHARED)
108+
add_library(PHP::sapi::phpdbg_shared ALIAS php_sapi_phpdbg_shared)
109+
endif()
137110

138-
target_link_libraries(
139-
php_sapi_phpdbg
140-
PRIVATE
141-
$<BUILD_INTERFACE:PHP::sapi>
142-
$<$<PLATFORM_ID:Windows>:ws2_32;user32>
143-
)
111+
foreach(target IN ITEMS php_sapi_phpdbg php_sapi_phpdbg_shared)
112+
if(NOT TARGET ${target})
113+
continue()
114+
endif()
115+
116+
target_sources(
117+
${target}
118+
PRIVATE
119+
phpdbg_bp.c
120+
phpdbg_break.c
121+
phpdbg_btree.c
122+
phpdbg_cmd.c
123+
phpdbg_frame.c
124+
phpdbg_help.c
125+
phpdbg_info.c
126+
phpdbg_io.c
127+
phpdbg_lexer.c
128+
phpdbg_list.c
129+
phpdbg_out.c
130+
phpdbg_parser.c
131+
phpdbg_print.c
132+
phpdbg.stub.php
133+
phpdbg_prompt.c
134+
phpdbg_set.c
135+
phpdbg_sigsafe.c
136+
phpdbg_utils.c
137+
phpdbg_watch.c
138+
$<$<PLATFORM_ID:Windows>:phpdbg_win.c>
139+
phpdbg.c
140+
)
141+
142+
target_compile_definitions(
143+
${target}
144+
PRIVATE
145+
ZEND_ENABLE_STATIC_TSRMLS_CACHE
146+
$<$<PLATFORM_ID:Windows>:YY_NO_UNISTD_H>
147+
$<$<BOOL:${PHP_SAPI_PHPDBG_DEBUG}>:PHPDBG_DEBUG=1>
148+
)
149+
150+
target_link_libraries(
151+
${target}
152+
PRIVATE
153+
$<BUILD_INTERFACE:PHP::sapi>
154+
$<$<PLATFORM_ID:Windows>:ws2_32;user32>
155+
)
156+
157+
set_target_properties(
158+
${target}
159+
PROPERTIES
160+
OUTPUT_NAME ${PHP_PROGRAM_PREFIX}phpdbg${PHP_PROGRAM_SUFFIX}
161+
ENABLE_EXPORTS TRUE # TODO: Check if there's a better solution.
162+
PHP_CLI TRUE
163+
)
164+
endforeach()
144165

145166
target_link_options(
146167
php_sapi_phpdbg
@@ -152,10 +173,16 @@ set_target_properties(
152173
php_sapi_phpdbg
153174
PROPERTIES
154175
OUTPUT_NAME ${PHP_PROGRAM_PREFIX}phpdbg${PHP_PROGRAM_SUFFIX}
155-
ENABLE_EXPORTS TRUE # TODO: Check if there's a better solution.
156-
PHP_CLI TRUE
157176
)
158177

178+
if(TARGET php_sapi_phpdbg_shared)
179+
set_target_properties(
180+
php_sapi_phpdbg_shared
181+
PROPERTIES
182+
OUTPUT_NAME libphpdbg
183+
)
184+
endif()
185+
159186
################################################################################
160187
# Readline support.
161188
################################################################################
@@ -174,6 +201,9 @@ if(PHP_SAPI_PHPDBG_READLINE OR PHP_EXT_READLINE)
174201
)
175202

176203
target_link_libraries(php_sapi_phpdbg PRIVATE Editline::Editline)
204+
if(TARGET php_sapi_phpdbg_shared)
205+
target_link_libraries(php_sapi_phpdbg_shared PRIVATE Editline::Editline)
206+
endif()
177207

178208
set(HAVE_LIBEDIT TRUE)
179209
set(HAVE_PHPDBG_READLINE TRUE)
@@ -187,36 +217,6 @@ add_feature_info(
187217
"enhanced command-line accessibility"
188218
)
189219

190-
################################################################################
191-
# The phpdbg shared library.
192-
################################################################################
193-
194-
# TODO: Should readline support be also enabled like in the executable?
195-
# TODO: fix this better in the future (building with -fPIC etc).
196-
if(PHP_SAPI_PHPDBG_SHARED)
197-
add_library(php_sapi_phpdbg_shared SHARED)
198-
add_library(PHP::sapi::phpdbg_shared ALIAS php_sapi_phpdbg_shared)
199-
200-
set_target_properties(php_sapi_phpdbg_shared PROPERTIES OUTPUT_NAME phpdbg)
201-
202-
target_sources(php_sapi_phpdbg_shared PRIVATE ${phpdbgSources})
203-
204-
target_compile_definitions(
205-
php_sapi_phpdbg_shared
206-
PRIVATE
207-
ZEND_ENABLE_STATIC_TSRMLS_CACHE
208-
$<$<PLATFORM_ID:Windows>:YY_NO_UNISTD_H>
209-
$<$<BOOL:${PHP_SAPI_PHPDBG_DEBUG}>:PHPDBG_DEBUG=1>
210-
)
211-
212-
target_link_libraries(
213-
php_sapi_phpdbg_shared
214-
PRIVATE
215-
$<BUILD_INTERFACE:PHP::sapi>
216-
$<$<PLATFORM_ID:Windows>:ws2_32;user32>
217-
)
218-
endif()
219-
220220
################################################################################
221221
# Generate parser and lexer files.
222222
################################################################################
@@ -244,6 +244,9 @@ if(HAVE_UFFDIO_WRITEPROTECT_MODE_WP)
244244
find_package(Threads)
245245
if(Threads_FOUND)
246246
target_link_libraries(php_sapi_phpdbg PRIVATE Threads::Threads)
247+
if(TARGET php_sapi_phpdbg_shared)
248+
target_link_libraries(php_sapi_phpdbg_shared PRIVATE Threads::Threads)
249+
endif()
247250
else()
248251
message(WARNING "Threads not available.")
249252
endif()
@@ -290,4 +293,41 @@ php_install(CODE "
290293
)
291294
")
292295

296+
# Configure pkg-config phpdbg.pc metadata file and install shared phpdbg module.
297+
if(TARGET php_sapi_phpdbg_shared)
298+
include(PHP/PkgConfig)
299+
php_pkgconfig_generate_pc(
300+
phpdbg.pc.in
301+
phpdbg.pc
302+
TARGET PHP::sapi::phpdbg_shared
303+
VARIABLES
304+
prefix "$<INSTALL_PREFIX>"
305+
exec_prefix "$<INSTALL_PREFIX>"
306+
includedir "$<PATH:ABSOLUTE_PATH,NORMALIZE,${CMAKE_INSTALL_INCLUDEDIR},$<INSTALL_PREFIX>>"
307+
php_include_prefix "${PHP_INCLUDE_PREFIX}"
308+
libdir "$<PATH:ABSOLUTE_PATH,NORMALIZE,${CMAKE_INSTALL_LIBDIR},$<INSTALL_PREFIX>>"
309+
PHP_VERSION "${PHP_VERSION}"
310+
PHP_VERSION_ID "${PHP_VERSION_ID}"
311+
PHP_EXTENSION_DIR "$<PATH:ABSOLUTE_PATH,NORMALIZE,${PHP_EXTENSION_DIR},$<INSTALL_PREFIX>>"
312+
# TODO: Fix this for cmake --install ... --prefix
313+
PHP_CONFIG_FILE_SCAN_DIR "$<PATH:ABSOLUTE_PATH,NORMALIZE,${PHP_CONFIG_FILE_SCAN_DIR},$<INSTALL_PREFIX>>"
314+
PHP_CONFIG_FILE_PATH "$<PATH:ABSOLUTE_PATH,NORMALIZE,${PHP_CONFIG_FILE_PATH},$<INSTALL_PREFIX>>"
315+
PHP_DEBUG "$<IF:$<CONFIG:Debug,DebugAssertions>,yes,no>"
316+
PHP_THREAD_SAFETY "$<IF:$<BOOL:$<TARGET_PROPERTY:PHP::config,PHP_THREAD_SAFETY>>,yes,no>"
317+
)
318+
319+
install(
320+
FILES ${CMAKE_CURRENT_BINARY_DIR}/phpdbg.pc
321+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
322+
)
323+
324+
install(
325+
TARGETS php_sapi_phpdbg_shared
326+
LIBRARY
327+
DESTINATION ${CMAKE_INSTALL_LIBDIR}
328+
RUNTIME
329+
DESTINATION ${CMAKE_INSTALL_LIBDIR}
330+
)
331+
endif()
332+
293333
configure_file(cmake/config.h.in config.h)

cmake/sapi/phpdbg/phpdbg.pc.in

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# The pkg-config .pc file for PHP Debugger SAPI.
2+
# https://en.wikipedia.org/wiki/Pkg-config
3+
#
4+
# Usage:
5+
# pkg-config --cflags phpdbg
6+
# pkg-config --cflags-only-I phpdbg
7+
# pkg-config --libs phpdbg
8+
# pkg-config --mod-version phpdbg
9+
# pkg-config --print-variables phpdbg
10+
# pkg-config --variable=php_vernum phpdbg
11+
12+
prefix=@prefix@
13+
exec_prefix=@exec_prefix@
14+
includedir=@includedir@
15+
php_include_prefix=@php_include_prefix@
16+
libdir=@libdir@
17+
# The extension_dir PHP INI directive absolute path.
18+
extensiondir=@PHP_EXTENSION_DIR@
19+
# PHP version as integer.
20+
php_vernum=@PHP_VERSION_ID@
21+
# The path where to scan for additional INI configuration files.
22+
php_ini_dir=@PHP_CONFIG_FILE_SCAN_DIR@
23+
# The path in which to look for php.ini.
24+
php_ini_path=@PHP_CONFIG_FILE_PATH@
25+
# Whether PHP is built in debug mode (yes) or not (no).
26+
php_debug=@PHP_DEBUG@
27+
# Whether PHP is built with thread safety (yes) or not (no).
28+
php_zts=@PHP_THREAD_SAFETY@
29+
30+
Name: PHP debugger
31+
Description: Interactive PHP debugger
32+
URL: https://www.php.net
33+
License: PHP
34+
Version: @PHP_VERSION@
35+
Cflags.private: @PHP_CFLAGS_PRIVATE@
36+
Cflags: -I${includedir}/${php_include_prefix} -I${includedir}/${php_include_prefix}/main -I${includedir}/${php_include_prefix}/TSRM -I${includedir}/${php_include_prefix}/Zend -I${includedir}/${php_include_prefix}/ext
37+
Libs.private: @PHP_LIBS_PRIVATE@
38+
Libs: -L${libdir} -lphpdbg

0 commit comments

Comments
 (0)