Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

qmake: Use flags from pkg-config if they exist, otherwise use defaults

In my setup, I want to support both system-wide Qt installations and custom Qt installations. I can use pkg-config to get the correct compile and link flags for my system-wide installation:

CONFIG += link_pkgconfig
PKGCONFIG += Qt5Core

However, if pkg-config cannot find Qt5Core, the build will fail with Project ERROR: Qt5Core development package not found.

Instead of failing, I want to set reasonable defaults (e.g. /usr/local/qt5). It should achieve the following:

if pkg-config can find Qt5Core {
    PKGCONFIG += Qt5Core
} else {
    INCLUDEPATH += /usr/local/qt5/
    LIBS += -lQt5Core
}

How can I accomplish this in my project configuration?

like image 652
morxa Avatar asked Jan 23 '26 09:01

morxa


1 Answers

There is a qmake function for this: http://doc.qt.io/qt-5/qmake-test-function-reference.html#packagesexist-packages

packagesExist(Qt5Core) {
    PKGCONFIG += Qt5Core
} else {
    INCLUDEPATH += /usr/local/qt5/
    LIBS += -lQt5Core
}
like image 56
Former contributor Avatar answered Jan 26 '26 02:01

Former contributor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!