@@ -14,20 +14,20 @@ syntax, e.g. 'find_package(RE2C 0.15.3)'.
1414## Cache variables
1515
1616* `RE2C_EXECUTABLE` - Path to the re2c program. When RE2C is downloaded and
17- built from source as part of the built (using the `ExternalProject` CMake
18- module), this path will be autofilled to the built re2c and will not exist
19- until the build phase.
17+ built from source as part of the build (using the `ExternalProject` CMake
18+ module), this path will be autofilled to point to the built re2c. Note, that
19+ re2c built from source will not exist until the build phase.
2020
2121## Hints
2222
23- * `RE2C_DEFAULT_OPTIONS` - A `;-` list of default global options to pass to re2c
24- for all `re2c_target()` invocations. Set before calling the
25- `find_package(RE2C)`. Options are prepended to additional options passed with
26- `re2c_target()` arguments.
23+ * `RE2C_DEFAULT_OPTIONS` - A semicolon-separated list of default global options
24+ to pass to re2c for all `re2c_target()` invocations. Set before calling the
25+ `find_package(RE2C)`. These options are prepended to additional options passed
26+ as `re2c_target()` arguments.
2727
2828* `RE2C_DISABLE_DOWNLOAD` - This module can also download and build re2c from
2929 its Git repository using the `ExternalProject` module. Set to `TRUE` to
30- disable downloading re2c, when it is not found on the system or system version
30+ disable downloading re2c, when it is not found on the system or found version
3131 is not suitable.
3232
3333* `RE2C_USE_COMPUTED_GOTOS` - Set to `TRUE` before calling `find_package(RE2C)`
@@ -52,7 +52,7 @@ re2c_target(
5252)
5353```
5454
55- This will add a custom command and a custom target `<name>` that generates lexer
55+ This adds a custom target `<name>` and a custom command that generates lexer
5656file `<output>` from the given `<input>` re2c template file using the re2c
5757utility. Relative source file path `<input> is interpreted as being relative to
5858the current source directory. Relative `<output>` file path is interpreted as
@@ -63,19 +63,19 @@ being relative to the current binary directory.
6363* `HEADER <header>` - Generate a given `<header>` file. Relative header file
6464 path is interpreted as being relative to the current binary directory.
6565
66- * `OPTIONS <options>...` - List of additional options to pass to re2c
67- command-line tool.
66+ * `OPTIONS <options>...` - Optional list of additional options to pass to the
67+ re2c command-line tool.
6868
6969* `DEPENDS <depends>...` - Optional list of dependent files to regenerate the
7070 output file.
7171
7272* `NO_DEFAULT_OPTIONS` - If specified, then the options from
73- `RE2C_DEFAULT_OPTIONS` are not passed to the re2c invocation.
73+ `RE2C_DEFAULT_OPTIONS` are not added to current re2c invocation.
7474
7575* `NO_COMPUTED_GOTOS` - If specified when using the `RE2C_USE_COMPUTED_GOTOS`,
76- then the computed gotos option is not passed to the re2c invocation.
76+ then the computed gotos option is not added to the current re2c invocation.
7777
78- * `CODEGEN` - adds the `CODEGEN` option to the re2c's `add_custom_command()`
78+ * `CODEGEN` - Adds the `CODEGEN` option to the re2c's `add_custom_command()`
7979 call. Works as of CMake 3.31 when policy `CMP0171` is set to `NEW`, which
8080 provides a global CMake `codegen` target for convenience to call only the
8181 code-generation-related targets and skips the majority of the build:
@@ -87,7 +87,7 @@ being relative to the current binary directory.
8787## Examples
8888
8989The `re2c_target()` also creates a custom target called `<name>` that can be
90- used in more complex scenarios, like defining dependencies to other targets :
90+ used in more complex scenarios, such as defining dependencies:
9191
9292```cmake
9393# CMakeLists.txt
@@ -247,6 +247,8 @@ find_package_handle_standard_args(
247247unset (_re2cMsg)
248248unset (_re2cRequiredVars)
249249unset (_re2cTest)
250+ unset (_re2cVersionError)
251+ unset (_re2cVersionResult)
250252unset (_re2cVersionValid)
251253
252254if (NOT RE2C_FOUND)
@@ -351,9 +353,28 @@ function(re2c_target)
351353 set (message "[RE2C][${ARGV0} ] Generating lexer with re2c ${RE2C_VERSION} " )
352354 set (command ${RE2C_EXECUTABLE} ${options} --output ${output} ${input} )
353355
356+ # RE2C cannot create output directories. Ensure any required directories
357+ # for the generated files are created if they don't already exist.
358+ set (makeDirectoryCommand "" )
359+ foreach (output IN LISTS outputs)
360+ cmake_path(GET output PARENT_PATH dir)
361+ if (dir)
362+ list (APPEND makeDirectoryCommand ${dir} )
363+ endif ()
364+ unset (dir)
365+ endforeach ()
366+ if (makeDirectoryCommand)
367+ list (REMOVE_DUPLICATES makeDirectoryCommand)
368+ list (
369+ PREPEND
370+ makeDirectoryCommand
371+ COMMAND ${CMAKE_COMMAND} -E make_directory
372+ )
373+ endif ()
374+
354375 if (CMAKE_SCRIPT_MODE_FILE )
355376 message (STATUS "${message} " )
356- execute_process (COMMAND ${command} )
377+ execute_process (${makeDirectoryCommand} COMMAND ${command} )
357378 return ()
358379 endif ()
359380
@@ -372,6 +393,7 @@ function(re2c_target)
372393
373394 add_custom_command (
374395 OUTPUT ${outputs}
396+ ${makeDirectoryCommand}
375397 COMMAND ${command}
376398 DEPENDS ${input} ${parsed_DEPENDS} $<TARGET_NAME_IF_EXISTS:RE2C::RE2C>
377399 COMMENT "${message} "
0 commit comments