[Cmake] Shared library versioning

Gavin Baker gavinb at antonym . org
17 Jun 2003 09:09:01 +1000


Hi Brad,

Thanks for the feedback...

On Tue, 2003-06-17 at 07:21, Brad King wrote:

> This support has been on our list of future features for a while, but no
> one has had time/funding to do it.  You have a good start, but we cannot
> include your patch as-is (see below).  I can help you complete the
> implementation if you're able to spend the time.

Sure - I'll give it a go, and would appreciate some guidance.  It is
quite urgent for Unix platforms to have this support IMHO.

> > I have added a new command, SET_LIBRARY_VERSION.  A simple example:
> >
> > PROJECT(Farcical)
> > ADD_LIBRARY(hello SHARED hello.cxx)
> > SET_LIBRARY_VERSION(hello 1.6.3 4)
> 
> This can be done with an existing command:
> 
> SET_TARGET_PROPERTIES(hello PROPERTIES LIBRARY_SOVERSION 1.6.3
>                                        LIBRARY_VERSION 4)
> 
> If you don't like the verbosity, you can create a SET_LIBRARY_VERSION
> macro with the MACRO command for your project that wraps up the call.

Ok; I thought that having an explicit command would be cleaner, but the
macro makes sense.  Could the macro be included in the default cmake
config?  This would avoid potential spelling errors, and ensure that
both version and soversion were specified together.

> >         c++ -fPIC  -rdynamic -Wl,-soname,libhello.so.4  -shared -o libhello.so $(hello_SRC_OBJS)
>                                ^^^^^^^^^^^^^^^^^^^^^^^^^
> 
> The flag configuration here needs to be specified for all unix
> platforms/compilers/linkers in the Modules/Platform directory.  Your patch
> includes only the linux implementation.

But of course; think of this as more of a 'proof of concept'. :)  I will
provide as many as possible, but I think I only have access to Linux,
{Free,Open,Net}BSD and Solaris.  I might have to go begging for the
others.

> >         mv libhello.so libhello.so.1.6.3
> 
> This should be done by specifying libhello.so.1.6.3 with the -o option on
> the library build line.  If the link fails, the symlinks should not be
> created (and should be deleted if they exist), so some additional logic
> may be needed.

Ok, the '-o' is the way to go.  I think I can just add the version to
the suffix.

If the link fails, the subsequent lines wouldn't be executed right?  I
could add an 'rm' for the symlinks in the 'clean' target.  This way, the
symlinks should only be created if the link step is successful.

> >         ln -sf libhello.so.1.6.3 libhello.so.4
> >         ln -sf libhello.so.4 libhello.so
> 
> Look at CMakeDefaultMakeRuleVariables.cmake in the Modules directory.  It
> contains default settings for variables describing how to build each kind
> of object/library/exe.  The platform-specific files in the
> Modules/Platform directory can override these variables.  The
> CMAKE_CXX_CREATE_SHARED_LIBRARY variable can be set with a list of rules
> to use in building a C++ shared library.  These ln lines should be added
> to this rule.

Cool, ok - that would simplify things a little.  Actually it looks like
the above will simplify things quite a bit.

Thanks for your feedback.  I will have another crack at it based on your
suggestions, and get back with another patch.

Regards,

  :: Gavin


-- 
Gavin Baker // gavinb*antonym_org // Linux|Python|Esperanto|MIDI|Cheese