【问题标题】:How to prepend the contents of a .pri file with a path?如何在 .pri 文件的内容前面加上路径?
【发布时间】:2013-02-08 05:38:01
【问题描述】:

我有以下目录结构,我想使用 Qt .pri 文件来简化事情。

Project1/
    project1.pro
    main.cpp
    Algorithms/
        algorithm1.h
        algorithm1.cpp
        ...
        // add an algorithms.pri file here
    Utilities/           
        utiliy1.h
        utiliy1.cpp
        ...
        // add an utilities.pri file here
    Gui/
        gui1.h
        gui1.cpp
        ...
        // add a gui.pri file here

AlgorithmsUnitTest/
     algorithms_unit_test.pro
     main.cpp

UtilitiesUnitTest/
     utilities_unit_test.pro
     main.cpp

我要解决的一个问题是,当我从 AlgorithmsUtilitiesGui 文件夹之一添加或删除源文件时,我必须从所有其他 @ 文件夹中删除它987654325@ 文件。

我想为每个包含源文件和头文件的文件夹创建一个.pri 文件。这些文件将包含在所有其他项目中。然后,如果我添加/删除一个源文件或头文件,我只会从相应的.pri 文件中删除它。

这种方法的问题在于,在.pro 文件中包含.pri 文件只是简单的复制粘贴。也就是说,如果algorithms_unit_test.pro 包含algorithms.pri 文件,qmake 构建系统将在不存在的AlgorithmsUnitTest/Algorithms 文件夹中查找文件。

解决方案是在 .pri 文件的内容前面加上

../Project1/

但我不知道该怎么做。请你教我怎么做或建议一些其他方式来组织我的项目?

【问题讨论】:

    标签: c++ qt build qmake


    【解决方案1】:

    您可以在您的 .pri 文件中使用 qmake 变量 PWD

    algorithms.pri

    SOURCES      += $$PWD/algorithm1.cpp
    HEADERS      += $$PWD/algorithm1.h
    

    utilities.pri

    SOURCES      += $$PWD/utiliy1.cpp
    HEADERS      += $$PWD/utiliy1.h
    

    ...

    http://doc.qt.digia.com/qt/qmake-variable-reference.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-11
      • 1970-01-01
      • 2010-09-10
      • 1970-01-01
      • 2011-07-22
      • 1970-01-01
      • 2017-06-09
      • 1970-01-01
      相关资源
      最近更新 更多