[SailfishDevel] Check for OS in .PRO file

Thomas Perl th.perl at gmail.com
Thu Jan 2 19:44:39 UTC 2014


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


More information about the Devel mailing list