[SailfishDevel] Check for OS in .PRO file

Oleksii Serdiuk contacts at oleksii.name
Sun Jan 5 10:54:25 UTC 2014


I use similar approach, but I do

qmake CONFIG+=sailfish

and then I can check for it in the .pro file like this:

sailfish {
     DEFINES += Q_OS_SAILFISH
     ...
}

Looks shorter and cleaner to me :-)

On 03.01.2014 12:21, Timur Kristóf wrote:
> Hi,
>
> What Thomas said makes sense, I just want to add one more little thing.
> You can, in the .spec file, add stuff to qmake, like this define. This
> would make the necessary code shorter and as a bonus, it gives you
> something you can even ifdef in C++.
>
> # spec file
> qmake DEFINES+=IS_SAILFISH_OS
>
> # pro file
> contains(DEFINES, IS_SAILFISH_OS) {
>    ...
> }
>
> // C++ file
> #if defined(IS_SAILFISH_OS)
>    ...
> #endif
>
> Cheers,
> Timur
>
>
>
> Timur
>
>
>
> On Thu, Jan 2, 2014 at 8:44 PM, Thomas Perl <th.perl at gmail.com
> <mailto:th.perl at gmail.com>> wrote:
>
>     Hi,
>
>     On 02 Jan 2014, at 20:25, Sven Putze <sailfish.os at hardcodes.de
>     <mailto:sailfish.os at hardcodes.de>> wrote:
>      > There are ways to check for the OS in QtCreator .PRO files, e.g. like
>      >
>      > unix:symbian{ # do stuff}
>      > unix:maemo5{ # do stuff}
>      > macx{ # do stuff}
>      > win32{ # do stuff}
>      >
>      > Is there a way to check (or control to be more precise) that some
>     directives are only used when compiling on the MerSDL VM?
>      > Just checking for the presence of "sailfishapp" does not work,
>     because that is defined for any OS.
>
>
>     In general, it might just be easier (and more maintainable) to have
>     a per-platform .pro file for your project and not litter your .pro
>     file with lots of conditionals (been there, done that - it will
>     become hard to read, understand and maintain as the number of
>     platforms grows). If there’s a lot of common things that you need in
>     each file, put that in a .pri file and include it in each
>     platform-specific .pro file. Then, in the sailfish .spec, you can
>     call qmake on the sailfish-specific project file, in the Maemo 5
>     debian/rules script, you call qmake on the maemo5 .pro file, etc…
>
>     With that said, you can use packagesExist[1] to do sailfish-specific
>     things if you are convinced that a single .pro file really is the
>     way to go:
>
>     packagesExist(sailfishapp) { .. do stuff .. }
>
>     Alternatively, set an environment variable in the qmake call in the
>     .spec file and check for that variable in the .pro file:
>
>     # In the .spec file:
>     IS_SAILFISH_OS=1 qmake
>
>     # In the .pro file:
>     IS_SAILFISH_OS = $$(IS_SAILFISH_OS)
>     contains(IS_SAILFISH_OS, 1) {
>          .. do stuff ..
>     }
>
>
>     HTH :)
>     Thomas
>
>     [1]
>     http://qt-project.org/doc/qt-4.8/qmake-function-reference.html#packagesexist-packages

-- 
With best regards,
Oleksii Serdiuk

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4813 bytes
Desc: S/MIME Cryptographic Signature
URL: <https://lists.sailfishos.org/pipermail/devel/attachments/20140105/2df8ed56/attachment.bin>


More information about the Devel mailing list