[CMake] Build the dependencies tree of an executable

Marco Corvo marco.corvo at pd.infn.it
Mon Jul 18 12:54:24 EDT 2011


Hi all,

I'm facing the following problem trying to generate the dependencies 
tree of an executable. I have a working area

/path/to/my/working/area/MyPackage

with, say, one executable I want to build. The relevant CMakeLists.txt 
line is something like:

add_executable(App src/App.cc)
target_link_libraries(App A B C D)

now these libs (A B C D) are already installed somewhere and they depend 
on other libraries of my software release. Say they're under

/path/to/sw/release/X.Y.Z/lib/arch/libA.a
/path/to/sw/release/X.Y.Z/lib/arch/libB.a
/path/to/sw/release/X.Y.Z/lib/arch/libC.a
/path/to/sw/release/X.Y.Z/lib/arch/libD.a
/path/to/sw/release/X.Y.Z/lib/arch/libE.a

...

and that A depends on D, E and F. When I run my build, cmake only finds 
that my App has A, B, C and D as dependencies, while actually these 
libraries have also their own dependencies.

I tried to add a .cmake file to each package in the release area

/path/to/sw/release/X.Y.Z/packageA/Deps.cmake
/path/to/sw/release/X.Y.Z/packageB/Deps.cmake
/path/to/sw/release/X.Y.Z/packageD/Deps.cmake

with

add_library(A STATIC IMPORTED)
add_dependencies(A D E F...)

which is "include"ed with my CmakeLists.txt file in order to let cmake 
know that when I build App it depends on A, B, C D _and_ A itself 
depends in his turn on D, E and F. This should create a complete 
dependencies tree for my App.

I know that add_dependencies gives "Adding dependency to non-existent 
target" with cmake version before 2.8.4 if the target is IMPORTED while 
with 2.8.4/5 on a Scientific Linux 5 I'm getting a seg fault with the 
add_dep directive.

Is this nevertheless the way to solve this problem? Are there other ways 
to build the dependencies tree of an executable which depends directly 
on some libs and indirectly on some other ones? Consider that I build 
static libraries, so I need to have the full list of libraries when 
linking the executable.

Thanks in advance for your help.

Cheers

Marco

-- 
Marco Corvo
SuperB experiment
CNRS - Orsay
c/o INFN - Padova


More information about the CMake mailing list