@@ -78,57 +78,73 @@ add_library(PHP::extensions ALIAS php_extensions)
7878# Add subdirectories of extensions.
7979foreach (extension IN LISTS extensions)
8080 list (APPEND CMAKE_MESSAGE_CONTEXT "${extension} " )
81+
8182 message (CHECK_START "Configuring extension ${extension} " )
8283 list (APPEND CMAKE_MESSAGE_INDENT " " )
83-
8484 add_subdirectory ("${extension} " )
85-
8685 php_extensions_postconfigure("${extension} " )
87-
8886 list (POP_BACK CMAKE_MESSAGE_INDENT)
89- if (TARGET php_${extension} )
90- set_property (GLOBAL APPEND PROPERTY PHP_EXTENSIONS ${extension} )
91-
92- # Add extension's PUBLIC/INTERFACE compile properties to configuration.
93- # Cleaner COMPILE_ONLY generator expression is available in CMake >= 3.27.
94- if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.27)
95- target_link_libraries (
96- php_configuration
97- INTERFACE
98- $<COMPILE_ONLY:PHP::${extension} >
99- )
100- else ()
101- # TODO: Fix this better. Either require 3.27, or limit/adjust compile
102- # properties propagated globally. Also, shared extensions shouldn't
103- # propagate globally.
104- # https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#id36
105- target_include_directories (
106- php_configuration
107- INTERFACE
108- $<TARGET_PROPERTY:PHP::${extension} ,INTERFACE_INCLUDE_DIRECTORIES >
109- )
110- endif ()
111-
112- target_link_libraries (php_${extension} PRIVATE PHP::configuration )
113-
114- # Add configuration compile options before the extension compile options.
115- target_compile_options (
116- php_${extension}
117- BEFORE PRIVATE
118- $<TARGET_PROPERTY:php_configuration,INTERFACE_COMPILE_OPTIONS>
119- )
12087
121- add_dependencies (php_${extension} Zend::Zend)
88+ if (NOT TARGET php_${extension} )
89+ message (CHECK_FAIL "disabled" )
90+ list (POP_BACK CMAKE_MESSAGE_CONTEXT)
91+ continue ()
92+ endif ()
12293
123- get_target_property (type php_${extension} TYPE )
124- if (NOT type MATCHES "^(MODULE|SHARED)_LIBRARY$" )
125- target_link_libraries (php_extensions INTERFACE PHP::${extension} )
126- endif ()
94+ set_property (GLOBAL APPEND PROPERTY PHP_EXTENSIONS ${extension} )
12795
128- message (CHECK_PASS "enabled" )
96+ add_dependencies (php_${extension} Zend::Zend)
97+
98+ # Add extension's PUBLIC/INTERFACE compile properties to configuration.
99+ # Cleaner COMPILE_ONLY generator expression is available in CMake >= 3.27.
100+ if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.27)
101+ target_link_libraries (
102+ php_configuration
103+ INTERFACE
104+ $<COMPILE_ONLY:PHP::${extension} >
105+ )
129106 else ()
130- message (CHECK_FAIL "disabled" )
107+ # TODO: Fix this better. Either require 3.27, or limit/adjust compile
108+ # properties propagated globally. Also, shared extensions shouldn't
109+ # propagate globally.
110+ # https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#id36
111+ target_include_directories (
112+ php_configuration
113+ INTERFACE
114+ $<TARGET_PROPERTY:PHP::${extension} ,INTERFACE_INCLUDE_DIRECTORIES >
115+ )
116+ endif ()
117+
118+ target_link_libraries (php_${extension} PRIVATE PHP::configuration )
119+
120+ # Add configuration compile options before the extension compile options.
121+ target_compile_options (
122+ php_${extension}
123+ BEFORE PRIVATE
124+ $<TARGET_PROPERTY:php_configuration,INTERFACE_COMPILE_OPTIONS>
125+ )
126+
127+ get_target_property (type php_${extension} TYPE )
128+ if (NOT type MATCHES "^(MODULE|SHARED)_LIBRARY$" )
129+ target_link_libraries (
130+ php_extensions
131+ INTERFACE
132+ # If extension is STATIC library link as whole archive, otherwise link
133+ # normally:
134+ $<IF:$<STREQUAL :$<TARGET_PROPERTY:PHP::${extension} ,TYPE >,STATIC_LIBRARY>,$<LINK_LIBRARY:WHOLE_ARCHIVE,PHP::${extension} >,PHP::${extension} >
135+ )
136+
137+ target_sources (
138+ php_extensions
139+ INTERFACE
140+ # If extension is OBJECT library:
141+ $<$<STREQUAL :$<TARGET_PROPERTY:PHP::${extension} ,TYPE >,OBJECT_LIBRARY>:$<TARGET_OBJECTS:PHP::${extension} >>
142+ # If extension and linked target (SAPI) are both STATIC libraries:
143+ $<$<AND :$<STREQUAL :$<TARGET_PROPERTY:TYPE >,STATIC_LIBRARY>,$<STREQUAL :$<TARGET_PROPERTY:PHP::${extension} ,TYPE >,STATIC_LIBRARY>>:$<TARGET_OBJECTS:PHP::${extension} >>
144+ )
131145 endif ()
146+
147+ message (CHECK_PASS "enabled" )
132148 list (POP_BACK CMAKE_MESSAGE_CONTEXT)
133149endforeach ()
134150
0 commit comments