[Cmake] TARGET_LINK_LIBRARIES

Amitha Perera perera at cs.rpi.edu
Thu Apr 17 12:41:18 EDT 2003


On Thu 17 Apr 2003, Mathieu Malaterre wrote:
> Hi all,
> 	I have a project with directory like this:
> 
> project/
> 	libA/
> 	libB/
> 
> And libB need libA to be link.
> 
> Therefore in project/libB/CMakeLists.txt I add an entry:
> 
> TARGET_LINK_LIBRARIES(libB ${libA}) but this doesn't seems to be
> sufficient. What should I add ?

This is the solution being used successfully in many projects,
including vxl, itk and vtk. What exactly is the problem?

Generally, something like

ADD_LIBRARY( foo ... )
ADD_LIBRARY( bar ... )
TARGET_LINK_LIBRARIES( bar foo )
ADD_EXECUTABLE( blah ... )
TARGET_LINK_LIBRARIES( blah bar )

would generate a link line with
  ... -o blah -lbar -lfoo ...

provided, of course, that all these are done within CMake. The
TARGET_LINK_LIBRARIES does not add the dependency information directly
to the library; it merely records the information in the
CMakeCache.txt and uses it where necessary.

> BTW I thought that adding :
> LINK_DIRECTORIES(.)
> in project/CMakeLists.txt would do the trick, but unfortunately not.

This is not necessary. CMake "knows" the locations of the libraries
that it builds, and will add the appropriate paths as necessary.

Cheers,
Amitha.



More information about the CMake mailing list