[Qt-interest] Auto-Incremented Build Number for my Project
David Walthall
walthall at wavefun.com
Thu Sep 17 18:35:50 CEST 2009
Josiah Bryan wrote:
> Hey All -
>
> Here's the goal: An auto-incremented build number that I can access from
> my program (via a define or symbol - dont matter), that increments each
> time I call make (on linux) or build it with QtCreator on windows.
>
> On linux - thats easy - just hack Makefile with some custom build target
> definitions and run a small perl or bash script each build to increment
> a 'special' file or whatever. But since the Makefile is auto-gen'd by
> qmake, I imagine I'd have to do something fancy in my .pro file to
> re-add my Makfile-changes every time qmake regens the project file. On
> windows, I'm a bit murky - not sure how I'd get it done there.
>
> What I'm wondering is if there is any "Standard" way using .pro files to
> tell qmake to autoinc a build number for me without me having to do any
> special "hacks". Anyone have any leads or pointers on it? Or am I on my
> own for this one?
Below is what I did for this. It has the advantage that the version
number is up-to-date whenever you build.
### Add to bottom of .pro
# Add the revision number stuff.
# This has to come after the include(xxxx.pri) so that
# $$SOURCES $$HEADERS $$FORMS are all set
REVISION_INPUT = Revision_template.cpp
revtarget.input = REVISION_INPUT
revtarget.output = Revision.h
win32 {
revtarget.commands = C:\cygwin\bin\sh make_revision.sh
${QMAKE_FILE_NAME} ${QMAKE_FILE_OUT}
}
macx {
revtarget.commands = /usr/bin/sh make_revision.sh ${QMAKE_FILE_NAME}
${QMAKE_FILE_OUT}
}
revtarget.depends = ${QMAKE_FILE_NAME} $$SOURCES $$HEADERS $$FORMS
revtarget.name = Generating_RevNum (${QMAKE_FILE_NAME})
QMAKE_EXTRA_UNIX_COMPILERS += revtarget
### End of section for .pro file
---------------------------------
Here is make_revision.sh
---------------------------------
#! /bin/sh -x
/usr/bin/sed 's/SVNVERSION/'`svnversion -n ..`'/' "$1" > "$2"
---------------------------------
Revision_template.cpp:
---------------------------------
#include <QString>
QString GetSvnRevisionNumber()
{
return QString::fromLatin1("SVNVERSION").trimmed();
}
PS The ".." in `svnversion -n ..` is because the working copy root is on
directory above where this is invoked. Adjust yours accordingly.
More information about the Qt-interest-old
mailing list