Skip to content

Commit dbf518c

Browse files
committed
Fix nits
- Using CMAKE_ROLE global property where possible - Some generated files are now created with configure to pass less variables to command-line scripts
1 parent 36eb009 commit dbf518c

File tree

7 files changed

+66
-70
lines changed

7 files changed

+66
-70
lines changed

cmake/Zend/cmake/GenerateGrammar.cmake

+5-6
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ block()
4141
[[
4242
foreach(
4343
file IN ITEMS
44-
@CMAKE_CURRENT_SOURCE_DIR@/zend_language_parser.h
45-
@CMAKE_CURRENT_SOURCE_DIR@/zend_language_parser.c
44+
zend_language_parser.h
45+
zend_language_parser.c
4646
)
47-
file(READ "${file}" content)
47+
file(READ "@CMAKE_CURRENT_SOURCE_DIR@/${file}" content)
4848
string(
4949
REPLACE
5050
"int zendparse"
@@ -56,9 +56,8 @@ block()
5656
NOT content MATCHES "ZEND_API int zendparse"
5757
AND NOT content STREQUAL "${patchedContent}"
5858
)
59-
cmake_path(GET file FILENAME filename)
60-
message(STATUS "[Zend] Patching ${filename}")
61-
file(WRITE "${file}" "${patchedContent}")
59+
message(STATUS "[Zend] Patching ${file}")
60+
file(WRITE "@CMAKE_CURRENT_SOURCE_DIR@/${file}" "${patchedContent}")
6261
endif()
6362
endforeach()
6463
]]

cmake/cmake/modules/FindDTrace.cmake

+10-13
Original file line numberDiff line numberDiff line change
@@ -189,21 +189,22 @@ function(dtrace_target)
189189

190190
# Generate DTrace header.
191191
file(
192-
GENERATE
192+
CONFIGURE
193193
OUTPUT CMakeFiles/GenerateDTraceHeader.cmake
194194
CONTENT [[
195195
execute_process(
196-
COMMAND ${DTrace_EXECUTABLE}
197-
-s "${parsed_INPUT}"
198-
-h # Generate a SystemTap header file.
199-
-C # Run the cpp preprocessor on the input file.
200-
-o "${parsed_HEADER}" # Name of the output file.
196+
COMMAND "@DTrace_EXECUTABLE@"
197+
-s "@parsed_INPUT@" # Input file.
198+
-h # Generate a SystemTap header file.
199+
-C # Run the C preprocessor (cpp) on the input file.
200+
-o "@parsed_HEADER@" # Output file.
201201
)
202202
# Patch DTrace header.
203-
file(READ "${parsed_HEADER}" content)
203+
file(READ "@parsed_HEADER@" content)
204204
string(REPLACE "PHP_" "DTRACE_" content "${content}")
205-
file(WRITE "${parsed_HEADER}" "${content}")
205+
file(WRITE "@parsed_HEADER@" "${content}")
206206
]]
207+
@ONLY
207208
)
208209
cmake_path(
209210
RELATIVE_PATH
@@ -213,11 +214,7 @@ function(dtrace_target)
213214
)
214215
add_custom_command(
215216
OUTPUT ${parsed_HEADER}
216-
COMMAND ${CMAKE_COMMAND}
217-
-DDTrace_EXECUTABLE=${DTrace_EXECUTABLE}
218-
-Dparsed_HEADER=${parsed_HEADER}
219-
-Dparsed_INPUT=${parsed_INPUT}
220-
-P CMakeFiles/GenerateDTraceHeader.cmake
217+
COMMAND ${CMAKE_COMMAND} -P CMakeFiles/GenerateDTraceHeader.cmake
221218
DEPENDS "${parsed_INPUT}"
222219
COMMENT "[DTrace] Generating ${header}"
223220
VERBATIM

cmake/cmake/modules/FindICU.cmake

-6
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,3 @@ endif()
4040
# Find package with upstream CMake find module. Absolute path prevents the
4141
# maximum nesting/recursion depth error on some systems, like macOS.
4242
include(${CMAKE_ROOT}/Modules/FindICU.cmake)
43-
44-
# Upstream CMake module doesn't mark these as advanced variables.
45-
# https://gitlab.kitware.com/cmake/cmake/-/merge_requests/9199
46-
if(CMAKE_VERSION VERSION_LESS 3.29)
47-
mark_as_advanced(ICU_INCLUDE_DIR)
48-
endif()

cmake/cmake/modules/FindLibXslt.cmake

-6
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,3 @@ set_package_properties(
2424
# Find package with upstream CMake find module. Absolute path prevents the
2525
# maximum nesting/recursion depth error on some systems, like macOS.
2626
include(${CMAKE_ROOT}/Modules/FindLibXslt.cmake)
27-
28-
# Upstream CMake module doesn't mark these as advanced variables.
29-
# https://gitlab.kitware.com/cmake/cmake/-/merge_requests/8807
30-
if(CMAKE_VERSION VERSION_LESS 3.28)
31-
mark_as_advanced(LIBXSLT_EXSLT_INCLUDE_DIR LIBXSLT_LIBRARY)
32-
endif()

cmake/cmake/modules/PHP/Bison.cmake

+20-14
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ being relative to the current binary directory. If generated files are already
3333
available (for example, shipped with the released archive), and Bison is not
3434
found, it will create a target but skip the `bison` command-line execution.
3535
36-
When used in command-line script mode (see `CMAKE_SCRIPT_MODE_FILE`) it
37-
generates the parser right away without creating a target.
36+
When the `CMAKE_ROLE` global property value is not `PROJECT` (running is some
37+
script mode) it generates the files right away without creating a target. For
38+
example, in command-line scripts.
3839
3940
#### Options
4041
@@ -49,9 +50,9 @@ generates the parser right away without creating a target.
4950
`bison` command-line invocation. This module provides some sensible defaults.
5051
5152
* `OPTIONS <options>...` - List of additional options to pass to the `bison`
52-
command-line tool. Supports generator expressions. In script mode
53-
(`CMAKE_SCRIPT_MODE_FILE`) generator expressions are stripped as they can't be
54-
determined.
53+
command-line tool. Supports generator expressions. In script modes
54+
(`CMAKE_ROLE` is not `PROJECT`) generator expressions are stripped as they
55+
can't be determined.
5556
5657
* `DEPENDS <depends>...` - Optional list of dependent files to regenerate the
5758
output file.
@@ -152,7 +153,7 @@ include(PHP/Bison)
152153
php_bison(foo foo.y foo.c OPTIONS $<$<CONFIG:Debug>:--debug> --yacc)
153154
# When build type is Debug, this will run:
154155
# bison --debug --yacc foo.y --output foo.c
155-
# For other build types (including the script mode - CMAKE_SCRIPT_MODE_FILE):
156+
# For other build types, including the script modes (CMAKE_ROLE is not PROJECT):
156157
# bison --yacc foo.y --output foo.c
157158
```
158159
@@ -211,13 +212,15 @@ include(FeatureSummary)
211212

212213
# Configuration after find_package() in this module.
213214
macro(_php_bison_config_options)
214-
# Add --no-lines (-l) option to not output '#line' directives.
215215
if(NOT PHP_BISON_OPTIONS)
216-
if(CMAKE_SCRIPT_MODE_FILE)
217-
set(PHP_BISON_OPTIONS --no-lines)
218-
else()
216+
# Add --no-lines (-l) option to not output '#line' directives.
217+
get_property(_role GLOBAL PROPERTY CMAKE_ROLE)
218+
if(_role STREQUAL "PROJECT")
219219
set(PHP_BISON_OPTIONS $<$<CONFIG:Release,MinSizeRel>:--no-lines>)
220+
else()
221+
set(PHP_BISON_OPTIONS --no-lines)
220222
endif()
223+
unset(_role)
221224

222225
# Report all warnings.
223226
list(APPEND PHP_BISON_OPTIONS -Wall)
@@ -290,11 +293,13 @@ function(php_bison name input output)
290293
find_package(BISON ${PHP_BISON_VERSION} ${quiet})
291294
endif()
292295

296+
get_property(role GLOBAL PROPERTY CMAKE_ROLE)
297+
293298
if(
294299
NOT BISON_FOUND
295300
AND PHP_BISON_VERSION_DOWNLOAD
296301
AND packageType STREQUAL "REQUIRED"
297-
AND NOT CMAKE_SCRIPT_MODE_FILE
302+
AND role STREQUAL "PROJECT"
298303
# TODO: Support for other platforms.
299304
AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux"
300305
)
@@ -324,7 +329,7 @@ function(php_bison name input output)
324329
_php_bison_process_header_option()
325330
_php_bison_process_verbose_option()
326331

327-
if(NOT CMAKE_SCRIPT_MODE_FILE)
332+
if(role STREQUAL "PROJECT")
328333
add_custom_target(${name} SOURCES ${input} DEPENDS ${outputs})
329334
endif()
330335

@@ -344,7 +349,7 @@ function(php_bison name input output)
344349
)
345350
set(message "[Bison] Generating ${relativePath} with Bison ${BISON_VERSION}")
346351

347-
if(CMAKE_SCRIPT_MODE_FILE)
352+
if(NOT role STREQUAL "PROJECT")
348353
message(STATUS "${message}")
349354
execute_process(${commands} WORKING_DIRECTORY ${parsed_WORKING_DIRECTORY})
350355
return()
@@ -389,7 +394,8 @@ function(_php_bison_process_options)
389394
endif()
390395

391396
# Remove any generator expressions when running in script mode.
392-
if(CMAKE_SCRIPT_MODE_FILE)
397+
get_property(role GLOBAL PROPERTY CMAKE_ROLE)
398+
if(NOT role STREQUAL "PROJECT")
393399
list(TRANSFORM options GENEX_STRIP)
394400
endif()
395401

cmake/cmake/modules/PHP/Re2c.cmake

+24-17
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ being relative to the current binary directory. If generated files are already
3333
available (for example, shipped with the released archive), and re2c is not
3434
found, it will create a target but skip the `re2c` command-line execution.
3535
36-
When used in command-line script mode (see `CMAKE_SCRIPT_MODE_FILE`) it
37-
generates the lexer right away without creating a target.
36+
When the `CMAKE_ROLE` global property value is not `PROJECT` (running is some
37+
script mode) it generates the files right away without creating a target. For
38+
example, in command-line scripts.
3839
3940
#### Options
4041
@@ -46,18 +47,18 @@ generates the lexer right away without creating a target.
4647
`re2c` command-line invocation. This module provides some sensible defaults.
4748
4849
* `OPTIONS <options>...` - List of additional options to pass to the `re2c`
49-
command-line tool. Supports generator expressions. In script mode
50-
(`CMAKE_SCRIPT_MODE_FILE`) generator expressions are stripped as they can't be
51-
determined.
50+
command-line tool. Supports generator expressions. In script modes
51+
(`CMAKE_ROLE` is not `PROJECT`) generator expressions are stripped as they
52+
can't be determined.
5253
5354
* `DEPENDS <depends>...` - Optional list of dependent files to regenerate the
5455
output file.
5556
5657
* `COMPUTED_GOTOS <TRUE|FALSE>` - Set to `TRUE` to add the `--computed-gotos`
5758
(`-g`) command-line option if the non-standard C computed goto extension is
58-
supported by the C compiler. When calling `re2c()` in the command-line script
59-
mode (`CMAKE_SCRIPT_MODE`), option is not checked, whether the compiler
60-
supports it and is added unconditionally.
59+
supported by the C compiler. When calling `re2c()` in some script mode
60+
(`CMAKE_ROLE` value other than `PROJECT`), compiler checking is skipped and
61+
option is added unconditionally.
6162
6263
* `CODEGEN` - Adds the `CODEGEN` option to the `add_custom_command()` call. This
6364
option is available starting with CMake 3.31 when the policy `CMP0171` is set
@@ -149,7 +150,7 @@ include(PHP/Re2c)
149150
php_re2c(foo foo.re foo.c OPTIONS $<$<CONFIG:Debug>:--debug-output> -F)
150151
# When build type is Debug, this will run:
151152
# re2c --debug-output -F --output foo.c foo.re
152-
# For other build types (including the script mode - CMAKE_SCRIPT_MODE_FILE):
153+
# For other build types, including the script modes (CMAKE_ROLE is not PROJECT):
153154
# re2c -F --output foo.c foo.re
154155
```
155156
@@ -213,11 +214,13 @@ mark_as_advanced(PHP_RE2C_COMPUTED_GOTOS)
213214
macro(_php_re2c_config_options)
214215
if(NOT PHP_RE2C_OPTIONS)
215216
# Add --no-debug-info (-i) option to not output '#line' directives.
216-
if(CMAKE_SCRIPT_MODE_FILE)
217-
set(PHP_RE2C_OPTIONS --no-debug-info)
218-
else()
217+
get_property(_role GLOBAL PROPERTY CMAKE_ROLE)
218+
if(_role STREQUAL "PROJECT")
219219
set(PHP_RE2C_OPTIONS $<$<CONFIG:Release,MinSizeRel>:--no-debug-info>)
220+
else()
221+
set(PHP_RE2C_OPTIONS --no-debug-info)
220222
endif()
223+
unset(_role)
221224

222225
# Suppress date output in the generated file.
223226
list(APPEND PHP_RE2C_OPTIONS --no-generation-date)
@@ -298,11 +301,13 @@ function(php_re2c name input output)
298301
find_package(RE2C ${PHP_RE2C_VERSION} ${quiet})
299302
endif()
300303

304+
get_property(role GLOBAL PROPERTY CMAKE_ROLE)
305+
301306
if(
302307
NOT RE2C_FOUND
303308
AND PHP_RE2C_VERSION_DOWNLOAD
304309
AND packageType STREQUAL "REQUIRED"
305-
AND NOT CMAKE_SCRIPT_MODE_FILE
310+
AND role STREQUAL "PROJECT"
306311
)
307312
_php_re2c_download()
308313
endif()
@@ -329,7 +334,7 @@ function(php_re2c name input output)
329334
_php_re2c_process_options()
330335
_php_re2c_process_header_option()
331336

332-
if(NOT CMAKE_SCRIPT_MODE_FILE)
337+
if(role STREQUAL "PROJECT")
333338
add_custom_target(${name} SOURCES ${input} DEPENDS ${outputs})
334339
endif()
335340

@@ -350,7 +355,7 @@ function(php_re2c name input output)
350355
)
351356
set(message "[re2c] Generating ${relativePath} with re2c ${RE2C_VERSION}")
352357

353-
if(CMAKE_SCRIPT_MODE_FILE)
358+
if(NOT role STREQUAL "PROJECT")
354359
message(STATUS "${message}")
355360
execute_process(${commands} WORKING_DIRECTORY ${parsed_WORKING_DIRECTORY})
356361
return()
@@ -431,7 +436,8 @@ function(_php_re2c_process_options)
431436
endif()
432437

433438
# Remove any generator expressions when running in script mode.
434-
if(CMAKE_SCRIPT_MODE_FILE)
439+
get_property(role GLOBAL PROPERTY CMAKE_ROLE)
440+
if(NOT role STREQUAL "PROJECT")
435441
list(TRANSFORM options GENEX_STRIP)
436442
endif()
437443

@@ -483,7 +489,8 @@ endfunction()
483489

484490
# Check for re2c --computed-gotos option.
485491
function(_php_re2c_check_computed_gotos result)
486-
if(CMAKE_SCRIPT_MODE_FILE)
492+
get_property(role GLOBAL PROPERTY CMAKE_ROLE)
493+
if(NOT role STREQUAL "PROJECT")
487494
set(${result} TRUE)
488495
return(PROPAGATE ${result})
489496
endif()

cmake/ext/phar/CMakeLists.txt

+7-8
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,12 @@ add_custom_command(
189189

190190
# Set phar.phar permissions.
191191
file(
192-
GENERATE
192+
CONFIGURE
193193
OUTPUT CMakeFiles/PharPermissions.cmake
194-
CONTENT "
194+
CONTENT [[
195195
file(
196196
CHMOD
197-
${CMAKE_CURRENT_BINARY_DIR}/phar.phar
197+
"@CMAKE_CURRENT_BINARY_DIR@/phar.phar"
198198
FILE_PERMISSIONS
199199
OWNER_READ
200200
OWNER_WRITE
@@ -205,15 +205,14 @@ file(
205205
WORLD_READ
206206
WORLD_EXECUTE
207207
)
208-
"
208+
]]
209+
@ONLY
209210
)
210211

211212
add_custom_command(
212213
OUTPUT php_ext_phar_generated_phar
213-
COMMAND
214-
${CMAKE_COMMAND} -P CMakeFiles/PharPermissions.cmake
215-
DEPENDS
216-
${CMAKE_CURRENT_BINARY_DIR}/phar.phar
214+
COMMAND ${CMAKE_COMMAND} -P CMakeFiles/PharPermissions.cmake
215+
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/phar.phar
217216
COMMENT "[ext/phar] Generating ${relativeDir}/phar"
218217
)
219218

0 commit comments

Comments
 (0)