如何在QMake中运行带有额外目标的多个命令

问题描述 投票:14回答:3

我正在使用qmake设置额外的目标,并且我试图同时做两件事:创建一个新文件夹,然后将dll复制到该文件夹​​中。两种操作分开工作都可以,但是两者不能一起工作。

something.target = this

# This works:
# something.commands =   mkdir newFolder
# This works too (if newFolder exists)
# something.commands =   copy /Y someFolder\\file.dll newFolder

# This doesn't work:
something.commands = mkdir newFolder; \
                     copy /Y someFolder\\file.dll newFolder

QMAKE_EXTRA_TARGETS += something
PRE_TARGETDEPS += this

我以为这是正确的语法(我发现了类似的示例,例如herehere,但是我遇到了以下错误:

> mkdir newFolder; copy /Y someFolder\\file.dll newFolder
> The syntax of the command is incorrect.

语法在不同平台上或其他地方是否不同?我正在使用Qt 5.0.1的Windows 7。

qt qmake
3个回答
22
投票

.commands变量的值按原样通过qmake粘贴到Makefile中目标命令的位置。 qmake从值中剥离所有空格并将其更改为单个空格,因此,如果没有特殊工具,就无法创建多行值。还有工具:函数escape_expand。试试这个:

something.commands = mkdir newFolder $$escape_expand(\n\t) copy /Y someFolder\\file.dll newFolder

$$escape_expand(\n\t)添加新的行字符(结束上一个命令),并根据Makefile语法指示,以制表符开始下一个命令。


4
投票

and运算符在Linux和Windows上也适用于我。

something.commands = mkdir newFolder && copy /Y someFolder\\file.dll newFolder

0
投票

如果要避免反斜杠,也可以附加到.commands变量:

target.commands += mkdir toto
target.commands += && copy ...
# Result will be:
target:
    mkdir toto && copy ...

或:

target.commands += mkdir toto;
target.commands += copy ...;
# Result will be:
target:
    mkdir toto; copy ...;
© www.soinside.com 2019 - 2024. All rights reserved.