[Cmake] Shared library versioning
Brad King
brad . king at kitware . com
Mon, 16 Jun 2003 17:21:40 -0400 (EDT)
Hi Gavin,
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.
> 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.
> 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.
> 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.
> 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.
Good luck,
-Brad