3

I want to get the distribution name and version name of OS in qmake. For Linux, in some distributions (Debian, Ubuntu, CentOS, ...), I used:

DISTRIBUTION = $$system(cat /etc/issue | cut -d\' \' -f1)
message($$DISTRIBUTION)
OSVERSION = $$system(cat /etc/issue | cut -d\' \' -f3)
message($$OSVERSION)

On my Debian 7.8, the output is:

Project MESSAGE: Debian
Project MESSAGE: 7

This is a correct result. But I'm not sure about this way. I'm finding for Windows too: Windows 7, 8, ...

Do you have any idea about this in qmake?

aviit
  • 1,957
  • 1
  • 27
  • 50

1 Answers1

3

You can use conditional assignments (see Scopes and Contitions) ex.

win32:DISTRIBUTION = $$system(systeminfo | findstr /B /C:"OS Name")
unix:DISTRIBUTION = $$system(cat /etc/issue | cut -d\' \' -f1)
message($$DISTRIBUTION)

This way, the code will execute only on specific platforms. The command for Windows that I provided isn't the one you want, it prints the whole system name with version, you will have to modify it somehow.

prajmus
  • 3,171
  • 3
  • 31
  • 41
  • 1
    Maybe I found an alternative to the expensive systeminfo call under windows on this site: http://www.windows-commandline.com/find-windows-os-version-from-command/ This command produces an equivalent string for testing: `wmic os get Caption,CSDVersion /value` – tomy Jul 19 '16 at 08:37