[CMake] Dependency tracking with constructed source headers...

Brad King brad.king at kitware.com
Thu Oct 7 19:52:46 EDT 2004


Dan Katz wrote:
> ----------------- foo.cpp ------------------------------------
> #include "bar.h"
[snip]
> ---------------- CMakeLists.txt ----------------------------------
[snip]
> # how to build bar.h
> ADD_CUSTOM_COMMAND(
>   OUTPUT           ${foo_BINARY_DIR}/bar.h
>   COMMAND          cp
>   ARGS             ${foo_SOURCE_DIR}/bar.junk ${foo_BINARY_DIR}/bar.h
>   MAIN_DEPENDENCY  ${foo_SOURCE_DIR}/bar.junk)
> ADD_EXECUTABLE(foo foo.cpp ${foo_SOURCE_DIR}/bar.junk)
[snip]
> So I guess the question is:  why didn't the system pick up that foo.o
> depends on bar.h?  And how can I make it do so?

The dependency scanner for foo.cpp is not currently hooked into the set 
of generated files, so it does not find bar.h until after it is 
generated the first time.  As a bootstrapping mechanism, you can add the 
dependency explicitly:

SET_SOURCE_FILES_PROPERTIES(
   foo.cpp
   PROPERTIES
   OBJECT_DEPENDS ${foo_BINARY_DIR}/bar.h
   )

-Brad


More information about the CMake mailing list