Version Numbers in a project with Qt

Version numbers are needed all over a project; in installers, code, toolchains etc. I despise duplication. I want my version numbers to be stored in one central authoritative location.

I am working with C/C++ and using Qt on various platforms. In Qt, qmake projects specify version numbers like:

VERSION = 1.2.3

In code I use something like in a header like Version.h:

#define VERSION_MAJ 1
#define VERSION_MIN 2
#define VERSION_REV 3
#define VERSION_STRING \"VERSION_MAJ\" "." \"VERSION_MIN\" "." \"VERSION_REV\"

My installer toolchain has support for C preprocessing so I can use the same version specified in Version.h. However, I don't know how to get qmake to use the same version number. I thought I could preprocess the pro file, but that won't work as # characters mean a comment in pro files and the C preprocessor will fall over.

Anyone know of a good way to keep my version number centralised?

Answers


If you want to be able to store your version numbers in a c header file, you can do so and then import them into the Qt project variables in the project file. Something like the below should work:

Version.h:

#define MY_MAJOR_VERSION 3
#define MY_MINOR_VERSION 1

.pro

HEADERS  += Version.h

VERSION_MAJOR = MY_MAJOR_VERSION
VERSION_MINOR = MY_MINOR_VERSION

The advantage of doing it this way round is that you can then use your authoritative header file if you need to compile other parts of the project away from Qt.


I use something like this in my build system

#.pro file
#Application version
VERSION_MAJOR = 1
VERSION_MINOR = 0
VERSION_BUILD = 0

DEFINES += "VERSION_MAJOR=$$VERSION_MAJOR"\
       "VERSION_MINOR=$$VERSION_MINOR"\
       "VERSION_BUILD=$$VERSION_BUILD"

#Target version
VERSION = $${VERSION_MAJOR}.$${VERSION_MINOR}.$${VERSION_BUILD}

And after that you can use VERSION_MAJOR and others as normal macro in your application.


Need Your Help

What additional rotation is required for deletion from a Top-Down 2-3-4 Left-leaning Red Black tree?

java algorithm data-structures red-black-tree 2-3-4-tree

I have been implementing an LLRB package that should be able to operate in either of the two modes, Bottom-Up 2-3 or Top-Down 2-3-4 described by Sedgewick (code - improved code, though dealing only...

How do I hide/show the right button in the Navigation Bar

ios objective-c uibarbuttonitem rightbarbuttonitem

I need to hide the right button in the Navigation Bar, then unhide it after the user selects some options.