Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practices: versioning applications using CMake

I have a need to create a versioning mechanism for an application we are developing.

The version needs to be the following format: VERSION.RELEASE.MAINTENANCE.PATCH. This is nothing special till now, just 4 numbers. CMake will generate a header with these numbers and this file will be included in the required places to retrieve the version number.

But here comes my question: Where should I store these four numbers?

The following places was I thinking to store them:

  1. the CMakeLists.txt - easy to maintain but very exposed to human failure
  2. CMake should parse out these numbers from the SVN repository URL (we use SVN and there is an acceptable way of enforcing tag and branch names for the project)
  3. somewhere else ?

So, here is the question:

What best practices can you suggest for achieving this?

EDIT (answer to comment from LB):

The builds will be required for the trunk version (but not for any revision, just the "top"), tagged versions and special development branches.

like image 598
Ferenc Deak Avatar asked Nov 10 '22 03:11

Ferenc Deak


1 Answers

From my point of view (I am currently involved into several (non-large) projects, based on CMake, and have seen many other projects, based on different build platforms):

  1. For large or production project maintaining version inside code (CMakeLists.txt, auxiliary file, etc.) is preferrable.

For such project human failure in changing version number inside code is almost impossible because of well-defined business process.

From the other side, source code become separable from repository(SVN). So you able to deliver source code, e.g., as a simple archive.

  1. For small project, or project which hardly will be separated from repository, parsing repository data within CMake script is acceptable.

In such project human failure in release versions are more frequent, so reducing number of manual steps always has a sence.

From the other side, full support for several ways to deliver source files is not common in small projects. It is sufficient to support downloading sources only via SVN.


In case of parsing repository data for getting version number, it is better to have file-level dependency of CMake script from that data. Otherwise, having tagged revision differed from previous one only in source files, you may have incorrect version number after these steps:

  1. Clone non-tagged revision
  2. Configure it(cmake)
  3. Build it (make).
  4. Update to tagged revision.
  5. Build it.

Because none of CMake script dependencies are changed on step 4, build at step 5 will not involve automatic reconfiguration, so version number will not be regenerated.

like image 194
Tsyvarev Avatar answered Nov 15 '22 11:11

Tsyvarev