Reputation: 115
I have an existing project that is using CMake and has a complex binary target (compiles many .c file that include many .h files).
I want to add a process to auto generate some code before the existing target is built. So let's say the target is X
, and the auto-generated process is Y
. I want Y
to run before X
is built, but the auto-generating process and build take a long time, so I don't want them to run every time, I only want it to run when something changes.
The problem I see is that X
is dependent Y
and Y
is dependent on X
. Is there a way to solve this?
I basically want to say that the auto-generated process (Y
) should be dependent on all the source files (.c and .h files) for target X
(but not the build result), and that the the target X
should depend on the result of Y
.
Is there some way of doing this?
Note that I found that you can use glob to generate dependency on all the .c and .h files in the project, but the downside of that is that if someone adds a .h file they don't have to update Cmake, and so the Cmake won't re-run again before make, which means that we could miss the dependency on the header file and get bad results due to stale auto-generated code.
Upvotes: 1
Views: 41