how to generate header file at buildtime of project from installed plugin?

I am trying to create a plugin that adds a custom code generation step to unreal engine 5. This code generation step invokes a program that reads some files and generates some other files and is slow to run.

I would like to integrate with the cpp build system so that the generated code is generated only if needed, and then cached the same way it happens for cpp stuff.

I understand that i can use PrebuildSteps or tagging a .cs class with [UnrealHeaderTool] to partially achieve this, but doing this creates a command that is executed at every build, not only when the input files for the command have changed.

Is there a way do do this that does not involve reading the timestaps of the files myself and avoid generating if they are newer?