[CMake] ADD_LIBRARY and FIND_PACKAGE: shared vs. static

Nico Schlömer nico.schloemer at gmail.com
Tue Sep 18 19:06:14 EDT 2012


Hi all,

when building a library with CMake, I can decide whether its shared or
static by specifying the appropriate keyword,

ADD_LIBRARY( foobar {SHARED,STATIC} ...)

If this library uses a system library, and if I'm lucky enough that
there's a FindCMake of some sort available for it, I can usually do
something along the lines of

FIND_PACKAGE(FancyLib)

which then will possibly set variables like ${FANCY_LIB}, which I
could use to link foobar with,

TARGET_LINK_LIBRARIES(foobar ${FANCY_LIB})

Now, I can't see how to tell CMake the find static of shared version
of FancyLibs although it would seem natural to link FancyLib's shared
library when building foobar shared, and static if otherwise.
By default, FIND_PACKAGE always seems to set shared libraries.

What's the idea or concept here, and how is CMake to be used correctly?

Cheers,
Nico


More information about the CMake mailing list