@@ -40,6 +40,10 @@ If the `COMPONENTS` are not specified, module by default searches for the
40
40
find_package(PHP)
41
41
```
42
42
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
+
43
47
### The `Interpreter` component
44
48
45
49
When this component is found, it defines the following `IMPORTED` targets:
@@ -67,7 +71,7 @@ Cache variables of the `Development` component:
67
71
68
72
* `PHP_CONFIG_EXECUTABLE` - Path to the `php-config` development command-line
69
73
tool.
70
- * `PHP_INCLUDE_DIR ` - Directory containing PHP headers.
74
+ * `PHP_Development_INCLUDE_DIR ` - Directory containing PHP headers.
71
75
72
76
Result variables of the `Development` component:
73
77
@@ -437,16 +441,16 @@ endif()
437
441
438
442
if ("Development" IN_LIST PHP_FIND_COMPONENTS)
439
443
find_path (
440
- PHP_INCLUDE_DIR
444
+ PHP_Development_INCLUDE_DIR
441
445
NAMES main/php.h
442
446
HINTS
443
447
${PC_PHP_INCLUDE_DIRS}
444
448
${PHP_INCLUDE_DIRS}
445
449
DOC "Directory containing PHP headers"
446
450
)
447
- mark_as_advanced (PHP_INCLUDE_DIR )
451
+ mark_as_advanced (PHP_Development_INCLUDE_DIR )
448
452
449
- if (NOT PHP_INCLUDE_DIR )
453
+ if (NOT PHP_Development_INCLUDE_DIR )
450
454
string (APPEND _reason "The <main/php.h> header file not found. " )
451
455
endif ()
452
456
@@ -465,9 +469,9 @@ if("Development" IN_LIST PHP_FIND_COMPONENTS)
465
469
466
470
# Get PHP API version number.
467
471
block(PROPAGATE PHP_API_VERSION)
468
- if (EXISTS ${PHP_INCLUDE_DIR } /main/php.h)
472
+ if (EXISTS ${PHP_Development_INCLUDE_DIR } /main/php.h)
469
473
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} " )
471
475
472
476
if (CMAKE_VERSION VERSION_LESS 3.29)
473
477
string (REGEX MATCH "${regex} " _ "${_} " )
@@ -479,9 +483,9 @@ if("Development" IN_LIST PHP_FIND_COMPONENTS)
479
483
480
484
# Get PHP extensions API version number.
481
485
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)
483
487
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} " )
485
489
486
490
if (CMAKE_VERSION VERSION_LESS 3.29)
487
491
string (REGEX MATCH "${regex} " _ "${_} " )
@@ -493,9 +497,9 @@ if("Development" IN_LIST PHP_FIND_COMPONENTS)
493
497
494
498
# Get Zend extensions API version number.
495
499
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)
497
501
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} " )
499
503
500
504
if (CMAKE_VERSION VERSION_LESS 3.29)
501
505
string (REGEX MATCH "${regex} " _ "${_} " )
@@ -539,7 +543,7 @@ if("Development" IN_LIST PHP_FIND_COMPONENTS)
539
543
var IN ITEMS
540
544
PHP_API_VERSION
541
545
PHP_EXTENSION_DIR
542
- PHP_INCLUDE_DIR
546
+ PHP_Development_INCLUDE_DIR
543
547
PHP_ZEND_EXTENSION_API
544
548
PHP_ZEND_MODULE_API
545
549
)
@@ -574,6 +578,7 @@ if("Embed" IN_LIST PHP_FIND_COMPONENTS)
574
578
string (APPEND _reason "The <sapi/embed/php_embed.h> header file not found. " )
575
579
endif ()
576
580
581
+ # TODO: When CMAKE_ROLE is not PROJECT, CMake doesn't set search paths.
577
582
find_library (
578
583
PHP_EMBED_LIBRARY
579
584
NAMES php
@@ -653,8 +658,8 @@ block(PROPAGATE PHP_FOUND_VERSION _reason)
653
658
endif ()
654
659
655
660
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 } )
658
663
elseif (NOT PHP_FOUND_VERSION AND PHP_EMBED_INCLUDE_DIR)
659
664
set (includeDir ${PHP_EMBED_INCLUDE_DIR} )
660
665
endif ()
@@ -732,11 +737,17 @@ if(NOT PHP_FOUND)
732
737
return ()
733
738
endif ()
734
739
740
+ get_property (_phpRole GLOBAL PROPERTY CMAKE_ROLE)
741
+
735
742
################################################################################
736
743
# Interpreter component configuration.
737
744
################################################################################
738
745
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
+ )
740
751
add_executable (PHP::Interpreter IMPORTED )
741
752
set_target_properties (
742
753
PHP::Interpreter
@@ -749,7 +760,7 @@ endif()
749
760
# Development component configuration.
750
761
################################################################################
751
762
752
- if ("Development" IN_LIST PHP_FIND_COMPONENTS)
763
+ if (_phpRole STREQUAL "PROJECT" AND "Development" IN_LIST PHP_FIND_COMPONENTS)
753
764
if (NOT TARGET PHP::Development)
754
765
add_library (PHP::Development INTERFACE IMPORTED )
755
766
@@ -848,7 +859,11 @@ endif()
848
859
# Embed component configuration.
849
860
################################################################################
850
861
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
+ )
852
867
if (IS_ABSOLUTE "${PHP_EMBED_LIBRARY} " )
853
868
add_library (PHP::Embed UNKNOWN IMPORTED )
854
869
set_target_properties (
@@ -872,3 +887,5 @@ if("Embed" IN_LIST PHP_FIND_COMPONENTS AND NOT TARGET PHP::Embed)
872
887
INTERFACE_INCLUDE_DIRECTORIES "${PHP_INCLUDE_DIRS} "
873
888
)
874
889
endif ()
890
+
891
+ unset (_phpRole)
0 commit comments