[CMake] what is best for library dependencies?

Rolf Eike Beer eike at sf-mail.de
Mon Oct 3 05:32:52 EDT 2011


Am Sonntag, 2. Oktober 2011, 12:21:01 schrieb Cristobal Navarro:
> hello,
> 
> as many of us, i am making a library and this is my first time. I have some
> concept questions.
> 
> for example, my library depends on "GLEW" library. Therefore applications
> that use my library must compile with  "-lmylib"  and  "-lGLEW"

Nope. Your library has to link against those libraries. The applications only 
have to if they use this interface directly.

> is it possible, to make the "-lGLEW" implicit inside my library?? or making
> the user put it manually is the way to go?

You do TARGET_LINK_LIBRARIES(mylib /path/to/glew/libglew.so). That's all. To 
get the path to GLEW in a system independent way please have a look on 
FIND_LIBRARY.

The only exception is if your library is a static one and the target 
application is not built with CMake. The problem is that you can't put this 
information in static libraries. Writing a pkgconfig or CMake export file is the 
way to go then.

Eike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://www.cmake.org/pipermail/cmake/attachments/20111003/aefb46da/attachment.pgp>


More information about the CMake mailing list