Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run multiple commands with an extra target in QMake

Tags:

qt

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.

like image 758
Yellow Avatar asked Aug 05 '13 14:08

Yellow


2 Answers

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.

like image 183
Sergey Skoblikov Avatar answered Sep 19 '22 01:09

Sergey Skoblikov


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

something.commands = mkdir newFolder && copy /Y someFolder\\file.dll newFolder
like image 30
Chris Desjardins Avatar answered Sep 21 '22 01:09

Chris Desjardins