[CMake] multiple targets depending on generated file
Brad King
brad.king at kitware.com
Tue Apr 5 13:10:24 EDT 2011
On 04/05/2011 12:22 PM, Clinton Stimpson wrote:
>
> I'm looking at bug #11884
> http://public.kitware.com/Bug/view.php?id=11884
>
> And I've noticed there is a problem with depending on generated headers across
> directories but not within the same directory.
>
> For example:
>
> # section A
> add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/out.h COMMAND ....)
> add_executable(... ${CMAKE_BINARY_DIR}/out.h ...)
>
> # section B
> add_custom_command(OUTPUT out2.h COMMAND .. DEPENDS ${CMAKE_BINARY_DIR}/out.h)
> add_executable(... out2.h ...)
>
>
> If section A and B are in the same CMakeLists.txt, then there is no problem.
>
> If they are in sibling directories, then building section B first will lead to
> an error about out.h missing. A workaround involves the user of
> add_dependencies() and/or a custom target.
>
> Is this a bug in CMake? It seems there is enough information given that CMake
> could notice the dependency. But maybe it can't quite do it because its a
> separate directory? Maybe cmake can do the add_dependencies() automatically?
This is expected. You need to do add_dependencies or use a separate custom
target and then make both targets depend on that. CMake cannot just magically
introduce an extra custom target or arbitrary dependency between existing
targets.
-Brad
More information about the CMake
mailing list