I have a project with 5-6 libraries and one executable. The executable depends on the libraries, and some libraries depend on other libraries. How can I specify a build order so the dependencies are built before they are needed?
Although this question has been answered and accepted a long time ago, I feel the need to add another answer; I honestly think that there is a better answer.
I consider CONFIG += ordered
harmful and a bad habit. It is probably something that was a bit prematurely introduced by the qmake developers. And there are strong opponents to its use. The drawbacks are these:
- it prevents Qt developers from implementing meaningful features
Therefore, I suggest to change your project file as follows:
TEMPLATE = subdirs
SUBDIRS += Utility GraphicModule PackingLib Core GameProto
GameProto.depends = Core
Core.depends = PackingLib
PackingLib.depends = GraphicModule
GraphicModule.depends = Utility
This way the dependencies are clearly defined. You can also think of other, more complicated dependency hierarchies which are possible this way and absolutely impossible with the build order.
Update: (June 21st, 2017)
Unfortunately, qmake
is not the best tool when it comes to larger projects with deep sub-project hierarchies. Problems seen with larger projects are these:
Run qmake
takes an extremely long time to executeqmake
is not able to correctly calculate sub-project dependencies which makes it necessary to compile sub-projects separatelyThere mainly two ways to address these issues:
qmake
run times and shorter compilation times. However, even this approach may fail at times. cmake
. Seriously. Cmake
is a mature product and the support from within Qt Creator is comparable to qmake
.Comment:
Because of the well known problems with qmake
, the Qt Company has already decided to introduce a new make tool QBS
. However, the use of this tool is not as simple as it may look on first impression. There is no easy transition from qmake
to QBS
, especially for more complex projects. The Javascript-like syntax of the QBS
language is not easy to grasp and documentation is scarce.
There are IMHO only two other tools available that are of the caliber to replace qmake
: