Question

I organized my projects contains apps and tests pro files and libs pri files as below:

root
├── apps
│   ├── mainapp
│   │   ├── mainapp.pro
│   │   └── other mainapp files...
│   ├── app2
│   │   ├── app2.pro
│   │   └── other app2 files...
│   └── allApps.pro
├── libs
│   ├── lib1
│   │   ├── lib1.pri
│   │   └── other lib1 files...
│   └── lib2
│       ├── lib2.pri
│       └── other lib2 files...
├── tests
│   ├── test1
│   │   ├── test1.pro
│   │   └── other test1 files...
│   ├── test2
│   │   ├── test2.pro
│   │   └── other test2 files...
│   └── allTests.pro
└── all.pro

all.pro is a subdir project containing allApps.pro and allTests.pro containing themself all apps and tests pro files.

Library pri files are library included by the apps and the tests project.

When build all.pro with qmake / make, my libraries are compiled for each app and test which is very time consuming...

Is there a way that the files included in my libs are compiled only once?

Thank you for your help!

Edit

I precise that I use pri files for lib because it's the only way I found to make my library code debuggable, and where change are taken in account when rebuilding the project.

Was it helpful?

Solution

Your tree does not agree with your narrative: there are no .pri files anywhere in your tree. IOW: You've answered your own question: your libraries should be .pro files and produce a static library, not .pri files :)

Static libraries are fully debuggable. You can compile Qt as a static library and debug into it, for example.

I have another problem: when I change something in the lib, the app doesn't automatically link it

You need to make the application dependent on the library. Add the library to the PRE_TARGETDEPS in the application's .pro file. You also need to set up the proper dependency in the top-level subdirs project, to ensure that the libraries are always built prior to the projects that use them. Add, for example

apps/mainapp.depends += libs/lib1. 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top