When writing libraries with CMake, you need to set a couple of properties, especially the VERSION and SOVERSION properties. For library libbar, it could look like:
|
1 2 |
set_property(TARGET bar PROPERTY VERSION “0.0.0”) set_property(TARGET bar PROPERTY SOVERSION 0 ) |
This will give you a libbar.so => libbar.so.0 => libbar.so.0.0.0 symlink chain with a SONAME of libbar.so.0 encoded into the library.
The SOVERSION target property controls the number in the middle part of the symlink chain as well as the numeric part of the SONAME encoded into the library. The VERSION target property controls the last part of the last element of the symlink chain
This also means that the first part of VERSION should match what you put in SOVERSION to avoid surprises for others and for the future you.
Both these properties control “Technical parts” and should be looked at from a technical perspective. They should not be used for the ‘version of the software’, but purely for the technical versioning of the library.
In the kdeexamples git repository, it is handled like this:
|
1 2 3 4 |
set(BAR_VERSION_MAJOR 1) set(BAR_VERSION_MINOR 2) set(BAR_VERSION_PATCH 3) set(BAR_VERSION ${BAR_VERSION_MAJOR}.${BAR_VERSION_MINOR}.${BAR_VERSION_PATCH} ) |
And a bit later:
|
1 2 |
set_target_properties(bar PROPERTIES VERSION ${BAR_VERSION} SOVERSION ${BAR_VERSION_MAJOR} ) |
which is a fine way to ensure that things actually matches.
Oh. And these components is not something that should be inherited from other external projects.
So people, please be careful to use these correct.

