Issue
I have a Qt application which I'd like to run on Linux, however it uses an API which is only available on windows. There are maybe 2 or 3 classes which make use of the API and I've tried to not tightly couple them with the rest of the program. I could obviously use a lot of #ifdef win32
all over the place but I believe there should be a more Qt way of doing it within the .pro file.
Ideally I'd like qmake to detect the system and look for the API if it's win32. Then if it cannot find it or it's on a different platform, exclude the library and all the classes which include the headers from the API.
Here's an example of what I mean:
In.pro file I now have
SOURCES += main.cpp \
mainwindow.cpp \
win32apiwrapperclass.cpp \
...
LIBS += "a/path/to/win32/only/lib -lwin32only
INCLUDEPATH += "a/path/to/win32/only/includes"
DEPENDPATH += "a/path/to/win32/only/includes"
Also in MainWindow.h I have something like:
private:
Win32OnlyWrapperClass* win32owc;
and then win32owc is used in the cpp file a few times. So I'd like all of it excluded on other platforms as well. Hope it makes sense.
Thanks!
Solution
In .pro file you can do this:
win32:LIBS += "a/path/to/win32/only/lib -lwin32only
win32:INCLUDEPATH += "a/path/to/win32/only/includes"
win32:DEPENDPATH += "a/path/to/win32/only/includes"
or
win32 {
LIBS += "a/path/to/win32/only/lib -lwin32only
INCLUDEPATH += "a/path/to/win32/only/includes"
DEPENDPATH += "a/path/to/win32/only/includes"
}
https://doc.qt.io/archives/qt-4.8/qmake-advanced-usage.html#scopes-and-conditions
Answered By - Kirween Answer Checked By - Pedro (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.