[cmake-developers] ninja parallelism and LLVM cmake builds

Brad King brad.king at kitware.com
Tue Feb 11 08:26:00 EST 2014


On 02/10/2014 10:34 PM, Bill Hoffman wrote:
> Someone just posted this comment to one of my blogs: 
> (http://www.kitware.com/blog/home/post/434)
> 
>>  I don’t know if CMake or Ninja (or LLVM’s build rules) are at fault
>> here, but when I build Clang and LLVM under CMake and Ninja, parallelism
>> often drops to zero when a static library is being linked. I understand
>> that this is a place where a whole mess of parallelizable compilations
>> come together, but if there are further compilations required in the
>> build, shouldn’t it start working on some of those jobs during the link?
> 
> Any idea what might be going on?  I am guessing there are some 
> add_depends between targets that are causing this.

This is the same in all the generators, not just Ninja.  When one writes

 target_link_libraries(staticB staticA)

then it adds target ordering dependencies, just like add_dependencies,
to be sure everything in A is done before B starts to compile.  This is
in case custom commands in A generate headers used by B, or similar cases.
Also IDEs will do it because the build rules are broken down by target
anyway.

With CMake 2.8.12 one can work around this for static libraries by
specifying A as a usage requirement of B but not a build dependency:

 target_link_libraries(staticB INTERFACE staticA)

However, that will propagate all usage requirements of A to consumers
of B.  Depending on the usage requirements specified for A and B that
may be correct or not.

-Brad




More information about the cmake-developers mailing list