Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. can i specify a pre_build step in my .pro file?
Forum Update on Monday, May 27th 2025

can i specify a pre_build step in my .pro file?

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
19 Posts 6 Posters 6.0k 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.
  • D Offline
    D Offline
    davecotter
    wrote on last edited by
    #1

    i know i can specify a QMAKE_POST_LINK in my pro file, but is there a QMAKE_PRE_BUILD or equivalent? i saw a method that uses target dependencies to achieve this, but that feels very hacky.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      davecotter
      wrote on last edited by
      #17

      i'm not looking for a hack, i'm looking for official support.
      i'm guessing at this point the answer is "no"

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        What would you need to do in that ore-build step ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • D Offline
          D Offline
          davecotter
          wrote on last edited by
          #3

          the question isn't about what i want to do with it, the question is "is there a way?"

          but if you are just curious, there are several valid reasons to want this:

          • generating a .cpp or .h file before the build starts
          • modifying / updating a version file to be read in during build
          • pre-cleaning previous build cruft
          • deleting the exe to enforce re-linking (which will enforce post-link-step(s)) if some file NOT in the project has changed
          • other, very valid reasons which i don't remember, as part of a very complex, multi-target build system
          1 Reply Last reply
          0
          • K Offline
            K Offline
            kenchan
            wrote on last edited by
            #4

            you can add a custom build step and move it to before all the other steps.
            Does not that not serve your purpose?

            1 Reply Last reply
            0
            • D Offline
              D Offline
              davecotter
              wrote on last edited by davecotter
              #5

              it does not because that's not automatic when someone ELSE opens the pro file
              plus if i have six targets and two bit depths, that's 12 targets i have to add that step to?
              it's begging for automation, which the pro file is MADE for

              1 Reply Last reply
              0
              • K Offline
                K Offline
                kenchan
                wrote on last edited by
                #6

                sorry, i don't follow your meaning?

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  davecotter
                  wrote on last edited by davecotter
                  #7

                  if another developer opens the .pro file, (ie: must generate their own .user file), then the knowledge to create the pre_build step must be made by the voice-to-ear network, rather than it being automatic. multiply by hundreds of developers and it's obviously an error prone method

                  1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    kenchan
                    wrote on last edited by
                    #8

                    ah, i see.

                    1 Reply Last reply
                    0
                    • K Offline
                      K Offline
                      kenchan
                      wrote on last edited by kenchan
                      #9

                      so, which is your favourite tool to work with that can do this kind of thing for you then?

                      1 Reply Last reply
                      0
                      • D Offline
                        D Offline
                        davecotter
                        wrote on last edited by
                        #10

                        i don't understand what you're getting at by asking this question?

                        to be clear, i'm asking "can this be done?"

                        the answer is "yes" or "no", right?

                        1 Reply Last reply
                        0
                        • K Offline
                          K Offline
                          kenchan
                          wrote on last edited by
                          #11

                          i am just asking you what tool you prefer to use or have used that can do what you want. I am just thinking that you are finding the Qt Creator pro file combination laking in that respect Hence your question to the forum.

                          This is after all an open forum and any one can ask any kind of question they like. I thought I might learn from your experience of better tools for doing the kind of things you are describing.

                          Excuse me for wasting your time!!

                          1 Reply Last reply
                          0
                          • D Offline
                            D Offline
                            davecotter
                            wrote on last edited by
                            #12

                            i had been using xcode, which already does the particular thing that i need (always does post-build steps regardless of whether a re-link is necessary), and MSDEV (which did not, causing me to need to delete the exe, by hand, every time)

                            also i do not know that Qt Creator is lacking this feature, since no definitive answer has been given

                            i did not intend to ruffle your feathers.

                            1 Reply Last reply
                            0
                            • K Offline
                              K Offline
                              kenchan
                              wrote on last edited by
                              #13

                              Thank you for your explanation. I hope someone on the forum will be able to help you with you question.
                              good luck.

                              1 Reply Last reply
                              0
                              • mrjjM Offline
                                mrjjM Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on last edited by
                                #14

                                Hi
                                We use $$system to run scripts that does some tasks.

                                doc sample:
                                UNAME = $$system(uname -s)
                                contains( UNAME, [lL]inux ):message( This looks like Linux ($$UNAME) to me )

                                1 Reply Last reply
                                0
                                • D Offline
                                  D Offline
                                  davecotter
                                  wrote on last edited by
                                  #15

                                  but when does that get run? any time the .pro is parsed? mine gets parsed THREE times when i "run qmake", and does NOT get parsed before running

                                  1 Reply Last reply
                                  0
                                  • P Offline
                                    P Offline
                                    patrik08
                                    wrote on last edited by JKSH
                                    #16

                                    Have a look by
                                    [EDIT: Irrelevant link removed --JKSH]
                                    code ...
                                    before the big build Framework start... is a submodule dir that compile bevore all... only question from pro e pri file and comand....

                                    or CMakeFile.txt... can do all in build order...

                                    1 Reply Last reply
                                    -1
                                    • D Offline
                                      D Offline
                                      davecotter
                                      wrote on last edited by
                                      #17

                                      i'm not looking for a hack, i'm looking for official support.
                                      i'm guessing at this point the answer is "no"

                                      1 Reply Last reply
                                      0
                                      • aha_1980A Offline
                                        aha_1980A Offline
                                        aha_1980
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #18

                                        I have not tested myself, but see https://wiki.qt.io/Undocumented_QMake:

                                        "And finally an example on how to call a batch file called "PreBuildEvent.bat" each time you compile your code (tested in VisualStudio, based on qt-creator-enterprise-src-3.1.0\share\qtcreator\static.pro):"

                                        PRE_BUILD_FILE = ../Applications/PreBuildEvents.bat
                                        # must use a variable as input
                                        PHONY_DEPS = .
                                        PreBuildEvent.input = PHONY_DEPS
                                        # use non-existing file here to execute every time
                                        PreBuildEvent.output = phony.txt
                                        # the system call to the batch file
                                        PreBuildEvent.commands = call $$PRE_BUILD_FILE
                                        # some name that displays during execution
                                        PreBuildEvent.name = running Pre-Build steps...
                                        # "no_link" tells qmake we don’t need to add the output to the object files for linking, and "no_clean" means there is no clean step for them.
                                        # "target_predeps" tells qmake that the output of this needs to exist before we can do the rest of our compilation.
                                        PreBuildEvent.CONFIG += no_link no_clean target_predeps
                                        # Add the compiler to the list of 'extra compilers'.
                                        QMAKE_EXTRA_COMPILERS += PreBuildEvent
                                        

                                        Qt has to stay free or it will die.

                                        1 Reply Last reply
                                        2
                                        • aha_1980A Offline
                                          aha_1980A Offline
                                          aha_1980
                                          Lifetime Qt Champion
                                          wrote on last edited by
                                          #19

                                          (Of course that is no official solution, but most likely will work nicely)

                                          Qt has to stay free or it will die.

                                          1 Reply Last reply
                                          0

                                          • Login

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