c++ - qt generate header file containing git hash at compile time and force rebuild using files -


i figured out how generate define macro containing git hash @ compile time:

defines += git_current_sha1="\\\"$(shell git -c \""$$_pro_file_pwd_"\" describe)\\\"" 

the problem when git hash changed, files (mainwindow.cpp adding text dialog) using git_current_sha1 not automatically rebuilt (obviously)..

i generate header file @ compile time containing git hash in const char *git_hash="git-hash-etc-etc";

and header file include in mainwindow.cpp , hope recompiled when header changes..

my question add .pro file generate such file makefile?

thanks.

just evidence script used git version on linux:

#!/bin/bash  echo "generating header git hash" $1 $2 git_header="$1/$2" if [ -z "$2" ];         git_header="$1/git_version.h" fi  git_version="`git -c \"$1\" describe`" if grep --quiet $git_version $git_header;         echo "no need generate new $git_header - git hash unchanged"         exit 0; fi  echo "git version is:" $git_version  echo "#ifndef git_version_h" > $git_header echo "#define git_version_h" >> $git_header echo "" >> $git_header echo "#define git_current_sha1 \"$git_version\"" >> $git_header echo "#endif //git_version_h" >> $git_header  echo "file generated into" $git_header 

and in .pro:

gitversion = git_version.h versiontarget.target =  $$gitversion versiontarget.commands = '$$pwd/git_version.sh \"$$pwd\" $$gitversion' versiontarget.depends = force pre_targetdeps += $$gitversion qmake_extra_targets += versiontarget 

Comments

Popular posts from this blog

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -