qtcreator使用git提供版本号

一、git配置

* 打标签 git tag -a <commit-id>
* [查看版本号 git describe --tags --dirty]

二、windows脚本

* version.cmd

```
del version.h

echo #ifndef VERSION_H >>version.h
echo #define VERSION_H >>version.h
echo. >>version.h
echo. >>version.h

for /f "delims=" %%i in ('git describe --tags --dirty') do (set a=%%i)
echo #define GIT_VERSION "%a%" >>version.h
echo. >>version.h
echo. >>version.h

echo #endif // VERSION_H >>version.h
```

三、自定义构建步骤

* 在“项目-构建步骤”里添加一个步骤,移动到qmake之前

* 可用的工作目录
```
%{CurrentProject:Name}
%{CurrentKit:FileSystemName}
%{CurrentBuild:Name}
%{buildDir}
%{sourceDir}
```

posted @ 2018-02-08 10:26  zhang846682029  阅读(421)  评论(0编辑  收藏  举报