How to add custom command after compilation stage and before linking stage?

Hi,
I’m a writer of a code generator tool, and the tool must be run after the compilation stage and before linking stage.

We use makefile before and this is not a problem, but when ports to cmake, I only find adding flags to compilers and linkers, which seem not fit my requirement, so is there anyway I can do this?

I believe you’re looking for the “Build events” signature of add_custom_command:

add_custom_command(
  TARGET TheTarget 
  PRE_LINK
  COMMAND GeneratorTool arg1 arg2
  VERBATIM
  # add other arguments to taste
)

This adds a custom command that will run before TheTarget is linked, but after its sources have been compiled.

Thanks a lot, seems I’m not carefully enough to read the document…