3

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

Eph
  • 81
  • 1
  • 7

1 Answers1

0

It sounds like you need a QMake SUBDIRS Project in the top level directory with the appropriate ".depends" statements. Check out the first answer to "How to Use QMake's SUBDIRS Template and QMake Project Dependencies.

Community
  • 1
  • 1
jwernerny
  • 6,978
  • 2
  • 31
  • 32
  • Thanks for your answer. The compilation is indeed fine after adding a subdir project at the top level directory. But, isn't it possible to separately compile lib1, then lib2 (with appropriate dependencies and header includes to lib1) and then app (with ONLY explicit header includes and dependencies to lib2) ? What I would like is actually use the libraries as independent libraries and call them from the app, without having the need of an additional .pro file or having to explicitely specify the lib1 header include in the app.pro (since app depends directly on lib2, but indirectly on lib1) – Eph Apr 03 '14 at 12:15
  • To complete my comment : suppose lib2 is used by several applications (e.g. app and app2). I guess I have then to create 2 subdir projects, one for app and another one for app2. But then, the library file lib2.a exists in 2 versions: one in the build directory of app, the other one in the build directory of app2. It's then not really clean, is it ? Wouldn't it be better to refer to the same lib2.a ? – Eph Apr 03 '14 at 12:24