how to include files to qt project depending on target operating system
-
Hi,
If you have only minor changes between platforms, why not use the
Q_OS_XXX
macros like Q_OS_LINUX ? -
Hi,
If you have only minor changes between platforms, why not use the
Q_OS_XXX
macros like Q_OS_LINUX ? -
@SGaist I have never heard of these macros before. I will try it in my code but it seems a good solution for my problem at first glance. Thank you!
I believe you can use these macros only inside of your classes and not in the project file itself. But I might be mistaken.
To differ between OS inside the project file I usually use these:
- win32
- macx
- unix
eg:
win32:DEFINES += QT_DLL macx:debug { HEADERS += debugging.h } win32|macx { HEADERS += debugging.h }
Taken from the docu here:
-
@J-Hilk Indeed, that's the goal of these macros. The suggestion was that you don't necessarily need to have one file per platform every time there's a small change to adapt to that platform. There should be a balance between the platform specific macros in code and write platform specific files when the code is too big or too involved to fit nicely between macro guards.
-
@J-Hilk Indeed, that's the goal of these macros. The suggestion was that you don't necessarily need to have one file per platform every time there's a small change to adapt to that platform. There should be a balance between the platform specific macros in code and write platform specific files when the code is too big or too involved to fit nicely between macro guards.
@SGaist ah, ok, that makes total sence now. And in fact I do use those macros myself in my classes on a regular base.
It's just the docu about qmake could really use an update!
Just recently I searched through there to find out, how to automatically link precompiled libaries depending on the compiler set/used for my project.Eventually I found that information, but it took way to long to find, for such an easy solution.
-
Documentation can always be improved ;)
If you find something unclear or hard to find, you can contribute an update that will make everyone's life easier. All the documentation is within Qt source tree so you're welcome to improve it and submit a patch :)
-
wrote on 19 May 2017, 11:10 last edited by
So far I tried the Q_OS_xxx Macros within my source and header files. It works fine! Thank you!
However, qmake recognizes my host OS (Linux) before it actually catches that my target OS is Android. I moved Bonjour related files into the .pri files and therefore these files are added to the project although I do not want them there.
I will try the solution from @J-Hilk the next days. I think it can solve my problems.I am curious, how can I remove files from a project within my .pri files?
-
Remove ? Usually you use scopes in your .pro or .pri file to add files to build for the platforms you are currently working on.
-
wrote on 22 May 2017, 06:26 last edited by
My solution is:
I added all header and source files in the .pro file and for Android I removed conflicting files in android.pri file withHEADERS -= ... SOURCES -= ...
Thanks a lot for your solutions!
-
That's pretty counter intuitive and a maintenance nightmare in the making.
Why not just have a scope in your .pro files that includes your android specific files when working on the android platform and the other files in the else statement ? i.e.
android { SOURCES += android_stuff.cpp HEADERS += something.h } else { SOURCES += other_stuff.cpp HEADERS += something_else.h }
From a maintainer point of view, removing files from the build system really doesn't make sense.
11/11