Skip to content

Commit 11e2ad3

Browse files
committed
Moving on
1 parent d7a79ef commit 11e2ad3

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed

cmake/cmake/modules/FindPHP.cmake

+33-16
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ If the `COMPONENTS` are not specified, module by default searches for the
4040
find_package(PHP)
4141
```
4242
43+
The imported targets defined by components are only created when the
44+
`CMAKE_ROLE` global property is `PROJECT`, which enables finding PHP, for
45+
example, in command-line scripts.
46+
4347
### The `Interpreter` component
4448
4549
When this component is found, it defines the following `IMPORTED` targets:
@@ -67,7 +71,7 @@ Cache variables of the `Development` component:
6771
6872
* `PHP_CONFIG_EXECUTABLE` - Path to the `php-config` development command-line
6973
tool.
70-
* `PHP_INCLUDE_DIR` - Directory containing PHP headers.
74+
* `PHP_Development_INCLUDE_DIR` - Directory containing PHP headers.
7175
7276
Result variables of the `Development` component:
7377
@@ -437,16 +441,16 @@ endif()
437441

438442
if("Development" IN_LIST PHP_FIND_COMPONENTS)
439443
find_path(
440-
PHP_INCLUDE_DIR
444+
PHP_Development_INCLUDE_DIR
441445
NAMES main/php.h
442446
HINTS
443447
${PC_PHP_INCLUDE_DIRS}
444448
${PHP_INCLUDE_DIRS}
445449
DOC "Directory containing PHP headers"
446450
)
447-
mark_as_advanced(PHP_INCLUDE_DIR)
451+
mark_as_advanced(PHP_Development_INCLUDE_DIR)
448452

449-
if(NOT PHP_INCLUDE_DIR)
453+
if(NOT PHP_Development_INCLUDE_DIR)
450454
string(APPEND _reason "The <main/php.h> header file not found. ")
451455
endif()
452456

@@ -465,9 +469,9 @@ if("Development" IN_LIST PHP_FIND_COMPONENTS)
465469

466470
# Get PHP API version number.
467471
block(PROPAGATE PHP_API_VERSION)
468-
if(EXISTS ${PHP_INCLUDE_DIR}/main/php.h)
472+
if(EXISTS ${PHP_Development_INCLUDE_DIR}/main/php.h)
469473
set(regex "#[ \t]*define[ \t]+PHP_API_VERSION[ \t]+([0-9]+)")
470-
file(STRINGS ${PHP_INCLUDE_DIR}/main/php.h _ REGEX "${regex}")
474+
file(STRINGS ${PHP_Development_INCLUDE_DIR}/main/php.h _ REGEX "${regex}")
471475

472476
if(CMAKE_VERSION VERSION_LESS 3.29)
473477
string(REGEX MATCH "${regex}" _ "${_}")
@@ -479,9 +483,9 @@ if("Development" IN_LIST PHP_FIND_COMPONENTS)
479483

480484
# Get PHP extensions API version number.
481485
block(PROPAGATE PHP_ZEND_MODULE_API)
482-
if(EXISTS ${PHP_INCLUDE_DIR}/Zend/zend_modules.h)
486+
if(EXISTS ${PHP_Development_INCLUDE_DIR}/Zend/zend_modules.h)
483487
set(regex "#[ \t]*define[ \t]+ZEND_MODULE_API_NO[ \t]+([0-9]+)")
484-
file(STRINGS ${PHP_INCLUDE_DIR}/Zend/zend_modules.h _ REGEX "${regex}")
488+
file(STRINGS ${PHP_Development_INCLUDE_DIR}/Zend/zend_modules.h _ REGEX "${regex}")
485489

486490
if(CMAKE_VERSION VERSION_LESS 3.29)
487491
string(REGEX MATCH "${regex}" _ "${_}")
@@ -493,9 +497,9 @@ if("Development" IN_LIST PHP_FIND_COMPONENTS)
493497

494498
# Get Zend extensions API version number.
495499
block(PROPAGATE PHP_ZEND_EXTENSION_API)
496-
if(EXISTS ${PHP_INCLUDE_DIR}/Zend/zend_extensions.h)
500+
if(EXISTS ${PHP_Development_INCLUDE_DIR}/Zend/zend_extensions.h)
497501
set(regex "#[ \t]*define[ \t]+ZEND_EXTENSION_API_NO[ \t]+([0-9]+)")
498-
file(STRINGS ${PHP_INCLUDE_DIR}/Zend/zend_extensions.h _ REGEX "${regex}")
502+
file(STRINGS ${PHP_Development_INCLUDE_DIR}/Zend/zend_extensions.h _ REGEX "${regex}")
499503

500504
if(CMAKE_VERSION VERSION_LESS 3.29)
501505
string(REGEX MATCH "${regex}" _ "${_}")
@@ -539,7 +543,7 @@ if("Development" IN_LIST PHP_FIND_COMPONENTS)
539543
var IN ITEMS
540544
PHP_API_VERSION
541545
PHP_EXTENSION_DIR
542-
PHP_INCLUDE_DIR
546+
PHP_Development_INCLUDE_DIR
543547
PHP_ZEND_EXTENSION_API
544548
PHP_ZEND_MODULE_API
545549
)
@@ -574,6 +578,7 @@ if("Embed" IN_LIST PHP_FIND_COMPONENTS)
574578
string(APPEND _reason "The <sapi/embed/php_embed.h> header file not found. ")
575579
endif()
576580

581+
# TODO: When CMAKE_ROLE is not PROJECT, CMake doesn't set search paths.
577582
find_library(
578583
PHP_EMBED_LIBRARY
579584
NAMES php
@@ -653,8 +658,8 @@ block(PROPAGATE PHP_FOUND_VERSION _reason)
653658
endif()
654659

655660
set(includeDir "")
656-
if(NOT PHP_FOUND_VERSION AND PHP_INCLUDE_DIR)
657-
set(includeDir ${PHP_INCLUDE_DIR})
661+
if(NOT PHP_FOUND_VERSION AND PHP_Development_INCLUDE_DIR)
662+
set(includeDir ${PHP_Development_INCLUDE_DIR})
658663
elseif(NOT PHP_FOUND_VERSION AND PHP_EMBED_INCLUDE_DIR)
659664
set(includeDir ${PHP_EMBED_INCLUDE_DIR})
660665
endif()
@@ -732,11 +737,17 @@ if(NOT PHP_FOUND)
732737
return()
733738
endif()
734739

740+
get_property(_phpRole GLOBAL PROPERTY CMAKE_ROLE)
741+
735742
################################################################################
736743
# Interpreter component configuration.
737744
################################################################################
738745

739-
if("Interpreter" IN_LIST PHP_FIND_COMPONENTS AND NOT TARGET PHP::Interpreter)
746+
if(
747+
_phpRole STREQUAL "PROJECT"
748+
AND "Interpreter" IN_LIST PHP_FIND_COMPONENTS
749+
AND NOT TARGET PHP::Interpreter
750+
)
740751
add_executable(PHP::Interpreter IMPORTED)
741752
set_target_properties(
742753
PHP::Interpreter
@@ -749,7 +760,7 @@ endif()
749760
# Development component configuration.
750761
################################################################################
751762

752-
if("Development" IN_LIST PHP_FIND_COMPONENTS)
763+
if(_phpRole STREQUAL "PROJECT" AND "Development" IN_LIST PHP_FIND_COMPONENTS)
753764
if(NOT TARGET PHP::Development)
754765
add_library(PHP::Development INTERFACE IMPORTED)
755766

@@ -848,7 +859,11 @@ endif()
848859
# Embed component configuration.
849860
################################################################################
850861

851-
if("Embed" IN_LIST PHP_FIND_COMPONENTS AND NOT TARGET PHP::Embed)
862+
if(
863+
_phpRole STREQUAL "PROJECT"
864+
AND "Embed" IN_LIST PHP_FIND_COMPONENTS
865+
AND NOT TARGET PHP::Embed
866+
)
852867
if(IS_ABSOLUTE "${PHP_EMBED_LIBRARY}")
853868
add_library(PHP::Embed UNKNOWN IMPORTED)
854869
set_target_properties(
@@ -872,3 +887,5 @@ if("Embed" IN_LIST PHP_FIND_COMPONENTS AND NOT TARGET PHP::Embed)
872887
INTERFACE_INCLUDE_DIRECTORIES "${PHP_INCLUDE_DIRS}"
873888
)
874889
endif()
890+
891+
unset(_phpRole)

cmake/ext/skeleton/CMakeLists.txt.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ include(CMakeDependentOption)
4747
# Include CMake module to use add_feature_info() and set_package_properties().
4848
include(FeatureSummary)
4949

50-
# Set GNU standard installation directories.
50+
# Define GNU standard installation directories.
5151
include(GNUInstallDirs)
5252

5353
# Boolean option that enables (ON) or disables (OFF) the extension. For example,

0 commit comments

Comments
 (0)