@@ -33,8 +33,9 @@ being relative to the current binary directory. If generated files are already
3333available (for example, shipped with the released archive), and re2c is not
3434found, 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)
149150php_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)
213214macro (_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.
485491function (_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 ()
0 commit comments