3

Since I'm using today's date for my application version, I'd be interested in filling it automatically.

Currently I'm doing the following in my project file:

VERSION = 15.4.20 

But I'd like to make it automatic:

VERSION = $$YEAR.$$MONTH.$$DAY

Any idea?

Martin Delille
  • 11,360
  • 15
  • 65
  • 132

3 Answers3

4

You can use QMAKE_POST_LINK with something like

$$version = date +%y.%m.%d

Edit

On Mac OS you can use:

VERSION = $$system(date +%y.%m.%d)

Adapt it to fit your others supported OS ;)

Thomas Ayoub
  • 29,063
  • 15
  • 95
  • 142
  • this can not be a post link step since the version number is used during build. – Martin Delille Apr 20 '15 at 16:39
  • but using the date command with the arg you gave is interesting! – Martin Delille Apr 20 '15 at 16:40
  • 1
    @MartinDelille if you need more information about [a trick for prebuild step in Qt](http://stackoverflow.com/questions/5083441/how-to-add-pre-build-step-in-qmake-qtcreator) – Thomas Ayoub Apr 20 '15 at 16:44
  • On Windows,this could be `VERSION = $$system(date /t) $$system(time /t)` – Andy.G Aug 22 '18 at 01:56
  • @Andy.G On Windows this kind of not work. It works for the "product version", but not for the "file version". In the "file version" the date is taken as a math operation because of the `-` between the years, months and days values. It is the result of this math operation that is put inside the "file version" field. – Benjamin T Feb 15 '19 at 11:55
3

Another option is to use undocumented qmake variable _DATE_, which is available on all platforms:

BUILD_YEAR = $$str_member($${_DATE_}, -4, -1)
message("Build year '$${BUILD_YEAR}' out of '$${_DATE_}'")

See Undocumented QMake

matejk
  • 798
  • 1
  • 14
  • 27
0

In our case, we just needed year for copyright:

company = My-Company
win32 {
    year = $$system("echo %date:~10,4%")
} else {
    year = $$system("date +%Y")
}
copyright = "Copyright (C) 2017-$$year, $$company"

Also, we used commit-hash decimal as version suffix:

win32 {
    commit = $$system("FOR /F \"tokens=*\" %H IN ('git rev-parse --short HEAD') DO @SET /A DECIMAL=0x%H")
} else {
    commit = $$system("printf '%d' 0x`git rev-parse --short HEAD`")
}
Top-Master
  • 7,611
  • 5
  • 39
  • 71