Generate code from code?

What I want to do is add a custom command that runs on all of the source/dependencies of a target.

So I want to know all the .c/.cpp and indirectly referenced .h files to generate code, which would also have to be compiled/linked back in to the final executable.

This would be similar to how Qt moc works.

Is this possible to do somehow without modifying cmake?

I could probably make a CMakeLists.txt generator that contains a bunch of custom commands, but it would end up being a manual step people would need to run.

I think the only reliable way of doing this right now is to pass all of the sources in from a genex to a single command (this can then dispatch as needed) because the source list isn’t “known” at configure time due to target_sources adding files after any given point and genexes for conditional sources not being computable either.

Getting the indirectly referenced .h files is almost certainly out of the question too as that is content-based and you really don’t want your configure to depend on the content of anything other than CMake files (otherwise any source change could force a rerun of CMake in addition to the build).