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

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



  • 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?



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

    @DEPENDPATH += . src include@



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



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



  • 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?



  • 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.


Log in to reply