Read file and transform the result in a custom command directly?

Before I run eg doxygen I want to read up some variables from a file that was written earlier in the build.
This reading also entails transforming the result a bit before passing it on to doxygen.
Is it customary to create a custom command that depends on the file creation and do all of this inside said command:
1 read the file into a variable
2 transforms the variables a bit (a few steps)
3 store the result in a variable
…and then have the call to doxygen depend on the above command?
That is, can I do all this with the ${CMAKE_COMMAND} inside the custom command directly somehow?
Or do I need to write the commands to another file and then run it from the custom command with -P? I have never encountered the former, hence my question.
Thank you.

If the -E subcommands do what you need. But I think a script and -P is easier and more common.