Skip to content

Commit 34052f5

Browse files
committed
Add initial installation configuration
This is initial installation using CMake's exports which enables finding PHP package with find_package(PHP), when installed with CMake and not using a local FindPHP.cmake module. Added extensions configuration for building within php-src and as standalone. Added also initial experimental CPS installation.
1 parent 222b447 commit 34052f5

File tree

94 files changed

+896
-119
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+896
-119
lines changed

.github/workflows/ci.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,18 @@ jobs:
139139
- name: Install PHP
140140
run: cmake --install php-build/all-enabled
141141

142+
- name: Setup shared standalone extension
143+
run: |
144+
php php-src/ext/ext_skel.php --ext phantom
145+
cd php-src/ext/phantom
146+
cmake \
147+
-B cmake-build \
148+
-DPHP_EXT_PHANTOM=ON \
149+
-DPHP_EXT_PHANTOM_SHARED=ON
150+
cmake --build cmake-build -j
151+
cmake --install cmake-build
152+
php -d extension=phantom -m | grep phantom
153+
142154
windows:
143155
runs-on: windows-latest
144156
name: Windows

cmake/CMakeLists.txt

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,114 @@ if(NOT PHP_HOST_FOUND)
168168
include(cmake/Rebuild.cmake)
169169
endif()
170170

171+
################################################################################
172+
# Configure PHP installation.
173+
################################################################################
174+
175+
include(CMakePackageConfigHelpers)
176+
177+
write_basic_package_version_file(
178+
PHPConfigVersion.cmake
179+
VERSION "${PHP_VERSION}" # Set explicitly so also PHP_VERSION_LABEL is added.
180+
COMPATIBILITY AnyNewerVersion
181+
)
182+
183+
configure_package_config_file(
184+
cmake/PHPConfig.cmake.in
185+
PHPConfig.cmake
186+
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/PHP
187+
PATH_VARS
188+
PHP_EXTENSION_DIR
189+
PHP_INSTALL_INCLUDEDIR
190+
)
191+
192+
add_library(php_extension INTERFACE)
193+
add_library(PHP::Extension ALIAS php_extension)
194+
set_target_properties(php_extension PROPERTIES EXPORT_NAME Extension)
195+
target_include_directories(
196+
php_extension
197+
INTERFACE
198+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
199+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/main>
200+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/TSRM>
201+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Zend>
202+
$<INSTALL_INTERFACE:${PHP_INSTALL_INCLUDEDIR}>
203+
$<INSTALL_INTERFACE:${PHP_INSTALL_INCLUDEDIR}/main>
204+
$<INSTALL_INTERFACE:${PHP_INSTALL_INCLUDEDIR}/TSRM>
205+
$<INSTALL_INTERFACE:${PHP_INSTALL_INCLUDEDIR}/Zend>
206+
)
207+
target_compile_definitions(
208+
php_extension
209+
INTERFACE
210+
$<INSTALL_INTERFACE:HAVE_CONFIG_H;ZEND_COMPILE_DL_EXT>
211+
$<BUILD_INTERFACE:$<$<IN_LIST:$<TARGET_PROPERTY:TYPE>,MODULE_LIBRARY;SHARED_LIBRARY>:ZEND_COMPILE_DL_EXT>>
212+
)
213+
214+
install(
215+
TARGETS php_extension
216+
EXPORT php_development_export
217+
)
218+
219+
install(
220+
EXPORT php_development_export
221+
NAMESPACE PHP::
222+
FILE PHPDevelopmentTargets.cmake
223+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/PHP/targets
224+
COMPONENT php-development
225+
)
226+
227+
install(
228+
FILES
229+
${CMAKE_CURRENT_BINARY_DIR}/PHPConfig.cmake
230+
${CMAKE_CURRENT_BINARY_DIR}/PHPConfigVersion.cmake
231+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/PHP
232+
COMPONENT php-development
233+
)
234+
235+
install(
236+
FILES
237+
${CMAKE_CURRENT_SOURCE_DIR}/CODING_STANDARDS.md
238+
${CMAKE_CURRENT_SOURCE_DIR}/EXTENSIONS
239+
${CMAKE_CURRENT_SOURCE_DIR}/LICENSE
240+
${CMAKE_CURRENT_SOURCE_DIR}/NEWS
241+
${CMAKE_CURRENT_SOURCE_DIR}/README.md
242+
${CMAKE_CURRENT_SOURCE_DIR}/README.REDIST.BINS
243+
${CMAKE_CURRENT_SOURCE_DIR}/UPGRADING
244+
${CMAKE_CURRENT_SOURCE_DIR}/UPGRADING.INTERNALS
245+
TYPE DOC
246+
COMPONENT php-doc
247+
)
248+
249+
install(
250+
DIRECTORY cmake/modules
251+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/PHP
252+
COMPONENT php-development
253+
PATTERN "FindPHP.cmake" EXCLUDE
254+
)
255+
256+
set(CMAKE_EXPERIMENTAL_EXPORT_PACKAGE_INFO "b80be207-778e-46ba-8080-b23bba22639e")
257+
258+
install(
259+
PACKAGE_INFO PHP
260+
EXPORT php_development_export
261+
)
262+
263+
################################################################################
171264
# Enable testing and configure test settings.
265+
################################################################################
266+
172267
include(cmake/Testing.cmake)
173268

269+
################################################################################
174270
# Enable and configure CPack module.
271+
################################################################################
272+
175273
include(cmake/CPack.cmake)
176274

275+
################################################################################
177276
# Print build configuration summary.
277+
################################################################################
278+
178279
include(cmake/Summary.cmake)
179280

180281
message(

cmake/Zend/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ target_include_directories(
378378
php_zend
379379
INTERFACE
380380
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../TSRM>
381-
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PHP_INCLUDE_PREFIX}/TSRM>
381+
$<INSTALL_INTERFACE:${PHP_INSTALL_INCLUDEDIR}/TSRM>
382382
)
383383

384384
target_compile_definitions(
@@ -389,7 +389,7 @@ target_compile_definitions(
389389
install(
390390
TARGETS php_zend
391391
FILE_SET tsrm
392-
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PHP_INCLUDE_PREFIX}/TSRM
392+
DESTINATION ${PHP_INSTALL_INCLUDEDIR}/TSRM
393393
COMPONENT php-development
394394
)
395395

@@ -535,9 +535,9 @@ install(
535535
TARGETS php_zend
536536
ARCHIVE EXCLUDE_FROM_ALL
537537
FILE_SET HEADERS
538-
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PHP_INCLUDE_PREFIX}/Zend
538+
DESTINATION ${PHP_INSTALL_INCLUDEDIR}/Zend
539539
COMPONENT php-development
540540
FILE_SET generated
541-
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PHP_INCLUDE_PREFIX}/Zend
541+
DESTINATION ${PHP_INSTALL_INCLUDEDIR}/Zend
542542
COMPONENT php-development
543543
)

cmake/cmake/Configuration.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ set(
8484
VALUE "php"
8585
)
8686
mark_as_advanced(PHP_INCLUDE_PREFIX)
87+
set(PHP_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR}/${PHP_INCLUDE_PREFIX})
8788

8889
set(
8990
CACHE{PHP_CONFIG_FILE_SCAN_DIR}

cmake/cmake/Extensions.cmake

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -393,50 +393,12 @@ function(php_extensions_postconfigure extension)
393393
endif()
394394
endforeach()
395395

396-
if(NOT TARGET PHP::ext::${extension})
397-
add_library(PHP::ext::${extension} ALIAS php_ext_${extension})
398-
endif()
399-
400-
# Set target output filename to "<extension>".
401-
get_target_property(output php_ext_${extension} OUTPUT_NAME)
402-
if(NOT output)
403-
set_property(TARGET php_ext_${extension} PROPERTY OUTPUT_NAME ${extension})
404-
endif()
405-
406-
# Specify extension's default installation rules.
407-
get_target_property(sets php_ext_${extension} INTERFACE_HEADER_SETS)
408-
set(file_sets "")
409-
foreach(set IN LISTS sets)
410-
list(
411-
APPEND
412-
file_sets
413-
FILE_SET
414-
${set}
415-
DESTINATION
416-
${CMAKE_INSTALL_INCLUDEDIR}/${PHP_INCLUDE_PREFIX}/ext/${extension}
417-
COMPONENT php-development
418-
)
419-
endforeach()
420-
install(
421-
TARGETS php_ext_${extension}
422-
ARCHIVE EXCLUDE_FROM_ALL
423-
RUNTIME
424-
DESTINATION ${PHP_EXTENSION_DIR}
425-
COMPONENT php
426-
LIBRARY
427-
DESTINATION ${PHP_EXTENSION_DIR}
428-
COMPONENT php
429-
${file_sets}
430-
)
431-
432396
# Configure shared extension.
433397
get_target_property(type php_ext_${extension} TYPE)
434398
if(NOT type MATCHES "^(MODULE|SHARED)_LIBRARY$")
435399
return()
436400
endif()
437401

438-
target_compile_definitions(php_ext_${extension} PRIVATE ZEND_COMPILE_DL_EXT)
439-
440402
# Set build-phase location for shared extensions.
441403
get_target_property(location php_ext_${extension} LIBRARY_OUTPUT_DIRECTORY)
442404
if(NOT location)
@@ -456,48 +418,6 @@ function(php_extensions_postconfigure extension)
456418
endif()
457419
endfunction()
458420

459-
# Prepend COMPILE_DL_<EXTENSION> macros to extensions configuration headers and
460-
# define them for shared extensions.
461-
function(php_extensions_configure_headers)
462-
get_property(extensions GLOBAL PROPERTY PHP_EXTENSIONS)
463-
foreach(extension IN LISTS extensions)
464-
if(NOT TARGET php_ext_${extension})
465-
continue()
466-
endif()
467-
468-
string(TOUPPER "COMPILE_DL_${extension}" macro)
469-
470-
get_target_property(type php_ext_${extension} TYPE)
471-
if(type MATCHES "^(MODULE|SHARED)_LIBRARY$")
472-
set(${macro} TRUE)
473-
else()
474-
set(${macro} FALSE)
475-
endif()
476-
477-
# Prepare config.h template.
478-
string(
479-
JOIN
480-
""
481-
template
482-
"/* Define to 1 if the PHP extension '@extension@' is built as a dynamic "
483-
"module. */\n"
484-
"#cmakedefine ${macro} 1\n"
485-
)
486-
487-
get_target_property(binary_dir php_ext_${extension} BINARY_DIR)
488-
set(current "")
489-
if(EXISTS ${binary_dir}/config.h)
490-
file(READ ${binary_dir}/config.h current)
491-
endif()
492-
493-
# Finalize extension's config.h header file.
494-
if(NOT current MATCHES "(#undef|#define) ${macro}")
495-
string(STRIP "${template}\n${current}" config)
496-
file(CONFIGURE OUTPUT ${binary_dir}/config.h CONTENT "${config}\n")
497-
endif()
498-
endforeach()
499-
endfunction()
500-
501421
# Validate extensions and their dependencies defined via add_dependencies().
502422
function(_php_extensions_validate)
503423
get_directory_property(extensions SUBDIRECTORIES)

0 commit comments

Comments
 (0)