How to set build order in Qt subdir project
Ok. I found the solution.Just add ordered to CONFIG and recite subdirs in correct order
CONFIG += ordered
SUBDIRS += Utility GraphicModule PackingLib Core GameProto
For me this work fine
Update: (Feb 2021)
- Oct 2018 - Qt decided to deprecate Qbs and redirect its resources to increase support for CMake.
- Oct 2020 - CMake is the build system for Qt 6.
Please consume the advice in the (old) answer below in light of this new information.
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 does not define the dependencies, it just names a build order
- it hammers multicore build times
- 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.
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:
- it is not possible to define dependencies to sub-projects higher up in the hierarchy
Run qmake
takes an extremely long time to execute- long compile time because the dependencies are not handled properly and too many unnecessary compile steps executed
- sometimes
qmake
is not able to correctly calculate sub-project dependencies which makes it necessary to compile sub-projects separately
There mainly two ways to address these issues:
- Rewrite your project to a flat hierarchy. All executables, static and dynamic libraries should be in the topmost level. Use two or more levels only for sub-projects where you absolutely cannot avoid it. (e.g. a dynamic library that comprises of static libraries) This will result in shorter
qmake
run times and shorter compilation times. However, even this approach may fail at times. - Change to a different make tool, like
cmake
. Seriously.Cmake
is a mature product and the support from within Qt Creator is comparable toqmake
.
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
:
CMake
, the well known build tool.meson
, an open source build system meant to be both extremely fast, and, even more importantly, as user friendly as possible.