[SailfishDevel] Check for OS in .PRO file

Timur Kristóf timur.kristof at gmail.com
Fri Jan 3 11:21:43 UTC 2014


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> wrote:

> Hi,
>
> On 02 Jan 2014, at 20:25, Sven Putze <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
> _______________________________________________
> SailfishOS.org Devel mailing list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.sailfishos.org/pipermail/devel/attachments/20140103/f29b9974/attachment.html>


More information about the Devel mailing list