[CMake] How to build projects with make -j2 and ADD_SUBDIRECTORY?

Michael Wild themiwi at gmail.com
Mon Feb 16 09:51:20 EST 2009


On 16. Feb, 2009, at 14:42, Micha Renner wrote:

> Hi Michael
>>
>> This works for me (Mac OS X 10.5.6, GNU Make 3.81). What version of
>> Make are you using?
> The same as you.
>
>> Reasonably recent versions of GNU Make should be
>> able to do exactly that, but AFAIK, nmake and MSYS Make have serious
>> trouble getting parallel builds right (or do not have the feature at
>> all).
> You are right. Especially , nmake might be a death end.
>>
>> Whether parallel builds are available is not so much a thing that
>> CMake handles, but the native build system (in your case some variant
>> of Make).
>>
> I'm pretty sure that this a is CMake-problem. E.g the autotools can  
> do a
> parallel build of tiff.
>
> The problem with CMake arises only if the library-build is long and  
> the
> parallel depending build short. In this case it took 50s to build the
> library and 8s to build the depending program.

50s is not sooo bad, here I have targets which take dozens of minutes...

>
> If the subdirectories are independent, then I have no difficulties to
> make parallel builds.


Aah yes, I noticed similar effects. Strange thing is that the  
Makefiles generated by CMake support building a single target in  
parallel. But once the "scheduler" decided to do the easier thing, and  
build two different targets in parallel, and one finishes much earlier  
than the other, it won't ever "fork" the build process of the other  
target, but instead start to build another target non-parallel. This  
is not so bad if you have many targets of about the same size, as I do  
(in the order of 100), but if you have only a very few targets with  
one of them being much more expensive than all the others, it breaks  
down.

>
>
> The other point is, there is no way to tell CMake that Sub1 depends on
> Sub2 and Sub2 depends on Sub3.

You can't define dependencies of directories, but of targets. That  
should do the trick, right? And actually makes more sense...

>
>
> So from the silence of the maintainers I conclude that I'm right,  
> alas.
> (Of course not sure, so I asked.)

I'd wait over the night, most of them are across the Atlantic ;-)

>
>
> Nevertheless, thanks for responding.
>
> Michael
>

Michael


More information about the CMake mailing list