How to deal with code generators?

In the past I have dealt with code generators such as flex, bison, protobuf, etc…
In an old project, using makefiles, it was the same make that wrote a header file containing the semantic version string, and a couple of files containing arrays generated from binary files with the command xxd.
How is it possible to achieve this, with the right dependencies between files, with cmake?
For example if it is necessary to run a command every time the executable is built.

best regards
Max

For each generated file, use a add_custom_command() and file outputs and dependencies correctly.

Then use each output in no more than ONE target. The custom commands must be defined in the same directory as the target.