Skip to content

Commit 405f61c

Browse files
authored
Improve naming conventions for extensions (#25)
In CMake there is common issue of naming collisions in extreme cases. There is issue opened upstream about this at: https://gitlab.kitware.com/cmake/cmake/-/issues/22687 Possible target name and cache variable names collisions can happen: - When some project is added with `FetchContent`, as an external project, via `add_subdirectory()` or similar - or the other way around, if PHP would be added via such mechanisms - If some extension would be named `config`, it would collide with global PHP target `php_config` (aliased `PHP::config`). This follows recent PHP SAPI target renames and renames target names for PHP extensions from: `php_<extension_name>` (aliased `PHP::<extension_name>`) to: `php_ext_<extension_name>` (aliased `PHP::ext::<extension_name>`) This adds abbreviated letters to target names to better organize them in various scenarios, while still not increasing usage complexity too much. This is initial refactoring in this direction with further adjustments following up in the future...
1 parent 0f12129 commit 405f61c

File tree

83 files changed

+570
-569
lines changed

Some content is hidden

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

83 files changed

+570
-569
lines changed

cmake/cmake/Testing.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ block()
1818

1919
get_property(extensions GLOBAL PROPERTY PHP_EXTENSIONS)
2020
foreach(extension IN LISTS extensions)
21-
get_target_property(type php_${extension} TYPE)
21+
get_target_property(type php_ext_${extension} TYPE)
2222
if(type MATCHES "^(MODULE|SHARED)_LIBRARY$")
23-
get_target_property(isZendExtension php_${extension} PHP_ZEND_EXTENSION)
23+
get_target_property(isZendExtension php_ext_${extension} PHP_ZEND_EXTENSION)
2424
if(isZendExtension)
2525
list(APPEND options -d zend_extension=${extension})
2626
elseif(NOT extension STREQUAL "dl_test")

cmake/cmake/modules/FindRE2C.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ if(RE2C_ENABLE_DOWNLOAD AND (NOT RE2C_EXECUTABLE OR NOT _re2c_version_valid))
157157
URL https://github.com/skvadrik/re2c/archive/refs/tags/${RE2C_VERSION}.tar.gz
158158
)
159159

160+
message(STATUS "Downloading RE2C")
160161
FetchContent_MakeAvailable(RE2C)
161162

162163
# Set executable to re2c target name.

cmake/cmake/modules/PHP/Extensions.cmake

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ https://bugs.php.net/53141
4545
capabilities.
4646
4747
```cmake
48-
set_target_properties(php_<extension_name> PROPERTIES PHP_ZEND_EXTENSION TRUE)
48+
set_target_properties(php_ext_<extension_name> PROPERTIES PHP_ZEND_EXTENSION TRUE)
4949
```
5050
5151
* `PHP_EXTENSION_<extension>_DEPS`
@@ -195,9 +195,9 @@ function(_php_extensions_parse_dependencies extension result)
195195
# Command invocation:
196196
"add_dependencies[ \t]*\\("
197197
# Target name:
198-
"[ \t\r\n]*php_${extension}[ \t\r\n]+"
198+
"[ \t\r\n]*php_ext_${extension}[ \t\r\n]+"
199199
# Dependencies:
200-
"[\"]?(php_[a-zA-Z0-9_; \t\r\n]+)"
200+
"[\"]?(php_ext_[a-zA-Z0-9_; \t\r\n]+)"
201201
)
202202

203203
string(REGEX MATCHALL "${regex}" matches "${content}")
@@ -209,7 +209,7 @@ function(_php_extensions_parse_dependencies extension result)
209209
if(CMAKE_MATCH_1)
210210
string(STRIP "${CMAKE_MATCH_1}" dependencies)
211211
string(REPLACE " " ";" dependencies "${dependencies}")
212-
list(TRANSFORM dependencies REPLACE "^php_" "")
212+
list(TRANSFORM dependencies REPLACE "^php_ext_" "")
213213
list(APPEND allDependencies ${dependencies})
214214
endif()
215215
endif()
@@ -364,17 +364,17 @@ endfunction()
364364

365365
# Postconfigure extension right after it has been configured.
366366
function(php_extensions_postconfigure extension)
367-
if(NOT TARGET php_${extension})
367+
if(NOT TARGET php_ext_${extension})
368368
return()
369369
endif()
370370

371371
# If extension is enabled, enable also all its dependencies.
372372
get_target_property(
373373
dependencies
374-
php_${extension}
374+
php_ext_${extension}
375375
MANUALLY_ADDED_DEPENDENCIES
376376
)
377-
list(TRANSFORM dependencies REPLACE "^php_" "")
377+
list(TRANSFORM dependencies REPLACE "^php_ext_" "")
378378
get_property(alwaysEnabledExtensions GLOBAL PROPERTY PHP_ALWAYS_ENABLED_EXTENSIONS)
379379
get_property(allExtensions GLOBAL PROPERTY PHP_ALL_EXTENSIONS)
380380

@@ -409,18 +409,18 @@ function(php_extensions_postconfigure extension)
409409
endif()
410410
endforeach()
411411

412-
if(NOT TARGET PHP::${extension})
413-
add_library(PHP::${extension} ALIAS php_${extension})
412+
if(NOT TARGET PHP::ext::${extension})
413+
add_library(PHP::ext::${extension} ALIAS php_ext_${extension})
414414
endif()
415415

416416
# Set target output filename to "<extension>".
417-
get_target_property(output php_${extension} OUTPUT_NAME)
417+
get_target_property(output php_ext_${extension} OUTPUT_NAME)
418418
if(NOT output)
419-
set_property(TARGET php_${extension} PROPERTY OUTPUT_NAME ${extension})
419+
set_property(TARGET php_ext_${extension} PROPERTY OUTPUT_NAME ${extension})
420420
endif()
421421

422422
# Specify extension's default installation rules.
423-
get_target_property(sets php_${extension} INTERFACE_HEADER_SETS)
423+
get_target_property(sets php_ext_${extension} INTERFACE_HEADER_SETS)
424424
set(fileSets "")
425425
foreach(set IN LISTS sets)
426426
list(
@@ -433,7 +433,7 @@ function(php_extensions_postconfigure extension)
433433
)
434434
endforeach()
435435
install(
436-
TARGETS php_${extension}
436+
TARGETS php_ext_${extension}
437437
ARCHIVE EXCLUDE_FROM_ALL
438438
RUNTIME
439439
DESTINATION ${PHP_EXTENSION_DIR}
@@ -443,24 +443,24 @@ function(php_extensions_postconfigure extension)
443443
)
444444

445445
# Configure shared extension.
446-
get_target_property(type php_${extension} TYPE)
446+
get_target_property(type php_ext_${extension} TYPE)
447447
if(NOT type MATCHES "^(MODULE|SHARED)_LIBRARY$")
448448
return()
449449
endif()
450450

451-
target_compile_definitions(php_${extension} PRIVATE ZEND_COMPILE_DL_EXT)
451+
target_compile_definitions(php_ext_${extension} PRIVATE ZEND_COMPILE_DL_EXT)
452452

453453
set_target_properties(
454-
php_${extension}
454+
php_ext_${extension}
455455
PROPERTIES
456456
POSITION_INDEPENDENT_CODE ON
457457
)
458458

459459
# Set build-phase location for shared extensions.
460-
get_target_property(location php_${extension} LIBRARY_OUTPUT_DIRECTORY)
460+
get_target_property(location php_ext_${extension} LIBRARY_OUTPUT_DIRECTORY)
461461
if(NOT location)
462462
set_property(
463-
TARGET php_${extension}
463+
TARGET php_ext_${extension}
464464
PROPERTY LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/modules"
465465
)
466466
endif()
@@ -471,13 +471,13 @@ endfunction()
471471
function(php_extensions_configure_headers)
472472
get_property(extensions GLOBAL PROPERTY PHP_EXTENSIONS)
473473
foreach(extension IN LISTS extensions)
474-
if(NOT TARGET php_${extension})
474+
if(NOT TARGET php_ext_${extension})
475475
continue()
476476
endif()
477477

478478
string(TOUPPER "COMPILE_DL_${extension}" macro)
479479

480-
get_target_property(type php_${extension} TYPE)
480+
get_target_property(type php_ext_${extension} TYPE)
481481
if(type MATCHES "^(MODULE|SHARED)_LIBRARY$")
482482
set(${macro} TRUE)
483483
endif()
@@ -492,7 +492,7 @@ function(php_extensions_configure_headers)
492492
"#cmakedefine ${macro} 1\n"
493493
)
494494

495-
get_target_property(binaryDir php_${extension} BINARY_DIR)
495+
get_target_property(binaryDir php_ext_${extension} BINARY_DIR)
496496
set(current "")
497497
if(EXISTS ${binaryDir}/config.h)
498498
file(READ ${binaryDir}/config.h current)
@@ -511,21 +511,21 @@ function(_php_extensions_validate)
511511
list(TRANSFORM extensions REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "")
512512

513513
foreach(extension IN LISTS extensions)
514-
if(NOT TARGET php_${extension})
514+
if(NOT TARGET php_ext_${extension})
515515
continue()
516516
endif()
517517

518518
get_target_property(
519519
dependencies
520-
php_${extension}
520+
php_ext_${extension}
521521
MANUALLY_ADDED_DEPENDENCIES
522522
)
523523

524524
if(NOT dependencies)
525525
continue()
526526
endif()
527527

528-
list(TRANSFORM dependencies REPLACE "^php_" "")
528+
list(TRANSFORM dependencies REPLACE "^php_ext_" "")
529529

530530
get_property(allExtensions GLOBAL PROPERTY PHP_ALL_EXTENSIONS)
531531

@@ -535,7 +535,7 @@ function(_php_extensions_validate)
535535
continue()
536536
endif()
537537

538-
if(NOT TARGET php_${dependency} OR NOT dependency IN_LIST extensions)
538+
if(NOT TARGET php_ext_${dependency} OR NOT dependency IN_LIST extensions)
539539
string(TOUPPER "${dependency}" dependencyUpper)
540540
message(
541541
SEND_ERROR
@@ -546,8 +546,8 @@ function(_php_extensions_validate)
546546
)
547547
endif()
548548

549-
get_target_property(dependencyType php_${dependency} TYPE)
550-
get_target_property(extensionType php_${extension} TYPE)
549+
get_target_property(dependencyType php_ext_${dependency} TYPE)
550+
get_target_property(extensionType php_ext_${extension} TYPE)
551551

552552
if(
553553
dependencyType MATCHES "^(MODULE|SHARED)_LIBRARY$"

cmake/cmake/modules/PHP/FeatureSummary.cmake

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ function(php_feature_summary)
161161
string(PREPEND item " * ")
162162
if(feature MATCHES "^ext/([^ ]+)$")
163163
if(CMAKE_MATCH_1)
164-
get_target_property(type php_${CMAKE_MATCH_1} TYPE)
164+
get_target_property(type php_ext_${CMAKE_MATCH_1} TYPE)
165165
if(type MATCHES "^(MODULE|SHARED)_LIBRARY$")
166166
string(APPEND item " (shared)")
167167
endif()
@@ -207,21 +207,21 @@ function(php_feature_summary)
207207
get_property(extensions GLOBAL PROPERTY PHP_EXTENSIONS)
208208

209209
foreach(extension IN LISTS extensions)
210-
if(NOT TARGET php_${extension})
210+
if(NOT TARGET php_ext_${extension})
211211
continue()
212212
endif()
213213

214214
get_target_property(
215215
dependencies
216-
php_${extension}
216+
php_ext_${extension}
217217
MANUALLY_ADDED_DEPENDENCIES
218218
)
219219

220220
if(NOT dependencies)
221221
continue()
222222
endif()
223223

224-
list(TRANSFORM dependencies REPLACE "^php_" "")
224+
list(TRANSFORM dependencies REPLACE "^php_ext_" "")
225225

226226
get_property(allExtensions GLOBAL PROPERTY PHP_ALL_EXTENSIONS)
227227

@@ -231,14 +231,14 @@ function(php_feature_summary)
231231
continue()
232232
endif()
233233

234-
if(NOT TARGET php_${dependency} OR NOT dependency IN_LIST extensions)
234+
if(NOT TARGET php_ext_${dependency} OR NOT dependency IN_LIST extensions)
235235
list(APPEND missingExtensions ${dependency})
236236
list(APPEND _phpFeatureSummaryReason_${dependency} ${extension})
237237
continue()
238238
endif()
239239

240-
get_target_property(dependencyType php_${dependency} TYPE)
241-
get_target_property(extensionType php_${extension} TYPE)
240+
get_target_property(dependencyType php_ext_${dependency} TYPE)
241+
get_target_property(extensionType php_ext_${extension} TYPE)
242242

243243
if(
244244
dependencyType MATCHES "^(MODULE|SHARED)_LIBRARY$"

cmake/ext/CMakeLists.txt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,63 +62,63 @@ foreach(extension IN LISTS extensions)
6262
php_extensions_postconfigure("${extension}")
6363
list(POP_BACK CMAKE_MESSAGE_INDENT)
6464

65-
if(NOT TARGET php_${extension})
65+
if(NOT TARGET php_ext_${extension})
6666
message(CHECK_FAIL "disabled")
6767
list(POP_BACK CMAKE_MESSAGE_CONTEXT)
6868
continue()
6969
endif()
7070

7171
set_property(GLOBAL APPEND PROPERTY PHP_EXTENSIONS ${extension})
7272

73-
add_dependencies(php_${extension} Zend::Zend)
73+
add_dependencies(php_ext_${extension} Zend::Zend)
7474

7575
# Add usage requirements to PHP interface targets.
7676
# TODO: Should PHP_CLI extensions pass properties only to PHP_CLI SAPIs?
77-
get_target_property(type php_${extension} TYPE)
77+
get_target_property(type php_ext_${extension} TYPE)
7878
if(NOT type MATCHES "^(MODULE|SHARED)_LIBRARY$")
7979
target_compile_definitions(
8080
php_config
8181
INTERFACE
82-
$<TARGET_PROPERTY:PHP::${extension},INTERFACE_COMPILE_DEFINITIONS>
82+
$<TARGET_PROPERTY:PHP::ext::${extension},INTERFACE_COMPILE_DEFINITIONS>
8383
)
8484

8585
target_compile_options(
8686
php_config
8787
INTERFACE
88-
$<TARGET_PROPERTY:PHP::${extension},INTERFACE_COMPILE_OPTIONS>
88+
$<TARGET_PROPERTY:PHP::ext::${extension},INTERFACE_COMPILE_OPTIONS>
8989
)
9090

9191
target_compile_features(
9292
php_config
9393
INTERFACE
94-
$<TARGET_PROPERTY:PHP::${extension},INTERFACE_COMPILE_FEATURES>
94+
$<TARGET_PROPERTY:PHP::ext::${extension},INTERFACE_COMPILE_FEATURES>
9595
)
9696

9797
target_include_directories(
9898
php_config
9999
INTERFACE
100-
$<TARGET_PROPERTY:PHP::${extension},INTERFACE_INCLUDE_DIRECTORIES>
101-
$<TARGET_PROPERTY:PHP::${extension},INTERFACE_SYSTEM_INCLUDE_DIRECTORIES>
100+
$<TARGET_PROPERTY:PHP::ext::${extension},INTERFACE_INCLUDE_DIRECTORIES>
101+
$<TARGET_PROPERTY:PHP::ext::${extension},INTERFACE_SYSTEM_INCLUDE_DIRECTORIES>
102102
)
103103

104104
target_link_libraries(
105105
php_sapi
106106
INTERFACE
107-
$<IF:$<BOOL:$<TARGET_GENEX_EVAL:PHP::${extension},$<TARGET_PROPERTY:PHP::${extension},PHP_CLI>>>,$<$<BOOL:$<TARGET_PROPERTY:PHP_CLI>>:PHP::${extension}>,PHP::${extension}>
107+
$<IF:$<BOOL:$<TARGET_GENEX_EVAL:PHP::ext::${extension},$<TARGET_PROPERTY:PHP::ext::${extension},PHP_CLI>>>,$<$<BOOL:$<TARGET_PROPERTY:PHP_CLI>>:PHP::ext::${extension}>,PHP::ext::${extension}>
108108
)
109109

110110
target_sources(
111111
php_sapi
112112
INTERFACE
113-
$<IF:$<BOOL:$<TARGET_GENEX_EVAL:PHP::${extension},$<TARGET_PROPERTY:PHP::${extension},PHP_CLI>>>,$<$<BOOL:$<TARGET_PROPERTY:PHP_CLI>>:$<TARGET_OBJECTS:PHP::${extension}>>,$<TARGET_OBJECTS:PHP::${extension}>>
113+
$<IF:$<BOOL:$<TARGET_GENEX_EVAL:PHP::ext::${extension},$<TARGET_PROPERTY:PHP::ext::${extension},PHP_CLI>>>,$<$<BOOL:$<TARGET_PROPERTY:PHP_CLI>>:$<TARGET_OBJECTS:PHP::ext::${extension}>>,$<TARGET_OBJECTS:PHP::ext::${extension}>>
114114
)
115115
endif()
116116

117-
target_link_libraries(php_${extension} PRIVATE PHP::config)
117+
target_link_libraries(php_ext_${extension} PRIVATE PHP::config)
118118

119119
# Add configuration compile options before the extension compile options.
120120
target_compile_options(
121-
php_${extension}
121+
php_ext_${extension}
122122
BEFORE PRIVATE
123123
$<TARGET_PROPERTY:PHP::config,INTERFACE_COMPILE_OPTIONS>
124124
)

cmake/ext/bcmath/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ if(NOT EXT_BCMATH)
4949
endif()
5050

5151
if(EXT_BCMATH_SHARED)
52-
add_library(php_bcmath SHARED)
52+
add_library(php_ext_bcmath SHARED)
5353
else()
54-
add_library(php_bcmath)
54+
add_library(php_ext_bcmath)
5555
endif()
5656

5757
target_sources(
58-
php_bcmath
58+
php_ext_bcmath
5959
PRIVATE
6060
bcmath.c
6161
bcmath.stub.php
@@ -82,7 +82,7 @@ target_sources(
8282
libbcmath/src/zero.c
8383
)
8484

85-
target_compile_definitions(php_bcmath PRIVATE ZEND_ENABLE_STATIC_TSRMLS_CACHE)
85+
target_compile_definitions(php_ext_bcmath PRIVATE ZEND_ENABLE_STATIC_TSRMLS_CACHE)
8686

8787
set(HAVE_BCMATH TRUE)
8888

cmake/ext/bz2/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,21 @@ if(NOT EXT_BZ2)
5151
endif()
5252

5353
if(EXT_BZ2_SHARED)
54-
add_library(php_bz2 SHARED)
54+
add_library(php_ext_bz2 SHARED)
5555
else()
56-
add_library(php_bz2)
56+
add_library(php_ext_bz2)
5757
endif()
5858

5959
target_sources(
60-
php_bz2
60+
php_ext_bz2
6161
PRIVATE
6262
bz2_filter.c
6363
bz2.c
6464
bz2.stub.php
6565
)
6666

6767
target_compile_definitions(
68-
php_bz2
68+
php_ext_bz2
6969
PRIVATE
7070
$<$<AND:$<PLATFORM_ID:Windows>,$<IN_LIST:$<TARGET_PROPERTY:TYPE>,MODULE_LIBRARY;SHARED_LIBRARY>>:PHP_BZ2_EXPORTS>
7171
)
@@ -79,7 +79,7 @@ set_package_properties(
7979
)
8080

8181
# Link with PUBLIC scope if include directories are on non-standard places.
82-
target_link_libraries(php_bz2 PUBLIC BZip2::BZip2)
82+
target_link_libraries(php_ext_bz2 PUBLIC BZip2::BZip2)
8383

8484
# Sanity check.
8585
if(TARGET BZip2::BZip2)

0 commit comments

Comments
 (0)