camino
camino

Reputation: 10584

How to execute shell command after compile finished from .pro in QT?

What changes must I make to the .pro file if I want to execute chmod command, execute the output binary file, or do some other operations.

Upvotes: 20

Views: 20169

Answers (4)

ephemerr
ephemerr

Reputation: 1983

Another way to make things in given order is to use empty "super" target:

super.depends = target_pre first target_post
QMAKE_EXTRA_TARGETS += super

Where first - is default qmake target, and target_pre and target_post some custom targets. Now make super just do the thing.

EDIT: looks like in last versions of Qt build of dependencies is running in paralell so this solution wouldn't work.

Upvotes: 1

Dariusz Scharsig
Dariusz Scharsig

Reputation: 1220

I had a similar problem. I wanted a special tool (versioner) to run over the code every time the Makefile was executed. Here's the solution:

(to be read in the Qmake Manual, Configuring qmake's Environment, Section: Customizing Makefile Output)

Create you own Makefile target. Specify the command etc.

mytarget.target = .buildfile
mytarget.commands = touch $$mytarget.target

QMAKE_EXTRA_TARGETS += mytarget

This way, you have an extra target you can call with make mytarget for example. If you want to tie it together to the actual buildtarget you'll have to add:

POST_TARGETDEPS += mytarget

Hope that helps.

Best regards
D

Upvotes: 27

BuvinJ
BuvinJ

Reputation: 11048

The right answer depends on exactly what you want, and when. However, as seen in some previously posted comments here QMAKE_POST_LINK is probably what you want rather than POST_TARGETDEPS.

Check out this related post: QMake: execute script after build

For one, when you use POST_TARGETDEPS that fires off BEFORE your exe is created (in Windows) or BEFORE it is recreated (in Linux)! QMake works differently depending upon the platform and the complier.

I needed to do some "symbols processing" on an exe when it was recompiled. POST_TARGETDEPS gave me problems in both Windows (using mingw) and Linux (using gcc). In Windows, it executed my script prematurely, and in Linux it overwrote my exe after I had modified it (i.e. added back my debugging info to the exe after I had stripped it in my external script). QMAKE_POST_LINK worked perfectly, however, in both cases. It's also short, sweet, and more clear by comparison!

Upvotes: 0

Stephen Chu
Stephen Chu

Reputation: 12832

If you are using Qt Creator, you can add custom build steps in the Projects panel: http://doc.qt.nokia.com/qtcreator-2.1/creator-build-settings.html#adding-custom-build-steps

Upvotes: 0

Related Questions