How to run multiple commands with an extra target in QMake

Yellow picture Yellow · Aug 5, 2013 · Viewed 7.9k times · Source

I am making extra targets using qmake, and I'm trying to do two things at the same time: make a new folder, and copy a dll into that folder. Both action separate work fine, but the two together don't work.

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

I thought this was the right syntax (I found similar examples for example here and here), but I am getting the following error:

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

Is the syntax different on different platforms or something? I'm working on Windows 7, with Qt 5.0.1.

Answer

Sergey Skoblikov picture Sergey Skoblikov · Aug 8, 2013

The value of .commands variable is pasted in the place of target commands in Makefile by qmake as is. qmake strips any whitespaces from values and changes them into single spaces so it's impossible to create multiline value without a special tool. And there is the tool: function escape_expand. Try this:

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

$$escape_expand(\n\t) adds new line character (ends previous command) and starts next command with a tab character as Makefile syntax dictates.