[CMake] shared and static libs with same rootname
Alan W. Irwin
irwin at beluga.phys.uvic.ca
Mon Aug 14 20:26:48 EDT 2006
On 2006-08-14 16:57-0400 Jorge Rodriguez wrote:
> I'm not building Cygwin or MinGW. So, I would have to do something like this?
>
> ADD_LIBRARY(foo SHARED ${FooSources})
> ADD_LIBRARY(foos STATIC ${FooSources})
>
> SET_TARGET_PROPERTIES(foos PROPERTIES OUTPUT_NAME foo)
>
> Won't that build all the sources twice? That's not really optimal when
> there's no difference between the resulting object files.
Two points. (1) Some/most platforms have different compile flags (e.g.,
-fPIC for the gcc compiler) for the shared library case so you really do
have to compile twice for those platforms in any case. For example, that is
the autotools approach (which I am much more familiar with than CMake which
I am just learning), and they do special renaming of the resulting *.o files
to distinguish between the static and shared compile because of the next
point. (2) Unless you apply some special measure like renaming, you would
not compile twice because the *.o dependency is already satisfied in the
Makefile by the first compilation. In fact that is a worry on platforms
with special compile flags for shared libraries unless CMake does renaming
to distinguish between the object compiled for the shared library and the
object compiled for the static library. If it doesn't do such renaming,
there is always the option of building and installing the shared version,
wiping the build tree, and building and installing the static version.
In sum, from my autotools experience I think the shoe is on the other foot
and you should worry if you don't get two separate compilations for the
static library and shared library case.
Alan
__________________________
Alan W. Irwin
Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).
Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the Yorick front-end to PLplot (yplot.sf.net); the
Loads of Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________
Linux-powered Science
__________________________
More information about the CMake
mailing list