add_custom_command: Add CODEGEN support

By specifying CODEGEN as an argument to add_custom_command the
custom command will be added to a codegen build target.

The intent is to provide a convenient way for users to get
their generated files without having to build the whole project.

This can be helpful for code analysis tools which can be useful
for IDEs and CI.
This commit is contained in:
Juan Ramos
2024-05-27 20:19:05 -07:00
committed by Brad King
parent 033713530a
commit 197cb419d1
64 changed files with 733 additions and 3 deletions

View File

@@ -26,6 +26,7 @@ The first signature is for adding a custom command to produce an output:
[JOB_POOL job_pool]
[JOB_SERVER_AWARE <bool>]
[VERBATIM] [APPEND] [USES_TERMINAL]
[CODEGEN]
[COMMAND_EXPAND_LISTS]
[DEPENDS_EXPLICIT_ONLY])
@@ -203,6 +204,18 @@ The options are:
``${CC} "-I$<JOIN:$<TARGET_PROPERTY:foo,INCLUDE_DIRECTORIES>,;-I>" foo.cc``
to be properly expanded.
``CODEGEN``
.. versionadded:: 3.31
Adds the custom command to a global ``codegen`` target that can be
used to execute the custom command while avoiding the majority of the
build graph.
This option is supported only by :ref:`Ninja Generators` and
:ref:`Makefile Generators`, and is ignored by other generators.
Furthermore, this option is allowed only if policy :policy:`CMP0171`
is set to ``NEW``.
``IMPLICIT_DEPENDS``
Request scanning of implicit dependencies of an input file.
The language given specifies the programming language whose
@@ -454,6 +467,25 @@ will re-run whenever ``in.txt`` changes.
where ``<config>`` is the build configuration, and then compile the generated
source as part of a library.
.. versionadded:: 3.31
Use the ``CODEGEN`` option to add a custom command's outputs to the builtin
``codegen`` target. This is useful to make generated code available for
static analysis without building the entire project. For example:
.. code-block:: cmake
add_executable(someTool someTool.c)
add_custom_command(
OUTPUT out.c
COMMAND someTool -o out.c
CODEGEN)
add_library(myLib out.c)
A user may build the ``codegen`` target to generate ``out.c``.
``someTool`` is built as dependency, but ``myLib`` is not built at all.
Example: Generating Files for Multiple Targets
""""""""""""""""""""""""""""""""""""""""""""""