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
98 changes: 57 additions & 41 deletions cmake/ext/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,57 +78,73 @@ add_library(PHP::extensions ALIAS php_extensions)
# Add subdirectories of extensions.
foreach(extension IN LISTS extensions)
list(APPEND CMAKE_MESSAGE_CONTEXT "${extension}")

message(CHECK_START "Configuring extension ${extension}")
list(APPEND CMAKE_MESSAGE_INDENT " ")

add_subdirectory("${extension}")

php_extensions_postconfigure("${extension}")

list(POP_BACK CMAKE_MESSAGE_INDENT)
if(TARGET php_${extension})
set_property(GLOBAL APPEND PROPERTY PHP_EXTENSIONS ${extension})

# 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(
php_configuration
INTERFACE
$<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
$<TARGET_PROPERTY:PHP::${extension},INTERFACE_INCLUDE_DIRECTORIES>
)
endif()

target_link_libraries(php_${extension} PRIVATE PHP::configuration)

# Add configuration compile options before the extension compile options.
target_compile_options(
php_${extension}
BEFORE PRIVATE
$<TARGET_PROPERTY:php_configuration,INTERFACE_COMPILE_OPTIONS>
)

add_dependencies(php_${extension} Zend::Zend)
if(NOT TARGET php_${extension})
message(CHECK_FAIL "disabled")
list(POP_BACK CMAKE_MESSAGE_CONTEXT)
continue()
endif()

get_target_property(type php_${extension} TYPE)
if(NOT type MATCHES "^(MODULE|SHARED)_LIBRARY$")
target_link_libraries(php_extensions INTERFACE PHP::${extension})
endif()
set_property(GLOBAL APPEND PROPERTY PHP_EXTENSIONS ${extension})

message(CHECK_PASS "enabled")
add_dependencies(php_${extension} Zend::Zend)

# 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(
php_configuration
INTERFACE
$<COMPILE_ONLY:PHP::${extension}>
)
else()
message(CHECK_FAIL "disabled")
# 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
$<TARGET_PROPERTY:PHP::${extension},INTERFACE_INCLUDE_DIRECTORIES>
)
endif()

target_link_libraries(php_${extension} PRIVATE PHP::configuration)

# Add configuration compile options before the extension compile options.
target_compile_options(
php_${extension}
BEFORE PRIVATE
$<TARGET_PROPERTY:php_configuration,INTERFACE_COMPILE_OPTIONS>
)

get_target_property(type php_${extension} TYPE)
if(NOT type MATCHES "^(MODULE|SHARED)_LIBRARY$")
target_link_libraries(
php_extensions
INTERFACE
# If extension is STATIC library link as whole archive, otherwise link
# normally:
$<IF:$<STREQUAL:$<TARGET_PROPERTY:PHP::${extension},TYPE>,STATIC_LIBRARY>,$<LINK_LIBRARY:WHOLE_ARCHIVE,PHP::${extension}>,PHP::${extension}>
)

target_sources(
php_extensions
INTERFACE
# If extension is OBJECT library:
$<$<STREQUAL:$<TARGET_PROPERTY:PHP::${extension},TYPE>,OBJECT_LIBRARY>:$<TARGET_OBJECTS:PHP::${extension}>>
# If extension and linked target (SAPI) are both STATIC libraries:
$<$<AND:$<STREQUAL:$<TARGET_PROPERTY:TYPE>,STATIC_LIBRARY>,$<STREQUAL:$<TARGET_PROPERTY:PHP::${extension},TYPE>,STATIC_LIBRARY>>:$<TARGET_OBJECTS:PHP::${extension}>>
)
endif()

message(CHECK_PASS "enabled")
list(POP_BACK CMAKE_MESSAGE_CONTEXT)
endforeach()

Expand Down
2 changes: 1 addition & 1 deletion cmake/ext/date/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ add_feature_info(
# Check for headers needed by timelib.
check_include_file(io.h HAVE_IO_H)

add_library(php_date STATIC)
add_library(php_date OBJECT)

target_sources(
php_date
Expand Down
2 changes: 1 addition & 1 deletion cmake/ext/hash/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ if(EXT_HASH_MHASH)
set(PHP_MHASH_BC TRUE)
endif()

add_library(php_hash STATIC)
add_library(php_hash OBJECT)

target_sources(
php_hash
Expand Down
2 changes: 1 addition & 1 deletion cmake/ext/json/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ add_feature_info(
"JavaScript Object Notation"
)

add_library(php_json STATIC)
add_library(php_json OBJECT)

target_sources(
php_json
Expand Down
2 changes: 1 addition & 1 deletion cmake/ext/pcre/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ option(

mark_as_advanced(EXT_PCRE_EXTERNAL EXT_PCRE_JIT)

add_library(php_pcre STATIC)
add_library(php_pcre OBJECT)

target_sources(
php_pcre
Expand Down
2 changes: 1 addition & 1 deletion cmake/ext/random/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ add_feature_info(
"random number generators and functions related to randomness"
)

add_library(php_random STATIC)
add_library(php_random OBJECT)

target_sources(
php_random
Expand Down
2 changes: 1 addition & 1 deletion cmake/ext/reflection/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ add_feature_info(
"reflection API to introspect PHP code"
)

add_library(php_reflection STATIC)
add_library(php_reflection OBJECT)
target_sources(
php_reflection
PRIVATE
Expand Down
2 changes: 1 addition & 1 deletion cmake/ext/spl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ add_feature_info(
"Standard PHP library (SPL)"
)

add_library(php_spl STATIC)
add_library(php_spl OBJECT)

target_sources(
php_spl
Expand Down
2 changes: 1 addition & 1 deletion cmake/ext/standard/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ add_feature_info(
# Add library.
################################################################################

add_library(php_standard STATIC)
add_library(php_standard OBJECT)

target_sources(
php_standard
Expand Down
13 changes: 11 additions & 2 deletions cmake/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ target_link_libraries(
INTERFACE
PHP::configuration
php_main
Zend::Zend
# If Zend is STATIC library link as whole archive, otherwise link normally.
$<IF:$<STREQUAL:$<TARGET_PROPERTY:Zend::Zend,TYPE>,STATIC_LIBRARY>,$<LINK_LIBRARY:WHOLE_ARCHIVE,Zend::Zend>,Zend::Zend>
$<$<TARGET_EXISTS:PHP::windows>::PHP::windows>
PHP::extensions
)
Expand All @@ -176,9 +177,17 @@ 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>

# If Zend is OBJECT library, add library objects as sources.
$<$<STREQUAL:$<TARGET_PROPERTY:Zend::Zend,TYPE>,OBJECT_LIBRARY>:$<TARGET_OBJECTS:Zend::Zend>>

# If Zend is STATIC library, and linking to a STATIC library (SAPI), add
# library objects as sources.
$<$<AND:$<STREQUAL:$<TARGET_PROPERTY:TYPE>,STATIC_LIBRARY>,$<STREQUAL:$<TARGET_PROPERTY:Zend::Zend,TYPE>,STATIC_LIBRARY>>:$<TARGET_OBJECTS:Zend::Zend>>

$<$<TARGET_EXISTS:PHP::windows>:$<TARGET_OBJECTS:PHP::windows>>
)

Expand Down
Loading