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

后端 未结 4 706
醉话见心
醉话见心 2020-12-01 12:40

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.

相关标签:
4条回答
  • 2020-12-01 12:56

    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

    0 讨论(0)
  • 2020-12-01 13:03

    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.

    0 讨论(0)
  • 2020-12-01 13:04

    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!

    0 讨论(0)
  • 2020-12-01 13:10

    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

    0 讨论(0)
提交回复
热议问题