[CMake] Is this expected behavior?

Chris Johnson cxjohnson at gmail.com
Mon Dec 8 13:53:47 EST 2014


When I change a header file for a library, and then do a "make" in the
build directory, only source (C++) files which directly include that header
get rebuilt, but those which use it indirectly do not.  But when I link to
the library, the other files do get rebuilt.

Example:

lib/mod.cpp
lib/mod2.cpp
lib/mod3.cpp
lib/lib/mod.h
lib/lib/mod2.h
lib/lib/mod3.h

mod1.h:
class mod {
};

mod2.h:
#include "lib/mod1.h"

class mod2 : public mod1 {
};

mod.cpp
#include "lib/mod.h"

mod2.cpp:
#include "lib/mod2.h"

// etc.

So mod.h contains the base class, and mod2.h and mod3.h contain derived
classes.  Changing mod.h requires all of the example source files above to
be recompiled to be correct, but "make" in the lib directory only
recompiles mod.cpp.

If I have a program elsewhere which references this library, doing a "make"
in its build directory causes dependency checks and results in mod2.cpp and
mod3.cpp being recompiled as well as mod.cpp.

The depend.mak and depend.internal files correctly list mod.h as being in
the dependencies for mod2.o and mod3.o, but those rules don't appear to get
used.

Is this expected behavior?  Is there some way to change it to cause a
"make" in the lib directory to compile all files dependent on the header,
even if transitively (correct word?)?

Thanks.  This is really throwing our developers for a loop as we transition
from home-grown make to CMake.

..chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20141208/16420b49/attachment.html>


More information about the CMake mailing list