Question

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 :

  • The path in the .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.
  • On the project tree it looks like :

(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!

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top