Skip to content

Replace FindPHPSystem.cmake with FindPHP.cmake #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: PHP-8.3
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,16 @@ jobs:
- name: Run tests
run: |
ctest --preset all-enabled

- name: Install PHP
run: |
cmake --install php-build/all-enabled

- name: Setup shared standalone extension
run: |
php php-build/all-enabled/php-src/ext/ext_skel.php --ext phantom
cd php-build/all-enabled/php-src/ext/phantom
cmake -B cmake-build
cmake --build cmake-build -j
cmake --install cmake-build
php -d extension=phantom -m | grep phantom
5 changes: 4 additions & 1 deletion cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ block()
endforeach()
endblock()

# Configure PHP installation.
include(cmake/installation/Install.cmake)

# Rebuild all targets as needed.
if(NOT PHPSystem_EXECUTABLE)
if(NOT PHP_FOUND)
include(PHP/Rebuild)
endif()

Expand Down
14 changes: 8 additions & 6 deletions cmake/cmake/Requirements.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ endif()
find_package(Sendmail)

################################################################################
# Find PHP installed on the system for generating stub files (*_arginfo.h),
# Zend/zend_vm_gen.php, ext/tokenizer/tokenizer_data_gen.php and similar where
# it can be used. Otherwise the built cli sapi is used at the build phase.
# Minimum supported version for gen_stub.php is PHP 7.4.
################################################################################
find_package(PHPSystem 7.4)
# Find PHP installed on the system and set PHP_EXECUTABLE for development such
# as generating stubs (*_arginfo.h) with build/gen_stub.php, running PHP scripts
# Zend/zend_vm_gen.php and similar. Otherwise the sapi/cli executable will be
# used at the build phase, where possible. The minimum version should match the
# version required to run these PHP scripts.
################################################################################
find_package(PHP 7.4 COMPONENTS Interpreter)
set(CMAKE_DISABLE_FIND_PACKAGE_PHP TRUE)
64 changes: 64 additions & 0 deletions cmake/cmake/installation/Install.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
include_guard(GLOBAL)

if(NOT PROJECT_NAME STREQUAL "PHP")
message(
AUTHOR_WARNING
"${CMAKE_CURRENT_LIST_FILE} should be used in the project(PHP) scope."
)
return()
endif()

include(CMakePackageConfigHelpers)

write_basic_package_version_file(
PHPConfigVersion.cmake
COMPATIBILITY AnyNewerVersion
)

set(INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR}/${PHP_INCLUDE_PREFIX})

configure_package_config_file(
cmake/installation/PHPConfig.cmake.in
PHPConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/PHP
PATH_VARS
INSTALL_INCLUDE_DIR
)

add_library(php_development INTERFACE)
add_library(PHP::Development ALIAS php_development)
set_target_properties(php_development PROPERTIES EXPORT_NAME Development)
target_include_directories(
php_development
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/main>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Zend>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/TSRM>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PHP_INCLUDE_PREFIX}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PHP_INCLUDE_PREFIX}/main>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PHP_INCLUDE_PREFIX}/Zend>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PHP_INCLUDE_PREFIX}/TSRM>
)
set_target_properties(php_development PROPERTIES EXPORT_NAME Development)

install(
TARGETS php_development
EXPORT PHP::Development
)

install(
EXPORT PHP::Development
FILE PHP_Development.cmake
NAMESPACE PHP::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/PHP
COMPONENT PHP::Development
)

install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/PHPConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/PHPConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/PHP
COMPONENT PHP::Development
)
49 changes: 49 additions & 0 deletions cmake/cmake/installation/PHPConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
if(CMAKE_VERSION VERSION_LESS 3.25)
set(
${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE
"PHP ${${CMAKE_FIND_PACKAGE_NAME}_VERSION} requires CMake 3.25 or later."
)
set(${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE)
return()
endif()

cmake_minimum_required(VERSION 3.25...3.31)

# Set PHP components.
if(${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS)
set(
${CMAKE_FIND_PACKAGE_NAME}_components
${${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS}
)
else()
# No components given, look for default components.
set(${CMAKE_FIND_PACKAGE_NAME}_components Interpreter)
endif()

# Ensure all required components are available before trying to load any.
foreach(component IN LISTS ${CMAKE_FIND_PACKAGE_NAME}_components)
if(
${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED_${component}
AND NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/PHP_${component}.cmake
)
set(
${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE
"PHP doesn't have the required component installed: ${component}"
)
set(${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE)

return()
endif()
endforeach()

foreach(component IN LISTS ${CMAKE_FIND_PACKAGE_NAME}_components)
# All required components are known to exist. The OPTIONAL keyword allows the
# non-required components to be missing without error.
include(${CMAKE_CURRENT_LIST_DIR}/PHP_${component}.cmake OPTIONAL)
endforeach()

@PACKAGE_INIT@

set_and_check(PHP_INCLUDE_DIR "@PACKAGE_INSTALL_INCLUDE_DIR@")

check_required_components(${CMAKE_FIND_PACKAGE_NAME})
Loading
Loading