QT Version from Git

Rezepte um sich die Version des Projekts aus Git zu holen.

Mit cmake

Da ich dies inzwischen nicht nur in meinen Qt Projekten, sondern generell verwende, habe ich das Vorgehen auf einer separaten Seite beschrieben: Version aus Git mit cmake.

Mit qmake

Wird nicht mehr weiter entwickelt, da es mir nicht gelungen ist eine entsprechende Datei version.h zu generieren.

gitversion.pri
# Try to get version from git tag GIT_VERSION = $$system("git describe --tags --long --always --dirty=+") GIT_V_ARR = $$split(GIT_VERSION, "-") count(GIT_V_ARR, 1) { # apparently only hash and no version tag GIT_COMMITS = $$system("git rev-list --count HEAD") GIT_COMMIT = $$system("git rev-parse --short HEAD") VERSION = "0.0" } else { GIT_V_TAG = $$member(GIT_V_ARR, 0) GIT_V_TAG ~= s/^v/""/ GIT_COMMITS = $$member(GIT_V_ARR, 1) GIT_COMMIT = $$member(GIT_V_ARR, 2) GIT_COMMIT ~= s/^g/""/ VERSION = $${GIT_V_TAG} } # Add to C preprocessor so we can use it in C++ code DEFINES += GIT_COMMIT=\\\"$$GIT_COMMIT\\\" DEFINES += GIT_COMMITS=\\\"$$GIT_COMMITS\\\" DEFINES += VERSION=\\\"$$VERSION\\\"


project.pro