Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Calling a shell file from .pro file

Calling a shell file from .pro file

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 1.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Augustas
    wrote on 27 Oct 2021, 11:31 last edited by Augustas
    #1

    Hello,

    I'm trying to call a shell file from the .pro file using qmake.

    According to the documentation (https://doc.qt.io/qt-5/qmake-advanced-usage.html#adding-custom-targets), adding my target to QMAKE_EXTRA_TARGETS should work, however, even if I call "@echo test" command on a fresh project, it doesn't seem to get executed.

    What seems to work on windows, is adding my target not only to QMAKE_EXTRA_TARGETS , but also to PRE_TARGETDEPS or POST_TARGETDEPS.

    However, if I add my target to PRE_TARGETDEPS or POST_TARGETDEPS on Mac, I get "No rule to make target" error.

    What would be the appropriate way of calling a shell file from .pro file, since the one provided in the documentation doesn't seem to work?
    I'm using MacOS Big Sur on a Mac Mini M1.

    R 1 Reply Last reply 27 Oct 2021, 12:02
    0
    • A Augustas
      27 Oct 2021, 11:31

      Hello,

      I'm trying to call a shell file from the .pro file using qmake.

      According to the documentation (https://doc.qt.io/qt-5/qmake-advanced-usage.html#adding-custom-targets), adding my target to QMAKE_EXTRA_TARGETS should work, however, even if I call "@echo test" command on a fresh project, it doesn't seem to get executed.

      What seems to work on windows, is adding my target not only to QMAKE_EXTRA_TARGETS , but also to PRE_TARGETDEPS or POST_TARGETDEPS.

      However, if I add my target to PRE_TARGETDEPS or POST_TARGETDEPS on Mac, I get "No rule to make target" error.

      What would be the appropriate way of calling a shell file from .pro file, since the one provided in the documentation doesn't seem to work?
      I'm using MacOS Big Sur on a Mac Mini M1.

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 27 Oct 2021, 12:02 last edited by
      #2

      @Augustas
      when do you want to call your command?

      I successfully used the following (executed on every successful build):

      QMAKE_POST_LINK += my_command $$shell_quote(arg1)
      

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      4
      • A Offline
        A Offline
        Augustas
        wrote on 27 Oct 2021, 12:59 last edited by
        #3

        Hi @raven-worx, thank you for the suggestion!

        I'd like to call the script at the start of the build, or atleast before the app launches.

        I've tried out your suggestion, and yes, it seems to work, as long as I pass the command directly (in this case, Script.sh is in the project folder):

        QMAKE_POST_LINK += $$_PRO_FILE_PWD_/Script.sh
        

        But if I try to add the command to a define and then call it using your suggestion:

        myCommand.commands = $$_PRO_FILE_PWD_/Script.sh
        QMAKE_POST_LINK += myCommand
        

        and build with this code, I get this error:

        make: myCommand: No such file or directory
        make: *** [TestProject.app/Contents/MacOS/TestProject] Error 1
        15:57:30: The process "/usr/bin/make" exited with code 2.
        Error while building/deploying project TestProject (kit: 5.14.2)
        When executing step "Make"
        

        Is anything wrong with my code, or am I using the defines incorrectly?

        R 1 Reply Last reply 27 Oct 2021, 13:20
        0
        • A Augustas
          27 Oct 2021, 12:59

          Hi @raven-worx, thank you for the suggestion!

          I'd like to call the script at the start of the build, or atleast before the app launches.

          I've tried out your suggestion, and yes, it seems to work, as long as I pass the command directly (in this case, Script.sh is in the project folder):

          QMAKE_POST_LINK += $$_PRO_FILE_PWD_/Script.sh
          

          But if I try to add the command to a define and then call it using your suggestion:

          myCommand.commands = $$_PRO_FILE_PWD_/Script.sh
          QMAKE_POST_LINK += myCommand
          

          and build with this code, I get this error:

          make: myCommand: No such file or directory
          make: *** [TestProject.app/Contents/MacOS/TestProject] Error 1
          15:57:30: The process "/usr/bin/make" exited with code 2.
          Error while building/deploying project TestProject (kit: 5.14.2)
          When executing step "Make"
          

          Is anything wrong with my code, or am I using the defines incorrectly?

          R Offline
          R Offline
          raven-worx
          Moderators
          wrote on 27 Oct 2021, 13:20 last edited by
          #4

          @Augustas
          QMAKE_POST_LINK simple executes the specified command after linking. and thus is executed only if linking happens due to code changes.

          You might want to define custom targets: https://doc.qt.io/qt-5/qmake-advanced-usage.html#adding-custom-targets
          Then try adding it to PRE_TARGETDEPS variable or executing it in QtCreator by adding the make call to the build sequence (in the project settings tab)

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          3
          • A Offline
            A Offline
            Augustas
            wrote on 28 Oct 2021, 05:56 last edited by Augustas
            #5

            @raven-worx,
            The suggestion you've mentioned is the one I was having trouble with, as mentioned before. However it is the correct one.

            Turns out, my issue was that on windows, you can use '/' or '\' in your paths (for ex. customTarget.target value), while on Mac, only '/' works :)

            Anyway, thank you for the help!

            R 1 Reply Last reply 28 Oct 2021, 12:45
            0
            • A Augustas
              28 Oct 2021, 05:56

              @raven-worx,
              The suggestion you've mentioned is the one I was having trouble with, as mentioned before. However it is the correct one.

              Turns out, my issue was that on windows, you can use '/' or '\' in your paths (for ex. customTarget.target value), while on Mac, only '/' works :)

              Anyway, thank you for the help!

              R Offline
              R Offline
              raven-worx
              Moderators
              wrote on 28 Oct 2021, 12:45 last edited by
              #6

              @Augustas
              https://doc.qt.io/qt-5/qmake-function-reference.html#shell-path-path

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              1

              4/6

              27 Oct 2021, 13:20

              • Login

              • Login or register to search.
              4 out of 6
              • First post
                4/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved