Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 0 additions & 53 deletions cmake/TSRM/CMakeLists.txt

This file was deleted.

59 changes: 45 additions & 14 deletions cmake/Zend/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[=============================================================================[
Zend Engine.

CMake target properties for the `Zend::Zend` (`zend`) target:
CMake target properties for the `Zend::Zend` target:

* `VERSION`

Expand Down Expand Up @@ -298,16 +298,7 @@ target_sources(
$<$<NOT:$<PLATFORM_ID:Windows>>:${CMAKE_CURRENT_BINARY_DIR}/zend_config.h>
)

# Add TSRM.
add_subdirectory(../TSRM ../TSRM)

target_link_libraries(
zend
PRIVATE
PHP::configuration
PUBLIC
TSRM::TSRM
)
target_link_libraries(zend PRIVATE PHP::configuration)

target_include_directories(
zend
Expand Down Expand Up @@ -352,18 +343,58 @@ block()
)
endblock()

# Add Zend PUBLIC/INTERFACE compile options to configuration.
# Add Zend PUBLIC/INTERFACE compile properties to configuration.
# Cleaner COMPILE_ONLY generator expression is available in CMake >= 3.27.
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.27)
target_link_libraries(php_configuration INTERFACE $<COMPILE_ONLY:Zend::Zend>)
target_link_libraries(php_configuration INTERFACE $<COMPILE_ONLY:zend>)
else()
target_include_directories(
php_configuration
INTERFACE
$<TARGET_PROPERTY:Zend::Zend,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:zend,INTERFACE_INCLUDE_DIRECTORIES>
)
target_compile_definitions(
php_configuration
INTERFACE
$<TARGET_PROPERTY:zend,INTERFACE_COMPILE_DEFINITIONS>
)
endif()

################################################################################
# TSRM (Thread Safe Resource Manager) is a separate directory in php-src as it
# was once a standalone project. Ideally, it should be moved into Zend Engine at
# some point.
################################################################################

target_sources(
zend
PRIVATE
$<$<PLATFORM_ID:Windows>:${CMAKE_CURRENT_SOURCE_DIR}/../TSRM/tsrm_win32.c>
${CMAKE_CURRENT_SOURCE_DIR}/../TSRM/TSRM.c
PUBLIC
FILE_SET tsrm
TYPE HEADERS
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../TSRM
FILES
$<$<PLATFORM_ID:Windows>:${CMAKE_CURRENT_SOURCE_DIR}/../TSRM/tsrm_win32.h>
${CMAKE_CURRENT_SOURCE_DIR}/../TSRM/TSRM.h
)

target_include_directories(
zend
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../TSRM>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PHP_INCLUDE_PREFIX}/TSRM>
)

target_compile_definitions(zend PUBLIC $<$<PLATFORM_ID:Windows>:TSRM_EXPORTS>)

install(
TARGETS zend
FILE_SET tsrm
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PHP_INCLUDE_PREFIX}/TSRM
)

################################################################################
# Configuration checks.
################################################################################
Expand Down
2 changes: 2 additions & 0 deletions cmake/cmake/modules/FindRE2C.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ function(re2c_target)
${input}
DEPENDS ${input} ${parsed_DEPENDS}
COMMENT "[RE2C][${ARGV0}] Building lexer with re2c ${RE2C_VERSION}"
VERBATIM
COMMAND_EXPAND_LISTS
)

add_custom_target(
Expand Down
8 changes: 6 additions & 2 deletions cmake/ext/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ foreach(extension IN LISTS extensions)
if(TARGET php_${extension})
set_property(GLOBAL APPEND PROPERTY PHP_EXTENSIONS ${extension})

# Add extension's PUBLIC/INTERFACE compile options to configuration.
# Add extension's PUBLIC/INTERFACE compile properties to configuration.
# Cleaner COMPILE_ONLY generator expression is available in CMake >= 3.27.
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.27)
target_link_libraries(
Expand All @@ -98,6 +98,10 @@ foreach(extension IN LISTS extensions)
$<COMPILE_ONLY:PHP::${extension}>
)
else()
# TODO: Fix this better. Either require 3.27, or limit/adjust compile
# properties propagated globally. Also, shared extensions shouldn't
# propagate globally.
# https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#id36
target_include_directories(
php_configuration
INTERFACE
Expand All @@ -114,7 +118,7 @@ foreach(extension IN LISTS extensions)
$<TARGET_PROPERTY:php_configuration,INTERFACE_COMPILE_OPTIONS>
)

add_dependencies(php_${extension} zend)
add_dependencies(php_${extension} Zend::Zend)

get_target_property(type php_${extension} TYPE)
if(NOT type MATCHES "^(MODULE|SHARED)_LIBRARY$")
Expand Down
2 changes: 1 addition & 1 deletion cmake/ext/pcntl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This extension provides support for process control support.
> This extension is available only on \*nix systems.

> [!IMPORTANT]
> This extension should be used only with cgi, cli, embed, or phpdbg SAPI.
> This extension should be used only with CLI-based PHP SAPIs.

## EXT_PCNTL

Expand Down
2 changes: 1 addition & 1 deletion cmake/ext/readline/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Configure the `readline` extension.
This extension provides interface for using Editline library.

> [!IMPORTANT]
> This extension should be used only with cgi, cli, embed, or phpdbg SAPI.
> This extension should be used only with CLI-based PHP SAPIs.

## EXT_READLINE

Expand Down
95 changes: 63 additions & 32 deletions cmake/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,16 @@ PHP main binding.

include(FeatureSummary)

add_library(php INTERFACE)
add_library(PHP::PHP ALIAS php)
################################################################################
# Add library.
################################################################################

add_library(php_main OBJECT)
add_library(PHP::main ALIAS php_main)

# These contain a list of built-in extensions based on the SAPI types.
add_library(php_main_internal_functions OBJECT internal_functions.c)
add_library(php_main_internal_functions_cli OBJECT internal_functions_cli.c)

# Configuration library to transitively pass build options to php_main* targets.
add_library(php_main_configuration INTERFACE)
add_library(PHP::mainConfiguration ALIAS php_main_configuration)

target_sources(
php_main
PRIVATE
Expand Down Expand Up @@ -113,51 +109,83 @@ target_sources(
)

target_compile_definitions(
php_main_configuration
INTERFACE
ZEND_ENABLE_STATIC_TSRMLS_CACHE=1
php_main
PUBLIC
$<$<PLATFORM_ID:Windows>:SAPI_EXPORTS>
)

target_link_libraries(
php_main_configuration
INTERFACE
PHP::configuration
$<$<TARGET_EXISTS:PHP::win32>:PHP::win32 $<TARGET_OBJECTS:PHP::win32>>
)

target_link_libraries(php_main PRIVATE PHP::mainConfiguration)
target_link_libraries(php_main_internal_functions PRIVATE PHP::mainConfiguration)
target_link_libraries(php_main_internal_functions_cli PRIVATE PHP::mainConfiguration)

target_include_directories(
php_main
INTERFACE
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
)

# Add main PUBLIC/INTERFACE include directories to configuration.
target_include_directories(
php_configuration
INTERFACE
$<TARGET_PROPERTY:PHP::main,INTERFACE_INCLUDE_DIRECTORIES>
set_property(
TARGET
php_main
php_main_internal_functions
php_main_internal_functions_cli
APPEND
PROPERTY COMPILE_DEFINITIONS ZEND_ENABLE_STATIC_TSRMLS_CACHE=1
)

# Add main PUBLIC/INTERFACE compile properties to configuration.
# Cleaner COMPILE_ONLY generator expression is available in CMake >= 3.27.
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.27)
target_link_libraries(php_configuration INTERFACE $<COMPILE_ONLY:php_main>)
else()
target_include_directories(
php_configuration
INTERFACE
$<TARGET_PROPERTY:php_main,INTERFACE_INCLUDE_DIRECTORIES>
)
target_compile_definitions(
php_configuration
INTERFACE
$<TARGET_PROPERTY:php_main,INTERFACE_COMPILE_DEFINITIONS>
)
endif()

target_link_libraries(php_main PRIVATE PHP::configuration)
target_link_libraries(php_main_internal_functions PRIVATE PHP::configuration)
target_link_libraries(php_main_internal_functions_cli PRIVATE PHP::configuration)

################################################################################
# Add PHP::PHP.
################################################################################

add_library(php INTERFACE)
add_library(PHP::PHP ALIAS php)

target_link_libraries(
php
INTERFACE
PHP::configuration
PHP::main
$<TARGET_OBJECTS:PHP::main>
# Pass transitively depending on the SAPI type.
$<IF:$<IN_LIST:$<TARGET_PROPERTY:NAME>,php_cgi;php_cli;php_embed;php_phpdbg>,php_main_internal_functions_cli $<TARGET_OBJECTS:php_main_internal_functions_cli>,php_main_internal_functions $<TARGET_OBJECTS:php_main_internal_functions>>
php_main
Zend::Zend
$<TARGET_OBJECTS:Zend::Zend>
$<$<TARGET_EXISTS:PHP::windows>::PHP::windows>
PHP::extensions
)

# OBJECT libraries propagate only compile properties to static libraries without
# objects as there is no "linking" involved on the compiler level. This is a
# workaround using interface target sources to make PHP::PHP more intuitive to
# work with SAPIs.
target_sources(
php
INTERFACE
$<TARGET_OBJECTS:php_main>
# Internal functions objects based on the SAPI type.
$<IF:$<BOOL:$<TARGET_PROPERTY:PHP_SAPI_CLI>>,$<TARGET_OBJECTS:php_main_internal_functions_cli>,$<TARGET_OBJECTS:php_main_internal_functions>>
$<TARGET_OBJECTS:Zend::Zend>
$<$<TARGET_EXISTS:PHP::windows>:$<TARGET_OBJECTS:PHP::windows>>
)

################################################################################
# Add DTrace.
################################################################################

if(PHP_DTRACE)
message(CHECK_START "Checking for DTrace support")

Expand Down Expand Up @@ -196,7 +224,10 @@ add_feature_info(
"performance analysis and troubleshooting"
)

################################################################################
# Add Dmalloc.
################################################################################

if(PHP_DMALLOC)
message(CHECK_START "Checking for Dmalloc support")

Expand All @@ -211,7 +242,7 @@ if(PHP_DMALLOC)
target_compile_definitions(
php_configuration
INTERFACE
$<$<COMPILE_LANGUAGE:ASM,C,CXX>:MALLOC_FUNC_CHECK>
$<$<COMPILE_LANGUAGE:ASM,C,CXX>:DMALLOC_FUNC_CHECK>
)

target_link_libraries(php_main PRIVATE Dmalloc::Dmalloc)
Expand Down
12 changes: 12 additions & 0 deletions cmake/sapi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ Add subdirectories of PHP SAPIs.
* `PHP_SAPIS`

Global property with a list of all enabled PHP SAPIs.

* `PHP_SAPI_CLI`

Target property that designates PHP SAPI as CLI-based. These SAPIs can utilize
CLI-based PHP extensions (for example, pcntl) and include
main/internal_functions_cli.c object instead of the main/internal_functions.c.
#]=============================================================================]

message(STATUS "----------------------------")
Expand All @@ -28,6 +34,12 @@ define_property(
BRIEF_DOCS "A list of all enabled PHP SAPIs"
)

define_property(
TARGET
PROPERTY PHP_SAPI_CLI
BRIEF_DOCS "Whether the PHP SAPI is CLI-based to run in a CLI environment"
)

list(APPEND CMAKE_MESSAGE_CONTEXT "sapi")

# Traverse CMakeLists.txt files of PHP SAPIs.
Expand Down
1 change: 1 addition & 0 deletions cmake/sapi/cgi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ set_target_properties(
OUTPUT_NAME ${PHP_PROGRAM_PREFIX}php-cgi${PHP_PROGRAM_SUFFIX}
# TODO: Check if there's a better solution here:
ENABLE_EXPORTS TRUE
PHP_SAPI_CLI TRUE
)

# BSD systems.
Expand Down
1 change: 1 addition & 0 deletions cmake/sapi/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ set_target_properties(
OUTPUT_NAME ${PHP_PROGRAM_PREFIX}php${PHP_PROGRAM_SUFFIX}
# TODO: Check if there's a better solution here:
ENABLE_EXPORTS TRUE
PHP_SAPI_CLI TRUE
)

if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
Expand Down
Loading
Loading