Question

I'm trying to add the output of "git describe" to the about window of my application, so it's easier to find out what version of the application people use.

I can do it by adding the following compiler flag: -DAPP_VERSION="$(git describe HEAD)"

But since the project is based on qmake, I would like to find a way to put this into the Qt project file. Is this possible? And if so, how?

edit: I tried adding the following:

QMAKE_CXXFLAGS += -DAPP_VERSION="$(git describe HEAD)"

But it just gave me "-DAPP_VERSION=", so I suppose I have to use some escape characters, but I don't know which ones and where. :/

Was it helpful?

Solution

Problem solved thanks to this link: http://robertcarlsen.net/blog/2009/01/06/qmake-xcode-bug-258

Here's a sample qt project I used to test it: qt.pro:

######################################################################
# Automatically generated by qmake (2.01a) Thu Apr 2 16:23:05 2009
######################################################################

TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .

# Input
SOURCES += qt.cpp

QMAKE_CXXFLAGS += -DAPP_DATE=\\\"`date +'\"%a_%b_%d,_%Y\"'`\\\"
QMAKE_CXXFLAGS += -DAPP_VERSION=\\\"`git describe`\\\"

qt.cpp:

#ifndef APP_DATE
#define APP_DATE "1/1/1970"
#endif

#ifndef APP_VERSION
#define APP_VERSION "local-dev"
#endif

#include <QApplication>
#include <QLabel>
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QString version = QString("version ") + APP_VERSION + ' ' + APP_DATE;
    QLabel *label = new QLabel(version);
    label->show();
    return app.exec();
}

OTHER TIPS

You can also use

QMAKE_CXXFLAGS += -DAPP_VERSION=\\\"$$system(git describe HEAD)\\\"

This will execute the git command only once during the qmake run which might speed up compilation for large projects. However, you must make sure to run qmake and make clean after pulling from the repository.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top