'Get the date with qmake

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?



Solution 1:[1]

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

Solution 2:[2]

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`")
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 matejk
Solution 2 Top-Master