Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Force build to be dependent on changes in header files in QtCreator/QMake

    Tools
    4
    6
    10909
    Loading More Posts
    • 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
      dusktreader last edited by

      It seems that by default the build functionality of QtCreator is only dependent on changes in the source files. So, for example, if I change a file in the SOURCES variable, initiating a "run" or "build" request from QtCreator will rebuild all objects dependent on those source files. However, if I change a file in the HEADERS list and initiate a "build" or "run" request, no objects will be rebuilt.

      How do I make the current build of my application dependent on a header file so that if a header changes the dependent objects are rebuilt?

      I know how to do this with standard make (i.e. add dependency to a .h file). How can I specify this sort of thing in a QMake .pro file?

      “Machines take me by surprise with great frequency.” -- Alan Mathison Turing

      1 Reply Last reply Reply Quote 0
      • F
        Franzk last edited by

        Haven't tested, but maybe adding paths to DEPENDPATH could help. For example:

        @DEPENDPATH += . src include@

        "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply Reply Quote 0
        • ?
          Guest last edited by

          by default it will rebuild when you modify any header.. can you post your .pro file here

          1 Reply Last reply Reply Quote 0
          • K
            kalle last edited by

            QMake will only observe dependencies in files listed in .pro files, or files in DEPENDPATH and INCLUDEPATH.

            1 Reply Last reply Reply Quote 0
            • D
              dusktreader last edited by

              Here is my .pro file:

              @
              TARGET = outlierdetecttest
              TEMPLATE = app

              INCLUDEPATH +=
              ../../../tools
              ../..

              SOURCES +=
              main.cpp
              ../../../tools/tools.cpp

              HEADERS +=
              ../../../tools/tools.h
              ../../outlier.h
              @

              This project simply tests the functionality of a custom header. The header has templated source code, so there is no accompanying .cpp file. The layout of the projects is as follows

              ~/analysis/ # This is the main source folder for my large project
              |- outlier.h
              |- other source and header files
              ~/analysis/sandbox/outlierdetecttest/ # This is the folder where the project for testing the outlier detection header lies
              |- main.cpp
              |- outlierdetecttest.pro

              The tools.h files are only used for debugging, and really aren't necessary.--

              Now, suppose I have already built the project. I run it and decide to change something in the header. After I edit the header and hit the build button (or ctrl-b ), nothing happens. If, however, I edit the main.cpp source file and request a rebuild, then the executable is rebuilt.

              I do not want to make the main source folder ( ~/analysis) part of the dependency path. I only want to make the outlierdetecttest build depend on changes in the header file. How can I do this?

              “Machines take me by surprise with great frequency.” -- Alan Mathison Turing

              1 Reply Last reply Reply Quote 0
              • J
                julrich last edited by

                I just encountered this issue with Qt 4.8 and I guess there is a bug in QMake.
                In my project, the .pro file contained the following:

                @
                DEPENDPATH += .
                INCLUDEPATH += .
                ./include
                @

                (of course, the header files are added to HEADERS)

                This lead to a makefile where the only dependency of the object file was the source file (e.g. "myfile.o: myfile.cpp"). However, the dependencies of the moc source files were fine.
                As soon as I change the .pro file like this:
                @
                DEPNENDPATH += .
                ./include
                INCLUDEPATH += .
                ./include
                @

                all dependencies are generated correctly. And now the dependencies even contain the ui generated header files which are not in the ./include directory!
                So I guess that the dependency generation does not take place when the DEPENDPATH only contains "." or is completely empty.

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post