【问题标题】:Adding building steps in Qt .pro file在 Qt .pro 文件中添加构建步骤
【发布时间】:2021-11-09 03:57:25
【问题描述】:

从 QtCreator “项目 - 添加构建步骤”,可以指定添加的构建步骤。例如,以下设置将在项目构建时回显一条消息。

添加的构建步骤实际上出现在对应的.pro.user文件中:

<value type="QString" key="ProjectExplorer.ProcessStep.Arguments">hello. This is my custom process step.</value>
<value type="QString" key="ProjectExplorer.ProcessStep.Command">/usr/bin/echo</value>

我的问题是:有没有办法在 .pro 文件中添加构建步骤而不是使用 GUI(“项目 - 添加构建步骤”)并实际将设置添加到 .pro.user 文件? (对我来说,优点是 .pro 文件可以很容易地使用 shell 脚本进行批处理。)

我尝试将步骤放在 .pro 文件中,并使用 QMAKE_EXTRA_TARGETS 作为

mystep.commands = echo 'hello. This is my custom process step'
QMAKE_EXTRA_TARGETS += mystep

但是,使用命令行中的qmake; make,只会发生原始构建。只有在进一步make mystep 之后,才会发生回声。换句话说,mystep 步骤不会发生在正常的make 上——也许我误解了QMAKE_EXTRA_TARGETS

【问题讨论】:

  • 也许尝试添加PRE_TARGETDEPS += mystep
  • 试过'qmake; make` 与 'PRE_TARGETDEPS += mystep` 编码。它抱怨 make: *** No rule to make target 'mystep', needed by 原始目标。

标签: qt qt-creator qmake


【解决方案1】:

很高兴您找到了适合您的答案。我想澄清我在上面所做的评论,因为我尝试过它并且对我来说效果很好。 (而且看起来比您的解决方案简单得多。)我认为它对您不起作用的原因是因为我打算将 PRE_TARGETDEPS 与您已经拥有的 QMAKE_EXTRA_TARGETS 结合起来。这应该就是您所需要的。

mystep.commands = echo 'hello. This is my custom process step'
QMAKE_EXTRA_TARGETS += mystep
PRE_TARGETDEPS += mystep

【讨论】:

  • 感谢您的澄清。你的答案比我的好,因为你的答案比你提到的要简单得多。你对我的错误是对的。再次感谢。
【解决方案2】:

经过一段时间的挖掘,我找到了一个解决方案 - 使用 QMAKE_EXTRA_COMPILERS。

# must use a variable as input
PHONY_DEPS = .
mystep.input = PHONY_DEPS
# use non-existing file here to execute every time
mystep.output = phony.txt
# the system call to the batch file
mystep.commands = echo 'hello. This is my custom process step'
# some name that displays during execution
mystep.name = running mystep...
# "no_link" tells qmake we don’t need to add the output to the object files for linking
# "no_clean" means there is no clean step for them.
# "target_predeps" tells qmake that the output of this needs to exist before we can do the rest of our compilation.
mystep.CONFIG += no_link no_clean target_predeps
# Add the compiler to the list of 'extra compilers'.
QMAKE_EXTRA_COMPILERS += mystep

对于我的实际应用程序,它不仅仅是一个回显,我将指定不同的输出/配置。

参考:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-19
    相关资源
    最近更新 更多