[CMake] portable way for specifying whether everything or selective libs should be linked statically or as shared objects?

Christoph Anton Mitterer calestyo at scientia.net
Mon Apr 2 21:18:39 EDT 2012


Hi.

I started to switch over all my build systems to CMake recently and am
stuck with the following.

I thought of the "C" in CMake ("cross-platform") that it means to that
most basic tasks are handled for most platforms/compilers in a
transparent way, but this seems all but be the case unfortunately.

This starts with commands like add_definitions where one have to use
"-D" as parameter suffix (well eventually there could be compilers which
don't use -D as option for this)... and ends with the following what I
though would really be one of the basics in business.

I'd like to allow users of my build system to specify whether
- everything shall be linked statically (i.e. what gcc's --static does)
- selectively select libraries (for which I allow it) to be linked
statically as shared objects or to be dynamically loaded[0].

Isn't this possible? If it is how?

I mean I've googled obviously and found ugly looking hacks where you set
some magic variables to --static (e.g.)... but this is then absolutely
importable.

Rather I'd have expected some clean interface e.g.
target_link_libraries(foo STATIC lib1 lib2 SHARED lib3 lib4)
where obviously lib1/2 are linked statically and 3/4 as shared objects.


Any ideas?! :-)


Thanks,
Chris.



[0] Obviously handling dynamic loading is out of the scope of CMake, so
the only thing I want here is to set some defines in order to let my
code know that it should dlopen/etc.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 5677 bytes
Desc: not available
URL: <http://www.cmake.org/pipermail/cmake/attachments/20120403/6ff05e0e/attachment.bin>


More information about the CMake mailing list