I would like to have a variable (or #define) in C++ source that will increment each time I use QT Creator to build source code. Is there any way I can do this, perhaps some QT Creator plugin or similar? If there is a way to do it if I use "make" on command line to build?
+6
A:
In your .pro file, you can create a variable that contains the results of a command-line program. You can then use that to create a define.
BUILDNO = $$(command_to_get_the_build_number)
DEFINES += -DBUILD=$${BUILDNO}
If you just want a simple incrementing number, you could use a pretty simple script:
#!/bin/bash
number=`cat build_number`
let number += 1
echo "$number" | tee build_number #<-- output and save the number back to file
I should note that this would cause the build number to increment every time you build, and also increment if you try to build but it fails. A better way is to get a build number based on the state of the code, and many version control tools can get you a text string for that, if not a number.
Caleb Huitt - cjhuitt
2009-09-13 14:31:00
I really want increment on each build not each repository commit. This answers my question.
Ross
2009-09-13 18:49:26
I'm using my own scheme with Qt+QMake:http://indiocolifax86.wordpress.com/2010/05/22/a-scheme-for-automatic-build-numbers-in-cc-projects/
Hernán
2010-07-15 15:33:38