Automatic buildnumber generation with QtCreator

QtCreator allows you to define custom build steps that are executed everytime you compile your project.

To take advantage of this feature, i wrote a tiny tool that generates a C header file when it is executed. I added the tool as custom build step in QtCreator and added the generated header file to my project.

Now everytime i recompile the project, the tool not only (re-)generates the header, it also increments the buildnumber contained in the file.

Example

manually generate header file
C:\> mkbuildnum buildnumber.h

use header in your c/c++ file
#include "buildnumber.h"

int MyClass::getBuild() { return BUILDNUMBER; }

Automate things

Add header to .pro
HEADERS += buildnumber.h

Add custom build step to the project

Downloads

mkbuildnum.exe (27kb)

Source code (1kb)

Source code was tested and compiled under windows, linux and mac os, but should also compile/run on other platforms (e.g. *bsd).