Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 661
oggmonster Avatar asked Nov 09 '12 22:11

oggmonster


People also ask

How to use version Control in qt Creator?

Disabled by default. To enable the plugin, select Help > About Plugins > Version Control > ClearCase. Then select Restart Now to restart Qt Creator and load the plugin.


2 Answers

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.

like image 131
MichK Avatar answered Oct 03 '22 17:10

MichK


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.

like image 24
sam-w Avatar answered Oct 03 '22 19:10

sam-w