Define a pre-build command without creating a new target

Your idea is not wrong. The dummy output makes sure the custom command is always executed and the generated header file is then part of the target sources.

I cannot immediately spot the problem without a working example. The source is probably build in parallel with its generation.

Before moving on with your question - have you had a look at chapter 19.3 Source Control Commits? It implements the same concept, but differently.