2015-12-22 90 views
1

在我的设置中,我希望支持系统级Qt安装和自定义Qt安装。我可以用pkg-config,以获得正确的编译和链接标志我全系统安装:qmake:如果它们存在,使用pkg-config中的标志,否则使用默认值

CONFIG += link_pkgconfig 
PKGCONFIG += Qt5Core 

但是,如果pkg-config找不到Qt5Core,构建将失败,Project ERROR: Qt5Core development package not found

而不是失败,我想设置合理的默认值(例如/usr/local/qt5)。它应该达到如下:

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

我如何在我的项目配置做到这一点?

回答

1

可以使用system内置的测试功能,executes the given command in a secondary shell. Succeeds if the command returns with a zero exit status; otherwise fails.

system(pkg-config --exists Qt5Core) { 
    PKGCONFIG += Qt5Core 
} else { 
    INCLUDEPATH += /usr/local/qt5/ 
    LIBS += -lQt5Core 
} 
相关问题