【问题标题】:qmake: Use flags from pkg-config if they exist, otherwise use defaultsqmake:如果存在,则使用 pkg-config 中的标志,否则使用默认值
【发布时间】:2015-12-22 02:27:13
【问题描述】:

在我的设置中,我希望同时支持系统范围的 Qt 安装和自定义 Qt 安装。我可以使用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
}

如何在我的项目配置中实现这一点?

【问题讨论】:

    标签: qt qmake pkg-config


    【解决方案1】:

    为此有一个 qmake 函数: http://doc.qt.io/qt-5/qmake-test-function-reference.html#packagesexist-packages

    packagesExist(Qt5Core) {
        PKGCONFIG += Qt5Core
    } else {
        INCLUDEPATH += /usr/local/qt5/
        LIBS += -lQt5Core
    }
    

    【讨论】:

      【解决方案2】:

      您可以使用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
      }
      

      【讨论】:

        猜你喜欢
        • 2013-11-20
        • 1970-01-01
        • 1970-01-01
        • 2013-09-10
        • 1970-01-01
        • 2013-06-03
        • 1970-01-01
        • 2011-12-01
        • 2021-07-27
        相关资源
        最近更新 更多