[Qt-interest] qmake and DEPENDPATH subtlety
Michael Ost
most at museresearch.com
Wed Oct 5 20:06:18 CEST 2011
Hi,
I've been stymied for a long time as to why some #includes are scanned
in qmake and some are not. It's led me to paranoid and lengthy "rebuild
project" sessions which have undermined my confidence in qmake / Qt Creator.
Then, thankfully!, I came across DEPENDPATH and that has helped immensely.
But there is a subtle detail that I didn't see documented that others
might find helpful: if you use directories in your #include statements,
DEPENDPATH should be the prefix to insert (like INCLUDEPATH works)
instead of the directory itself.
This makes sense in retrospect, but it wasn't clear at first.
So, for others challenged like me, here are two project files --- the
first fails to add test2.h as a dependency of test.cpp because
DEPENDPATH gives the directory, not the prefix. And the second works
because DEPENDPATH is changed to the prefix.
Ex 1 FAILS -
a/BAD.pro:
TARGET = test
TEMPLATE = lib
INCLUDEPATH += ../b
# Fails, becuase this is test2.h's directory not the prefix
DEPENDPATH += ../b/c
SOURCES += ../b/test.cpp
HEADERS += ../b/c/test.h ../b/c/test2.h
a/GOOD.pro:
TARGET = test
TEMPLATE = lib
INCLUDEPATH += ../b
# Works, becuase this is the prefix
DEPENDPATH += ../b
SOURCES += ../b/test.cpp
HEADERS += ../b/c/test.h ../b/c/test2.h
b/test.cpp:
#include "c/test.h"
b/c/test.h:
#include "c/test2.h"
b/c/test2.h:
(empty)
Note that for both projects, "test.h" is found, presumably because it is
in the CPP file. This seems to only impact headers that include headers.
Anyway, I hope this saves some other Qt programmer some headaches!
- Michael Ost
More information about the Qt-interest-old
mailing list