Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Saving value from Custom Proccess Step (Build Steps)



  • Hi guys,

    I am playing around with custom build steps. I have an executable which does some action for me that I want to happen when I build my program.

    I have tried using system() in the .pro file, the executable is called successfully from the .pro file but there are some issues.
    First is I noticed it is called 3 times (after some research I noticed its because there are more than one makefiles generated).
    Second is that the .pro file doesn't seem to be run(?) on every build. I have to run qmake manually to get it to run the executable.
    Due to those reasons I have decided to try calling it in a custom step. This step is run every time.
    The call is successful but what I cannot do now is save the cout value from the executable for use in my qt c++ project.

    I need to display the string from the .exe's cout in the compiled program. Is there a way I can either force qmake one time on a build everytime, OR save the cout value from the executable like i can from $$system() in the .pro file?

    Thanks,
    Shawn.


  • Lifetime Qt Champion

    Hi @MrShawn said in Saving value from Custom Proccess Step (Build Steps):

    I need to display the string from the .exe's cout in the compiled program.

    So in principle the same question as this one: https://stackoverflow.com/questions/5946896/how-to-execute-shell-command-after-compile-finished-from-pro-in-qt ?

    Is there a way I can either force qmake one time on a build everytime,

    Yeah, by adding a qmake command that is executed on make rather than on qmake, see e.g. here: http://doc.qt.io/qt-5/qmake-advanced-usage.html#adding-custom-targets

    OR save the cout value from the executable like i can from $$system() in the .pro file?

    Where should the output be save?

    Personally, I think adding these steps in the .pro file is better, as it just works after cloning to another machine or building without Creator (e.g. in Jenkins).

    Regards



  • Okay @aha_1980,
    First, thanks for responding, I got busy friday with actual work so I didn't get to respond sooner. I am trying to take the .pro approach.

    I looked at the resources you linked and I am still pretty lost. Trying to make sense of it without much progress.
    I see things being added to my makefiles. But I do not see those portions being executed.

    I added to the .pro file (this is from your second link):

    mytarget.target = .buildfile
    mytarget.commands = touch $$mytarget.target
    mytarget.depends = mytarget2
    
    mytarget2.commands = @echo Building $$mytarget.target
    
    QMAKE_EXTRA_TARGETS += mytarget mytarget2
    

    I run qmake and build and do not see the output from the echo at all.

    What I am not seeing is how it gets called. Am I supposed to add another step to call the new targets? From both links, and a 3rd (https://stackoverflow.com/questions/29853832/adding-custom-commands-to-existing-targets-in-qmake) it looks straight forward but nothing seems to be happening.

    Thanks


Log in to reply