Suppose I have such project structure:
Root
+ ProjA
+ SubA.1
+ SubA.2
+ ProjB
+ SubB.1
+ SubB.2
And the dependencies I setup is:
SubA.2 depends on SubA.1
ProjA depends on SubA.1 and SubA.2
ProjB depends on ProjA
I want to make the build order looks like this when start with make -jX
:
1. SubA.1
2. SubA.2
3. SubB.1 SubB.2
But the fact is:
1. SubA.1 SubB.1 SubB.2
2. SubA.2
It seems the ProjB => ProjA
can't be used to make all the SubB
s build after SubA
s.
How can I make all the SubB
s build after all the SubA
s finishes?
In CMake dependencies can be set only on per-target basis.
You should decide, whether
ProjB
depends on internals ofProjA
or not. By "internals" I mean names of targets, values of CMake variables and so on.ProjB
actually require internals ofProjA
, you may carefully determine targets ofProjA
, which are required for one or another target ofProjB
, and set only needed dependencies. Such a way building ofProjA
may interleave withProjB
withmake -j
, but building will be correct.E.g., if
SubB.1
is executable, which requiresSubA.1
library for link with, thenautomatically sets needed dependencies.
If
SubB.2
is generated using executableSubA.2
, then usagewill automatically set needed dependencies.
ProjB
doesn't aware about internal ofProjA
and it is only known thatProjB
can be built only whenProjA
is already built, then you may useExternalProject_Add
for build both projects and set dependencies between created targets:CMakeLists.txt: