[solved] Git describe in project file / Makefile



  • I'm trying to add git-tags to our program, using something like:

    @DEFINES += GITHASH=$(shell git describe)@

    in the project file. This method was suggested elsewhere (http://qt-project.org/forums/viewthread/34635), because it adds the command to the Makefile, therefore not requiring a re-run of qmake every time. However, its not working for us. The statement ends up in the Makefile as:

    @-DGITHASH=$(shell git describe)@

    but seems to be missing some quotation marks / slashes which (with my limited experience with Qt) I can't seem to add. Can anyone point me in the right direction of the correct syntax for such a statement in a Qt project file?


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Do you mean something like:

    @DEFINES += GITHASH="$(shell git describe)"@

    ?

    If not, what is the exact output that you would like to see in the Makefile ?



  • If I try that, it returns in the Makefile as:

    @DEFINES = -DGITHASH="$(shell -Dgit -Ddescribe)"@


  • Lifetime Qt Champion

    Ok, but then what would you expect to have in your Makefile ? Furthermore, what OS/Qt version are you using ?



  • Both OS X (10.9) and Arch linux with Qt5.1.1

    To be honest, I have no idea what should be in there. I guess that the general question should be: how can I get the command line output from 'git describe' into Qt/C++. Most other options that I've seen require some pre-processing step, building a header file from/with a separate script, but to me it seems that there should be easier ways?


  • Lifetime Qt Champion

    For 10.9 I would recommend upgrading to 5.2

    Try this

    @
    REVISION = $$system(git --git-dir $$PWD/.git --work-tree $$PWD describe)
    DEFINES += GITHASH=\\"\"$$REVISION\\"\"
    @

    Git must be in your path



  • Thanks for helping! It's a bit awkward with all these escape characters, but with:

    @DEFINES += GITHASH=\"$$REVISION\"@

    it works. So combined:

    @REVISION = $$system(git --git-dir $$PWD/.git --work-tree $$PWD describe)
    DEFINES += GITHASH=\"$$REVISION\"@

    does the trick.


  • Lifetime Qt Champion

    Welcome to the wonderful world of console + pro file char escaping. With the "awkward" version you should be safe for all OSs


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.