Yellow
Yellow

Reputation: 3957

How to run multiple commands with an extra target in QMake

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.

Upvotes: 16

Views: 9604

Answers (3)

Chnossos
Chnossos

Reputation: 10486

You can also append to the .commands variable if you want to avoid backslashes:

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

Or:

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

Upvotes: 1

Chris Desjardins
Chris Desjardins

Reputation: 2720

The and operator also works for me on Linux, and strangely windows.

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

Upvotes: 6

Sergey Skoblikov
Sergey Skoblikov

Reputation: 5900

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.

Upvotes: 26

Related Questions