Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify Mac platform in qmake (QtCreator)

Tags:

macos

qt

qt4

qt5

qmake

I would like to set some configurations for Mac OS in pro file via QtCreator. I read the document, and found it supports Windows and Unix, like the following,

 win32 {
     SOURCES += hellowin.cpp
 }
 unix {
     SOURCES += hellounix.cpp
 }

I understand Mac OS is *nix-like OS, however, I still want to make difference with Linux. Is there a way to do this?


Ubuntu + Qt5.1

like image 697
CCC Avatar asked Aug 27 '13 10:08

CCC


2 Answers

You can detect Mac OS X this way:

macx {
    SOURCES += hellomac.cpp
}

But to make the difference with Linux you would rather like to specify

unix:!macx {
    SOURCES += hellolinux.cpp
}

macx: {
    SOURCES += hellomac.cpp
}
like image 109
Dmitry Avatar answered Nov 19 '22 22:11

Dmitry


'mac': it applies both on Mac OS X and iOS

'macx': it is specific to Mac OS X.

So, if you wanna include iOS support later, or simply be flexible (and why not?), you will better use 'mac'. Otherwise go for the latter. So you will need either of those.

Here you can find the official documentation:

http://qt-project.org/doc/qt-5.1/qmake/qmake-language.html#platform-scope-values

Here are the variants you may need based on your specific use case.

mac (including iOS support)

win32 {
    SOURCES += hellolinux.cpp
} mac {
    SOURCES += hellomac.cpp
}

macx

win32 {
    SOURCES += hellolinux.cpp
} macx {
    SOURCES += hellomacx.cpp
}

Here you can find the source code to seek more information about undocumented scopes:

http://qt.gitorious.org/qt/qtbase/source/730bc064a070e886e10950ccfd59780e8976f5fd:mkspecs

like image 20
lpapp Avatar answered Nov 19 '22 22:11

lpapp