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. Force build to be dependent on changes in header files in QtCreator/QMake
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Qt Creator and other tools
6 Posts 4 Posters 11.5k Views 1 Watching
  • 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
    dusktreader
    wrote on last edited by
    #1

    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
    0
    • F Offline
      F Offline
      Franzk
      wrote on last edited by
      #2

      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
      0
      • ? This user is from outside of this forum
        ? This user is from outside of this forum
        Guest
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kalle
          wrote on last edited by
          #4

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

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

            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
            0
            • J Offline
              J Offline
              julrich
              wrote on last edited by
              #6

              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
              0

              • Login

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