Reputation: 7886
Right now I am having a project which uses a templated, hence header-only, library, and builds two apps.
My folder organisation is as follows :
base/lib
base/app1
base/app2
What I do right now is that I have base/lib/lib.pri
which looks like :
HEADERS += ../lib/someHeader.h
And I include it in base/app1/app1.pro
and base/app2/app2.pro
.
However, in QtCreator, it looks somewhat ugly, for two reasons :
.pri
file depends on where it is included from. For instance, if I had another app that for some reason I wanted to be in folder anotherBase/app3/
it would not work.(looks like I have to put text after a list in order to have code pretty-print)
app1
-> app1.pro
-> headers
-> source files
-> lib/
-> lib.pri
-> headers
-> someHeader.h
app2
-> app2.pro
-> headers
-> source files
-> lib/
-> lib.pri
-> headers
-> someHeader.h
Hence I have two times the library files in the tree view.
Is there any way to optimize this ? I would like to have :
app1
-> app1.pro
-> headers
-> source files
app2
-> app2.pro
-> headers
-> source files
lib
-> lib.pri
-> headers
in the tree view, however if I assing a .pro
to lib
and make it its own project, then when I want to compile everything it will complain that there is nothing to compile for lib and make an error...
Thanks!
Upvotes: 4
Views: 2743
Reputation: 5279
Looks like I've found a workaround for the problem. It's kind of a hack, but it works well.
You can make a separate .pro file for your headers-only lib and specify TEMPLATE = subdirs
for it, but leave SUBDIRS
variable unassigned. List the headers of the library in this .pro-file. It will look something like this:
TEMPLATE = subdirs
HEADERS += h1.h \
h2.h
qmake will now understand that this .pro file should not produce any "target", but qt creator will show all headers you listed in the project tree so you can edit them as ordinary project' s headers. And the library will enter the project tree only once and at the appropriate tree level.
Upvotes: 2
Reputation: 98485
In your .pri
file, you should reference all paths to $$PWD
. This variable contains the full path of the currently parsed file - namely, your include file.
Note that PWD
has different meaning than _PRO_FILE_PWD_
, even if they occasionally return the same value.
Upvotes: 3