How to run multiple commands with an extra target in QMake

qmake commands
qmake extra targets
qmake_extra_targets
qmake installs
undocumented qmake
qmake files function
qmake run shell command
qmake depends

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.

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.

Advanced Usage, For example, the following line tells qmake to execute a series of commands for this If you append a built-in install set to the INSTALLS variable and do not specify files or extra members, qmake Of course, you may want to tie one of these targets to the qmake build target. In many cases, however, this is not sufficient. A testcase project is an app project intended to be run as an automated test. Any app may be marked as a testcase by adding the value testcase to the CONFIG variable. For testcase projects, qmake will insert a check target into the generated Makefile. This target will run the application.

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

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

QMAKE_EXTRA_COMPILERS: single command for multiple targets , For example there is simple description for my extra compiler in .pro file: QMake generates the following Makefile's fragment: but moc is called once for each target, and I want to run the command once for several targets.

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 ...;

Pre-pre-build commands with qmake, Now, like most Qt developers, I use qmake to generate the Makefiles that are many other reasons that you may want a "pre-pre-build" command. and can actually confirm that the extra build target gets performed twice.

How to run a script after qmake? - qt - iOS, So far I've only found 2 ways to run a script from qmake: Using system() in my .pro I want to know if there is a way to add the command I want just as I wrote it, with no extras. You can run shell commands with qmake, using a custom target.

Tutorial on writing makefiles, Each one of these commands should be a separate rule in a makefile. The output files are also called targets, and the input files are also called Of course, if you contaminate your directories with extra files that shouldn't be compiled “-// IETF//DTD HTML//EN" <html <head <titleUsing Qt's moc preprocessor</title </ head.

The Vital Guide to Qmake, Readers that are new to Qt can use this guide as a tutorial to Qt's build system. Only a few of them supply dual configuration, e.g., qmake and CMake. instructs qmake to build a library sub-project first because other targets depend on it.

Comments
  • Fantastic, works like a charm! But out of curiosity: is there a reason that other threads seem to employ the ; \ as a line break without problem. Is this platform dependent?
  • It may be a shell-specific feature for joining multiple commands into one. On Windows && would work with standard cmd shell for example. I don't know unix-like shells well enough to answer with certainty.
  • @SergeySkoblikov: Under Unix, the && should work as well -> it runs the second command after the first, but only in case, the first one was successfully finished. Only & will run the second command anyway. Seems to be the same under windows?