[CMake] Cascading dependencies.

Brad King brad.king at kitware.com
Tue Jul 25 09:32:35 EDT 2006


Giulio Eulisse wrote:
> Ciao,
> I'm trying to use cmake to build a project with many libraries, with
> lots of dependencies. For this reason I would like to do something that
> allows the following.
> Given 3 libs A B C each one with its own dir and with
> 
> A depends on B
> B depends on C
> 
> I want to be able to discover that A depends on C too and put it in the
> list of libraries that should be linked with A. I was trying to do it
> with LISTs but they don't seem to be available across directories...Any
> idea?

Use these four CMakeLists.txt files:

# CMakeLists.txt
PROJECT(MYPROJ)
ADD_SUBDIRECTORY(C)
ADD_SUBDIRECTORY(B)
ADD_SUBDIRECTORY(A)
------------------------
# C/CMakeLists.txt
ADD_LIBRARY(C ...)
------------------------
# B/CMakeLists.txt
ADD_LIBRARY(B ...)
TARGET_LINK_LIBRARIES(B C)
------------------------
# A/CMakeLists.txt
ADD_LIBRARY(A ...)
TARGET_LINK_LIBRARIES(A B)

CMake will automatically chain the dependency of A on C through B and
construct the proper link line.

-Brad


More information about the CMake mailing list