Skip to content
Advertisement

Shared library versioning with cmake on github

I have a fairly new project on github that produces a shared library. Going forward, I would like to use semantic versioning (as described at semver.org) for the shared library major/minor/patch numbers in the file name. The project uses CMake. The CMakeLists.txt file refers to CPACK_PACKAGE_VERSION_MAJOR, CPACK_PACKAGE_VERSION_MINOR and CPACK_PACKAGE_VERSION_PATCH, and sets these to default values if they are not passed in on the command line.

My plan is to branch on ABI changes and API additions, according to semantic versioning principles.

I know github has support for creating and naming release packages containing the project source based on git tags. But I do not see a way to propagate the major, minor and patch numbers to the shared library name when the github user builds a release on their machine.

For example, if I have a branch called, myproj_1_2, and a release tag called myproj_rel_1_2_9, is there a way to have the shared library built by a user be name libmyproj.so.1.2.9?

Is this just a matter of documenting that a user should pass the build name information on the cmake command line, and the have the CMakeLists.txt file parse this and set CPACK_PACKAGE_VERSION_MAJOR, CPACK_PACKAGE_VERSION_MINOR and CPACK_PACKAGE_VERSION_PATCH accordingly, or is there a more elegant way to do this?

Advertisement

Answer

Your statement about how CPACK_PACKAGE_VERSION_XXX is set is incorrect. The CPack variables in question are set by the project command if the project command specifies versioning. So when you create the 1.2.9 branch you would set 1.2.9 as the version number in the project command.

From CPack Help

CPACK_PACKAGE_VERSION_MAJOR

Package major version. This variable will always be set, but its default value depends on whether or not version details were given to the project() command in the top level CMakeLists.txt file. If version details were given, the default value will be CMAKE_PROJECT_VERSION_MAJOR. If no version details were given, a default version of 0.1.1 will be assumed, leading to CPACK_PACKAGE_VERSION_MAJOR having a default value of 0.

Project command

> project(<PROJECT-NAME>
>         [VERSION <major>[.<minor>[.<patch>[.<tweak>]]]]
>         [DESCRIPTION <project-description-string>]
>         [HOMEPAGE_URL <url-string>]
>         [LANGUAGES <language-name>...])

If you don’t want to set the VERSION via the project command then there are multiple other ways of setting the relevant variables.

Examples are located: https://cmake.org/cmake-tutorial/

Also look at how CMake handles versions:

https://gitlab.kitware.com/cmake/cmake/blob/master/Source/CMakeVersionSource.cmake

https://gitlab.kitware.com/cmake/cmake/blob/master/Source/cmVersionConfig.h.in

Another example of how to get git meta data for setting version related information: https://github.com/pmirshad/cmake-with-git-metadata/blob/master/CMakeLists.txt

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement