[CMake] Bug in IMPLICIT_DEPENDS for add_custom_target

Ravi lists_ravi at lavabit.com
Wed Nov 11 08:58:23 EST 2009


On Tuesday 10 November 2009 19:30:25 Alan W. Irwin wrote:
> On 2009-11-10 17:34-0500 lists_ravi at lavabit.com wrote:
> >  How does one ensure that the appropriate scanner is run to obtain
> > implicit dependencies via IMPLICIT_DEPENDS? In the following example,
> > the 'drop' target depends on dummy.cc which has an implicit dependency
> > on blah.h, which means that 'drop' should be rebuilt after every change
> > to blah.h. However, with CMake 2.6.4 (rpm from Fedora 11) and 2.8.0-rc6
> > (self-compiled), the 'drop' target is never remade when blah.h is
> > modified. Is this a bug?
> >
> > blah.h:
> > inline int blah() { return 3; }
> >
> > dummy.cc:
> > #include <iostream>
> > #include "blah.h"
> > void tester() { std::cout << blah() << std::endl; }
> >
> > CMakeLists.txt:
> > cmake_minimum_required( VERSION 2.6.4 )
> > add_custom_command( OUTPUT drop
> >                    COMMAND touch drop
> >                    IMPLICIT_DEPENDS CXX dummy.cc )
> > add_custom_target( dropper ALL DEPENDS drop )
> >
> > Of course, the preceding is a very simplified example to show the issue.
> > My real use case is much more complex than a mere 'touch', involving some
> > complex pre-processing on some C++ source code.
> >
> > Any hints greatly appreciated. I am using the standard Unix makefiles
> > generator. The build.make file in CMakeFiles/dropper.dir has no
> > indication that blah.h is even involved in this compilation.
> 
> I am in the habit of always using full paths for DEPENDS and OUTPUT, e.g.,
> 
> ${CMAKE_CURRENT_BINARY_DIR}/drop
> 
> I am not sure that is necessary, but it is worth a try in this case.  Also,
> use "make VERBOSE=1 dropper" to make sure "touch
> ${CMAKE_CURRENT_BINARY_DIR}/drop" is actually being executed as expected
>  (or not).

The first time 'dropper' is made, so is 'drop' (correctly). However, 'drop' is 
not updated on subsequent makes of 'dropper' even if 'blah.h' has changed. 
Here's the dependency chain:
  'dropper' depends on 'drop' (specified in CMakeLists.txt)
  'drop' depends on 'dummy.cc' (specified in CMakeLists.txt)
  'dummy.cc' depends on 'blah.h' (implicit dependency)
The problem is that the last implicit dependency is not seen by CMake. My 
understanding is that IMPLICIT_DEPENDS was created to solve exactly this 
problem, but fails in this trivial case.

Sequence of events:
  1. make dropper
       makes 'drop' first time by running 'touch drop'
  2. change 'blah.h'
  3. make dropper
       should remake 'drop' due to dependency chain above, but does not

In the Makefile generated by CMake, 'dummy.cc' is an explicit dependency of 
'drop', but 'blah.h' is not mentioned anywhere. It seems that CMake did not 
run the CXX scanner on 'dummy.cc', which in turn leads me to believe that 
IMPLICIT_DEPENDS did not work.

Regards,
Ravi




More information about the CMake mailing list