为 qmake 目标指定多个参数可变的命令

Specify several commands with variable number of args for qmake target

在使用 QMake 的 Qt 项目中,我有一个带有自定义命令的目标 my_tool,它可以接受任意数量的参数:

target.commands = my_tool.exe arg01 arg02  # works fine

如果我现在需要 运行 该命令两次 ...

target.commands = my_tool.exe arg01 arg02
target.commands += my_tool.exe another_arg01 another_arg02  # breaks

... 对于该目标,第一个命令失败,因为第二个命令用作第一个命令的参数。如:当我输出第一个命令的参数时,它说:

ARGV[0]: my_tool.exe
ARGV[1]: arg01
ARGV[2]: arg02
ARGV[3]: my_tool.exe
ARGV[4]: another_arg01
ARGV[5]: another_arg02

我如何添加第二个命令以便单独处理它?

感谢您的帮助或指点。 :)

方式一

一种可能性是简单地使用两个单独的目标:

target1.commands = my_tool.exe arg01 arg02
target2.commands = my_tool.exe another_arg01 another_arg02

...并使一个依赖另一个:

target1.depends = target2

方式二

另一种方法是在命令之间指定$$escape_expand(\n\t)&&

target.commands = my_tool.exe arg01 arg02  $$escape_expand(\n\t)  my_tool.exe another_arg01 another_arg02

target.commands = my_tool.exe arg01 arg02  &&  my_tool.exe another_arg01 another_arg02

所以有很多方法可供选择。 :)