[CMake] Re: Library dependency

Kyle Heath heathkh at gmail.com
Mon Aug 13 13:10:46 EDT 2007


On 8/10/07, Christian Convey <christian.convey at gmail.com> wrote:
> On 8/10/07, Kyle Heath <heathkh at gmail.com> wrote:
> > I would like to use cmake to build a set of single target projects
> > (each project generates either one library or one executable).  I
> > understand how to handle dependencies on external packages with the
> > <foo>Find.cmake scripts, but I don't know how to deal with internal
> > CMake built packages.  There is some kind of magic with a
> > <name>Config.cmake that I don't understand.
> >
> > Here's a little high-level "use case" scenario to illustrate what I want to do:
> >
> > My executable project HelloWorld uses package "MyLibA" directly.  In
> > the CMakeLists.txt for HelloWorld I want to simply do something like:
> > SET(requiredPackages MyLibA)
> >
> > My static library project "MyLibA" uses package "MyLibB" directly.  In
> > the CMakeLists.txt for MyLibA I want to simply do something like:
> > SET(requiredPackages MyLibB)
> >
> > I want cmake to follow the package dependency chain so that my
> > HelloWorld executable project gets all the library file names and
> > include directories it needs to compile and link.  If I change a file
> > in library B and rebuild my executable HelloWorld, I want it to detect
> > that it needs to rebuild package "MyLibB" and "MyLibA" and relink my
> > executable.
> > I'd also like to handle different build types.  If I build my project
> > in debug mode, i want it to use the debug versions of all the packages
> > it depends on (and not rebuild "release" versions that won't be used).
> > Is cmake powerful enough to do this (and make it simple to use)?
> > Does the "Mastering CMake" book explain how to do these basic sort of things?
>
> If I understand your questions, the answers are yes, and yes:
> CMake does everything you mention, and generally does it very well.
> The book is a good read, although this email list is a very helpful supplement.

Great. I've ordered the book. I guess I'll be enlightened in 3 to 5 days.

In the meantime, I created a set of example projects to simulate the
senario above: One executable depends on a static library B that
depends on another static library A.

I've posted it here: http://www.stanford.edu/~heathkh/multi_lib_example.tar.gz

Expected behavior:
I want cmake to follow the package dependency chain so that my
exectest executable project gets all the library file names and
include directories it needs to compile and link by following the
dependency chain.

Actual behavior:
Building exectest fails because it doesn't get the include directory
for library A (on which lib B depends).

Notes:
I use eclipse as my IDE so that's why I've created a build directory
under the root of each project source directory.  It's not clear what
a <package_name>Config.cmake file should contain, this was just my
best guess...

I'm just getting started and would greatly appreciate any suggestions.

Thanks,
-Kyle


More information about the CMake mailing list