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

kent williams nkwmailinglists at gmail.com
Wed Oct 6 17:43:29 EDT 2010


I'd like to use parallel make to build libraries like ITK and VTK
which are rather time-consuming.

This simple-minded (and non portable) method works: In the
ExternalProject_Add macro, add

BUILD_COMMAND ${CMAKE_MAKE_PROGRAM} -j4

But that only works if CMAKE_MAKE_PROGRAM understands the '-j4' flag.

I can test the generator, i.e.

if("${CMAKE_GENERATOR}" STREQUAL "Unix Makefiles")
set(BUILD_COMMAND_STRING "${CMAKE_PROGRAM} -j4")
endif

and later use in the ExternalProjectAdd

BUILD_COMMAND ${BUILD_COMMAND_STRING}

But if the generator is not "Unix Makefiles" this will expand to the
empty string, with the result of suppressing builds from ever
happening.

The only solution I can imagine is to have 2 ExternalProject_Add
macros inside a conditional

if("${CMAKE_GENERATOR}" STREQUAL "Unix Makefiles")

  ExternalProjectAdd(
   BUILD_COMMAND ${CMAKE_MAKE_PROGRAM} -j4
   )
else()
  ExternalProjectAdd(
    # let the build command be the default for this generator
  )
endif()

Anyone have a better idea?


More information about the CMake mailing list