[CMake] Independent libraries in parallel directories
brad.king at kitware.com
Tue Jun 21 10:43:32 EDT 2005
Nils H. Busch wrote:
> I am trying to build an application with source code in the top-level
> directory and two independant libraries in two separate subdirectories.
> When I link these two libraries in the top-level CMakeLists.txt file to
> the application via LINK_LIBRARIES, cmake creates inter-dependancies for
> these two libraries and calling make results in a seemingly recursive
> attempt to alternatively build either one of these two libraries to
> satisfy the dependancies and the computer freezes with a 100% load.
> When I use TARGET_LINK_LIBRARIES instead, no inter-dependancies are
> created, but cmake gives an error message stating
> library xy is defined using ADD_LIBRARY after the library is used using
> TARGET_LINK_LIBRARIES for application z. This breaks CMale's dependency
> handling. Same for the other library. Subsequent call to make, however,
> correctly compiles application and libraries.
> Apparently, I am doing something fundamentally wrong for such a design.
> Or is this behaviour a bug ?
> Any pointers for how to set up CMakeLists.txt correctly appreciated.
The LINK_LIBRARIES command has a global effect that links all targets to
the given libraries. It is useful for things like the math library
(-lm) on UNIX. When you use this command it is telling each library to
link to the other.
The warning you are getting is because for CMake 2.0 and earlier the
generated makefile system traverses directories in post-order (parents
visited before children). Therefore you cannot have an executable in a
parent directory that links to libraries in a subdirectory. If you
create a third subdirectory that is listed after the other two and put
the executable there the problem will go away. Note that this is fixed
in the current CVS version of CMake and will be fixed in the next release.
More information about the CMake