I have a question about CMake which seems to be commonly asked here, but none of the answers seem to solve my problem.
In the details subdirectory, there is a CMakeLists.txt which contains:
add_custom_command(OUTPUT part.out
COMMAND foo --input=part.src --output=part.out
DEPENDS part.src)
add_custom_target(part_out
DEPENDS part.out)
In the main directory there is a CMakeLists.txt which uses part.out for generating another file:
add_custom_command(OUTPUT full.out
COMMAND bar --input=./details/part.out --output=full.out)
add_custom_target(full_out
DEPENDS full.out)
The problem is that I want 3 things to happen here:
- if
part.outdoesn't exist it needs to be generated - if
part.outis out of date (part.srcis newer thanpart.out) I want it to be regenerated - if
full.outis out of date (part.outis newer thanfull.out, orfull.outdesn't exist) I want it to be (re)generated
So if I add DEPENDS ./details/part.out to add_custom_command(OUTPUT full.out) I will achieve points 2 and 3, but not point 1, because if I delete part.out and then I call make full_out I'll get an error that there is no rule to make ./details/part.out (as it is a rule from another directory).
If I add DEPENDS full_out to add_custom_command(OUTPUT full.out) or to add_custom_target(full_out) I'll achieve points 1 and 2, but not 3, because even if part.out was regenerated, a full.out will not be regenerated, as it doesn't depend on the part.out file itself.
So how can I connect both scenarios?
I was thinking about adding both DEPENDS but how do I know if that will always work? I mean in such case the order of build will matter here.