[CMake] How would I use parallel make on ExternalProjects?

Bill Hoffman bill.hoffman at kitware.com
Fri Oct 8 12:44:09 EDT 2010


On 10/8/2010 11:57 AM, kent williams wrote:
> I think what I'm doing isn't clear to you.
>
> I have a CMakeLists.txt that is essentially 'sourceless' -- it defines
> a bunch of CMake variables, and then builds a bunch of prerequisites
> and applications added with ExternalProject_add. It doesn't have any
> add_subdirectory,add_executable, add_library etc of its own.
>
> So at build time, the process tree is
>
> make # the make of the top level
>           make # build external project 1
>               .
>               .
>           make # build external project n
>
> If I use make -j4, for example, it would build 4 external projects in
> parallel with make -j1.  If any of those projects is on the critical
> path, and takes significantly longer to build than any other projects,
> the build process bottlenecks doing the sequential build of that one
> project.
>
> My method -- changing the build command for the external projects to
> use -j4 for example, will instead do a sequential series of parallel
> sub-makes, instead of a parallel series of sequential submakes.
>
> I've tried it both ways and this is how it works.
>

We have fixed things recently to address this.  The way it should be 
working:

make  # top level
      make # build external project 1
      .
      .
      make # build external project n

make -j4 at the top:

The make jobserver should take care of the rest and make sure that 4 
different things are always building at the same time.   This could be 
.o files from more than one external project if that is how it works out.

This is possible because $(MAKE) is used so when the external projects 
are run gmake will pass the jobserver information down to the next 
sub-make.  The jobserver will keep track of making sure no more than 4 
things are running at the same time.

-Bill


More information about the CMake mailing list