[CMake] Bug in cmake 2.8.4/5 when using IMPORTED static targets?

Brad King brad.king at kitware.com
Thu Aug 4 15:29:24 EDT 2011


On 7/21/2011 1:07 PM, Marco Corvo wrote:
> Hi all,
>
> I'm trying to use a new feature of releases 2.8.4/5, that is the possibility
 > to define dependencies for IMPORTED targets and when I run cmake I get a
 > SIGSEV signal. Trying to get some more info with Valgrind I found that:

I can reproduce this with just:

   cmake_minimum_required(VERSION 2.8.4)
   project(FOO C)
   add_library(foo STATIC IMPORTED)
   add_dependencies(foo does_not_exist) # ***
   add_executable(bar bar.c)
   target_link_libraries(bar foo)

> So it looks like cmake is trying to access (dereference) a NULL pointer.
 > In particular, digging in the source code, the issue arises (apparently)
 > in cmComputeTargetDepends.cxx(AddTargetDepend) at line 279
>
> cmTarget* transitive_dependee =
> dependee->GetMakefile()->FindTargetToUse(i->c_str());
>
> when cmake recursively calculates the dependency of my target, which relies
 > on all IMPORTED targets, and hits an IMPORTED target (a library) with NO
 > dependencies, that is the last leaf of my deps tree. The "transitive_dependee"
 > returned by FindTargetToTuse turns out to be a NULL pointer and when
> IsImported() is called on it, it makes the program crash.

You found the correct line.  The bad code was added along with the feature:

   http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=e01cce28

This was a dumb mistake on my part.  I will fix it.  Meanwhile you can
avoid the crash by not making an imported target depend on a target
that does not exist.

-Brad


More information about the CMake mailing list