[CMake] using IMPORTED targets in multiple projects within one CMake tree

Pentasopor pentasopor at googlemail.com
Tue May 5 12:06:03 EDT 2009


Hi all,

here is what I'm trying to do:

I have a CMake build tree with several projects and targets with some
depending on others (impressive eh? ;)).  Furthermore I have a library
that I need to build outside of CMake and therefor I just added it
using

> add_library(xxx SHARED IMPORTED)

(But anyway - this is MY library, so I need to install it and everything.)

I also set some target properties (like IMPORTED_LOCATION) for it.
All this happens in CMakeLists file 'A'.  So my build tree looks like
this:

(I will call the CMakeLists.txt files A, B, ... for distinction)

M
|--- A
|--- B
|  |--- BA
|  |--- BB
|--- C

where M is something like:
====
PROJECT(TheWholeThingy)
#.. some defines a.s.o.
ADD_SUBDIRECTORY(A)
ADD_SUBDIRECTORY(B)
ADD_SUBDIRECTORY(C)
====

Now if I try to use target 'xxx' in B, it will not get resolved.  But
if I add a 'real' target (without IMPORTED) to 'A', I can use it (e.g.
in TARGET_LINK_LIBRARIES) without problems in B.

I just want to have a single point in my CMake-lists where I define
this externally built library and use it at several positions within
the rest of my CMake tree.

(Only at one point, because names and positions change for different
build types and I do not want to copy&paste the IF/THEN code needed
here to all locations where I want to link against 'xxx'.)

What am I doing wrong here?  Is this supposed to work, or did I just
use the wrong mechanism?

Any help is reaaallllyy appreciated! :)
bye

   Pentasopor



More information about the CMake mailing list