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

Bill Hoffman bill.hoffman at kitware.com
Thu Oct 7 12:05:37 EDT 2010


On 10/7/2010 11:52 AM, kent williams wrote:
> 1. Is that $(MAKE) or is it ${MAKE} ?  One thing missing from the
> CMake documentation -- unless I'm mistaken there's not much
> explanation of CMake syntax in the documentation.
>
No, this is make syntax not CMake syntax.
> 2. I think it's probably not what one intends to have 'make -j4' (for
> example) used every time make is invoked.  If you configure a program
> that includes several ExternalProjects, then it would spawn 4
> concurrent builds of those ExternalProjects, and then each of those
> builds would spawn 4 make steps at once, for 16 concurrent processes.
>

What you want is for make to treat the external projects just like any 
other library or executable in a build.

so, if you run this at the top of the build:

make -j4

It should run at most 4 concurrent things at once for the whole thing. 
By using $(MAKE) in the makefiles make will do that.

That said, CMake will do this by default for make based builds and 
external projects now.

 From ExternalProject.cmake:

   get_target_property(cmake_generator ${name} _EP_CMAKE_GENERATOR)
       if("${CMAKE_GENERATOR}" MATCHES "Make" AND
           ("${cmake_generator}" STREQUAL "${CMAKE_GENERATOR}" OR
           NOT cmake_generator))
         # The project uses the same Makefile generator.  Use recursive 
make.
         set(cmd "$(MAKE)")
         if(step STREQUAL "INSTALL")
           set(args install)
         endif()


-Bill


More information about the CMake mailing list