[CMake] Adding -fPIC to static libraries

Prakash Punnoor prakash at punnoor.de
Wed Mar 1 15:30:52 EST 2006


Am Mittwoch März 1 2006 21:06 schrieb Brad King:
> Prakash Punnoor wrote:
> Supporting this in CMake is tricky.  The problem we face that libtool
> does not is supporting Windows compilers (correct me if I'm wrong I have
> not checked this).

Not that I know of. Thinking again, it might be that the difference with cmake 
would be much less porblematic, if cmake would have "convenience libs" such 
that these are "static" libs which don't get installed but can be used for 
linkinginto static/shared libs and exes. CMake could decides itself whether 
it need to compile the convenience libs' objects twice or only pic or non-pic 
(unlike libtool which does it always twice). Wouldn't this be a feasable 
option? Should be fairly easy to handle by smake. It just needs to compile 
max two static libs, one with pic, one without.

> On Windows a shared library "foo" consists of the 
> runtime library "foo.dll" and the import library "foo.lib", and a static
> library "foo" consists of the file "foo.lib".  Therefore the static and
> shared versions of the library cannot have the same name.

Yes, I just experienced this problem....

> The current CMake way to support static and shared libraries is to use
> two ADD_LIBRARY commands with different target names:
>
> ADD_LIBRARY(foo-shared SHARED ${FOO_SOURCES})
> ADD_LIBRARY(foo-static STATIC ${FOO_SOURCES})

While we're at it: You probably want to disallow "-" in target names, as it is 
not portable, as I experienced. At least nmake in Windows complains and 
errors out.


-- 
(°=                 =°)
//\ Prakash Punnoor /\\
V_/                 \_V
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/cmake/attachments/20060301/02b1705b/attachment.pgp


More information about the CMake mailing list