file-api: expose `configure_file` and `add_custom_command`

Just to confirm first, there is nothing in the file-api that can be queried to get a record of the files generated by configure_file and add_custom_command(OUTPUT)? Specifically the source/command and the destination files

This would be useful for code analyzers like clang-format/clang-tidy, for example to try formatting the output file and then try to format back the equivalent lines in the input file. An example issue: `lizard` does not work · Issue #47 · Takishima/cmake-pre-commit-hooks · GitHub.

For custom command outputs, one can look through the codemodel-v2 object to find source files with the isGenerated field set.

For configure_file and file(GENERATE) outputs, this is not currently available. I opened CMake Issue 24594 for that.

The isGenerated would only work if the files are actually used in a target by the current configuration right? That is ok, but it is harder to find if one has to navigate through all targets to find the target that uses that file.

But also, there doesn’t seem to be a record of the add_custom_command that generated that file. It would be useful to get additional information from both add_custom_command and add_custom_target like DEPENDS and BYPRODUCT.

The isGenerated would only work if the files are actually used in a target by the current configuration right?

Typically if the outputs are not used then the custom command won’t even be included in the generated build system.

doesn’t seem to be a record of the add_custom_command that generated that file.

CMake Issue 20463 requests custom command information in the fileapi.

try formatting the output file and then try to format back the equivalent lines in the input file.

In the linked issue I see discussion of configuring config.h.in to config.h as an example. Over in KWSys (one of CMake’s dependencies) we clang-format the .in files directly using a script like this to replace @ placeholders with valid identifiers, run clang-format on the temporary file, and then replace the identifiers with @ placeholders again.