I have some trouble figuring out how qmake handles the include dependencies of a static library that depends on another static library.
My folder structure is as follow :
--- src/
lib1/
src/ (.pro,*.h,*.cpp)
lib2/
src/ (.pro,*.h,*.cpp)
app/
src/ (.pro,*.h,*.cpp)
--- build/
lib1/
lib1.a
lib2/
lib2.a
app/
app
lib2 uses lib1, and app uses lib2. The .pro files are :
lib1.pro
TARGET = lib1
TEMPLATE = lib
CONFIG += staticlib
CONFIG += create_prl link_prl
SOURCES += ...
HEADERS += ...
lib2.pro
TARGET = lib2
TEMPLATE = lib
CONFIG += staticlib
CONFIG += create_prl link_prl
INCLUDEPATH += $${_PRO_FILE_PWD_}/../../lib1/src
DEPENDPATH += $${_PRO_FILE_PWD_}/../../lib1/src
PRE_TARGETDEPS += $${OUT_PWD}/../lib1/liblib1.a
LIBS += -L$${OUT_PWD}/../lib1 -llib1
SOURCES += ...
HEADERS += ...
app.pro
TARGET = app
TEMPLATE = app
CONFIG += link_prl
# Include to lib1 headers ... How to avoid this ?
INCLUDEPATH += $${_PRO_FILE_PWD_}/../../lib1/src
DEPENDPATH += $${_PRO_FILE_PWD_}/../../lib1/src
# lib2
INCLUDEPATH += $${_PRO_FILE_PWD_}/../../lib2/src
DEPENDPATH +=$${_PRO_FILE_PWD_}/../../lib2/src
PRE_TARGETDEPS += $${OUT_PWD}/../lib2/liblib2.a
LIBS += -L$${OUT_PWD}/../lib2 -llib2
SOURCES += ...
HEADERS += ...
Is there a way to avoid the INCLUDEPATH
to the lib1 headers in the app.pro ? I thought that the DEPENDPATH
in lib2.pro would take care of that, but apparently not.
Edit : Clarifying question :
The problem comes from lib2.h that contains : #include "lib1.h"
. If I don't include the lib1 headers in app.pro, then I get a compilation error stating that lib1.h is not found. Is this normal ? Not sure if this makes sense, but since app only depends explicitly on lib2 shouldn't it be able to compile only with including lib2 headers ?