@@ -33,8 +33,9 @@ being relative to the current binary directory. If generated files are already
33
33
available (for example, shipped with the released archive), and re2c is not
34
34
found, it will create a target but skip the `re2c` command-line execution.
35
35
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.
38
39
39
40
#### Options
40
41
@@ -46,18 +47,18 @@ generates the lexer right away without creating a target.
46
47
`re2c` command-line invocation. This module provides some sensible defaults.
47
48
48
49
* `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.
52
53
53
54
* `DEPENDS <depends>...` - Optional list of dependent files to regenerate the
54
55
output file.
55
56
56
57
* `COMPUTED_GOTOS <TRUE|FALSE>` - Set to `TRUE` to add the `--computed-gotos`
57
58
(`-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.
61
62
62
63
* `CODEGEN` - Adds the `CODEGEN` option to the `add_custom_command()` call. This
63
64
option is available starting with CMake 3.31 when the policy `CMP0171` is set
@@ -149,7 +150,7 @@ include(PHP/Re2c)
149
150
php_re2c(foo foo.re foo.c OPTIONS $<$<CONFIG:Debug>:--debug-output> -F)
150
151
# When build type is Debug, this will run:
151
152
# 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 ):
153
154
# re2c -F --output foo.c foo.re
154
155
```
155
156
@@ -213,11 +214,13 @@ mark_as_advanced(PHP_RE2C_COMPUTED_GOTOS)
213
214
macro (_php_re2c_config_options)
214
215
if (NOT PHP_RE2C_OPTIONS)
215
216
# 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" )
219
219
set (PHP_RE2C_OPTIONS $<$<CONFIG:Release,MinSizeRel>:--no -debug-info>)
220
+ else ()
221
+ set (PHP_RE2C_OPTIONS --no -debug-info)
220
222
endif ()
223
+ unset (_role)
221
224
222
225
# Suppress date output in the generated file.
223
226
list (APPEND PHP_RE2C_OPTIONS --no -generation-date)
@@ -298,11 +301,13 @@ function(php_re2c name input output)
298
301
find_package (RE2C ${PHP_RE2C_VERSION} ${quiet} )
299
302
endif ()
300
303
304
+ get_property (role GLOBAL PROPERTY CMAKE_ROLE)
305
+
301
306
if (
302
307
NOT RE2C_FOUND
303
308
AND PHP_RE2C_VERSION_DOWNLOAD
304
309
AND packageType STREQUAL "REQUIRED"
305
- AND NOT CMAKE_SCRIPT_MODE_FILE
310
+ AND role STREQUAL "PROJECT"
306
311
)
307
312
_php_re2c_download()
308
313
endif ()
@@ -329,7 +334,7 @@ function(php_re2c name input output)
329
334
_php_re2c_process_options()
330
335
_php_re2c_process_header_option()
331
336
332
- if (NOT CMAKE_SCRIPT_MODE_FILE )
337
+ if (role STREQUAL "PROJECT" )
333
338
add_custom_target (${name} SOURCES ${input} DEPENDS ${outputs} )
334
339
endif ()
335
340
@@ -350,7 +355,7 @@ function(php_re2c name input output)
350
355
)
351
356
set (message "[re2c] Generating ${relativePath} with re2c ${RE2C_VERSION} " )
352
357
353
- if (CMAKE_SCRIPT_MODE_FILE )
358
+ if (NOT role STREQUAL "PROJECT" )
354
359
message (STATUS "${message} " )
355
360
execute_process (${commands} WORKING_DIRECTORY ${parsed_WORKING_DIRECTORY} )
356
361
return ()
@@ -431,7 +436,8 @@ function(_php_re2c_process_options)
431
436
endif ()
432
437
433
438
# 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" )
435
441
list (TRANSFORM options GENEX_STRIP)
436
442
endif ()
437
443
@@ -483,7 +489,8 @@ endfunction()
483
489
484
490
# Check for re2c --computed-gotos option.
485
491
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" )
487
494
set (${result} TRUE )
488
495
return (PROPAGATE ${result} )
489
496
endif ()
0 commit comments