Support rebuilding external project’s dependent targets when the external project changes
I’m working on a cross-compilation project with a top-level CMakeLists.txt
file generating Makefiles. Some of the cross-compiled source code is generated by a host-based code generation tool; since that tool needs a different toolchain, the top-level CMakeLists.txt
uses ExternalProject_Add()
to invoke the code generator subdirectory’s CMakeLists.txt,
with BUILD_ALWAYS set to TRUE. The code generation targets depend on the code generator target, so during the initial build the code generator is built, and then the code is generated, and then the whole shebang is compiled into the final result. (To be clear: there’s no downloading involved; all of the external project code is local.)
If I change the source of the code generator then the code generator executable will be properly rebuilt on the next make. Problem: the dependent code generation targets will NOT be rebuilt. There seems to be no way with an ExternalProject_Add()
target to indicate when/if any dependencies of the target should be rebuilt.
For instance, if my code generator target were configured using Add_Custom_Command()
, then I’d use its OUTPUT
keyword to specify the resulting executable file. I’d then create a convenience target using Add_Custom_Target()
whose DEPENDS keyword referenced the Add_Custom_Command()
's OUTPUT file. I’d then have the code generation targets depend on this convenience target. But, that won’t work for ExternalProject_Add()
.
Is there a way to configure an ExternalProject_Add()
-based target so that dependent targets will be automatically rebuilt when the main target’s output changes? If not, then consider this an enhancement request.