29

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

László Papp
  • 51,870
  • 39
  • 111
  • 135
CCC
  • 2,164
  • 8
  • 27
  • 47
  • BTW, it's very important in Qt .pro file to have the brace `{` in the same line as the OS. If the brace goes in the next line, then it will not work. – iammilind May 11 '18 at 08:49

2 Answers2

39

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
}
Dmitry
  • 3,063
  • 2
  • 22
  • 32
  • thanks, It works. just don't know why there is no `macx` details in qt official document. [qmake manual link](http://qt-project.org/doc/qt-5.0/qtdoc/qmake-manual.html). Marked & upvote – CCC Aug 27 '13 at 11:44
  • It is just documented elsewhere - [running qmake](http://qt-project.org/doc/qt-4.8/qmake-running.html). `macx` is one of qmake's platform-specific specs. – Dmitry Aug 27 '13 at 14:19
  • thanks for your link. and would you please take a look at the **update**, I found a problem. – CCC Aug 27 '13 at 15:11
  • Sorry, I can't reproduce that. I've tried to add four files - hellomac.cpp, hellolinux.cpp, otherfile_mac.cpp, otherfile_linux.cpp + project file like yours. Qmake recognizes the conditions for sources inclusion just fine in both Mac OS X (10.8.4) and Linux (Mint 15 in my case). – Dmitry Aug 27 '13 at 19:43
  • never mind, I also believe Qt should recognize the conditions. Just make sure I don't miss another points on qmake. Thanks a lot. – CCC Aug 28 '13 at 01:25
  • @Dmitry: That is wrong. It is actually officially documented: http://qt-project.org/doc/qt-5.1/qmake/qmake-language.html#platform-scope-values – László Papp Sep 08 '13 at 09:42
  • It's funny that for me, `unix:!macx` works, but `macx` or `mac` does not. – Eduardo Reis Apr 25 '19 at 21:36
26

'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

László Papp
  • 51,870
  • 39
  • 111
  • 135