[CMake] Dependency tracking with constructed source headers...
Dan Katz
dkatz at profitlogic.com
Fri Oct 8 19:13:04 EDT 2004
On 7 Oct 2004, Brad King wrote:
> Dan Katz wrote:
>> 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
> )
Thanks for the trick -- it solved my problem quite neatly.
I noticed, however, that this solution is sort of brittle. In the
case I posted yesterday, I had a simple dependency tree (generated
files in parens):
+--- foo.cpp
(foo) <--- (foo.o) <--|
+--- (bar.h) <--- bar.junk
and everything is fine. But if I later add another piece to the
project such that I now have a tree like this (modulo the limits of
ASCII art -- there's only one of bar.junk and baz.h, but I can't
figure out a good way to draw the graph conveniently):
+--- foo.cpp
|
+-- (foo.o) <--+--- (bar.h) <--- bar.junk
| |
| +--- baz.h
|
(foo) <-+
|
| +--- baz.cpp
| |
+-- (baz.o) <--+--- (bar.h) <--- bar.junk
|
+--- baz.h
then the build will break if I happen to list baz first in the
list of sources to be built:
ADD_EXECUTABLE(foo baz foo ${foo_SOURCE_DIR}/bar.junk)
Of course, one either updates the explicit dependency you suggested
above to point to baz.cpp, or simply reorders the source dependencies
in the ADD_EXECUTABLE statement, but it's still not quite as automatic
as one might hope.
Is there a simply way to understand why the dependency tracker doesn't
pick up the dependency on the generated header from the "#include"
statement in the source foo.cpp file?
How is the system generating the dependencies anyway? I guess I'll
take a look at the code for the scanner...
Dan
More information about the CMake
mailing list