Skip to content

Commit 3b70adf

Browse files
committed
Add FastCGI target for PHP CGI SAPI and PHP_SAPI_FASTCGI target property
- The main/fastcgi.c is only used in cgi and fpm SAPIs. - Synced sapi/cgi further. - Added custom target property PHP_SAPI_FASTCGI that links the required FastCGI-related objects into the binary.
1 parent d3d1023 commit 3b70adf

File tree

6 files changed

+36
-8
lines changed

6 files changed

+36
-8
lines changed

cmake/cmake/Bootstrap.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ define_property(
1010
BRIEF_DOCS "Whether the PHP SAPI or extension is CLI-based"
1111
)
1212

13+
define_property(
14+
TARGET
15+
PROPERTY PHP_SAPI_FASTCGI
16+
BRIEF_DOCS "Whether the PHP SAPI is FastCGI-based"
17+
)
18+
1319
# Optionally enable CXX for extensions.
1420
include(CheckLanguage)
1521
check_language(CXX)

cmake/main/CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ target_sources(
1717
php_main
1818
PRIVATE
1919
$<$<NOT:$<PLATFORM_ID:Windows>>:explicit_bzero.c>
20-
fastcgi.c
2120
fopen_wrappers.c
2221
getopt.c
2322
main.c
@@ -122,6 +121,17 @@ target_include_directories(
122121
target_link_libraries(php_sapi INTERFACE PHP::main)
123122
target_sources(php_sapi INTERFACE $<TARGET_OBJECTS:PHP::main>)
124123

124+
################################################################################
125+
# Add FastCGI target with objects for use in PHP SAPIs such as CGI and FPM.
126+
################################################################################
127+
add_library(php_main_fastcgi OBJECT fastcgi.c)
128+
129+
target_sources(
130+
php_sapi
131+
INTERFACE
132+
$<$<BOOL:$<TARGET_PROPERTY:PHP_SAPI_FASTCGI>>:$<TARGET_OBJECTS:php_main_fastcgi>>
133+
)
134+
125135
################################################################################
126136
# Create main/internal_functions*.c files with a list of static enabled PHP
127137
# extensions based on the PHP SAPI type.

cmake/sapi/cgi/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ set_target_properties(
5757
OUTPUT_NAME ${PHP_PROGRAM_PREFIX}php-cgi${PHP_PROGRAM_SUFFIX}
5858
ENABLE_EXPORTS TRUE # TODO: Check if there's a better solution.
5959
PHP_CLI TRUE
60+
PHP_SAPI_FASTCGI TRUE
6061
)
6162

6263
# BSD systems.

cmake/sapi/cli/CMakeLists.txt

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,20 @@ set_target_properties(
128128
PHP_CLI TRUE
129129
)
130130

131+
# Link editline library conditionally based on readline extension.
131132
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
132-
# Link readline extension interface library if enabled and built statically.
133-
target_link_libraries(
134-
php_sapi_cli
135-
PRIVATE
136-
$<$<AND:$<TARGET_EXISTS:PHP::ext::readline>,$<NOT:$<IN_LIST:$<TARGET_PROPERTY:PHP::ext::readline,TYPE>,MODULE_LIBRARY;SHARED_LIBRARY>>>:$<TARGET_PROPERTY:PHP::ext::readline,IMPORTED_LINK_INTERFACE_LIBRARIES>>
137-
)
133+
set(type "")
134+
if(PHP_EXT_READLINE)
135+
get_target_property(type PHP::ext::readline TYPE)
136+
endif()
137+
138+
if(NOT PHP_EXT_READLINE OR NOT type MATCHES "^(MODULE|SHARED)_LIBRARY$")
139+
find_package(Editline)
140+
if(Editline_FOUND)
141+
target_link_libraries(php_sapi_cli PRIVATE Editline::Editline)
142+
set(HAVE_LIBEDIT TRUE)
143+
endif()
144+
endif()
138145
endif()
139146

140147
# Man documentation.
@@ -196,7 +203,7 @@ if(PHP_SAPI_CLI_WIN_NO_CONSOLE)
196203
target_link_options(
197204
php_sapi_cli_win
198205
PRIVATE
199-
/stack:67108864
206+
$<$<COMPILE_LANG_AND_ID:C,MSVC>:/stack:67108864>
200207
)
201208
endif()
202209

cmake/sapi/cli/cmake/config.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/* Define to 1 if PHP uses the 'libedit' library. */
2+
#cmakedefine HAVE_LIBEDIT 1
3+
14
/* Define if the PS_STRINGS exists. */
25
#cmakedefine HAVE_PS_STRINGS
36

cmake/sapi/fpm/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ set_target_properties(
243243
PROPERTIES
244244
OUTPUT_NAME ${PHP_PROGRAM_PREFIX}php-fpm${PHP_PROGRAM_SUFFIX}
245245
ENABLE_EXPORTS TRUE # TODO: Check if there's a better solution.
246+
PHP_SAPI_FASTCGI TRUE
246247
)
247248

248249
################################################################################

0 commit comments

Comments
 (0)