[cmake-developers] Fwd: Ninja order-only dependency makes inefficient ninja DAG

Kristofer Tingdahl kristofer.tingdahl at dgbes.com
Tue Jun 24 07:11:27 EDT 2014


Hi,

CMake adds order-only dependencies in build.ninja between libraries and
subsequent object-files, and I cannot see why this is needed. Consider the
following CMakeLists.txt:

project( program )
add_library( A SHARED a.cc )
add_library( B SHARED b.cc )
target_link_libraries( B A )
add_executable( prog program.cc )
target_link_libraries( prog B )

There are a couple of targets generated:
a.cc.o, b.cc.o, libA.so, libB.so, prog.cc.o and prog.

The ninja-file will make these targets be built in the following steps:

   1. a.cc.o
   2. libA.so
   3. b.cc.o
   4. libB.so
   5. prog.cc.o
   6. prog


My point is that there is no reason to wait building b.cc.o and prog.cc.o;
they can be built at the same time as a.cc.o .

Hence I wonder why libA.so is added as a order-only dependency to b.cc.o
when CMake processes this? This is done in
Source/cmNinjaTargetGenerator.cxx:509 (in v2.8.12), line 548 in v3. The
call is:

// Ensure that the target dependencies are built before any source file in
// the target, using order-only dependencies.
  cmNinjaDeps orderOnlyDeps;
  this->GetLocalGenerator()->AppendTargetDepends(this->Target,
orderOnlyDeps);

I'm trying to trim a few minutes on our continuous build, and my build
system goes into singlethreadedness while libA is linked, while my 64 cores
could be compiling object-files for libB and other targets. Simply
commenting out the statement above solves it for me.

 At least in my project, I cannot see a reason for this rule. Perhaps a
variable could be introduced to steer the behaviour if it is needed
elsewhere. Any thought is welcome, and I'm willing to submit a patch if a
consensus could be reached on what to do.

Cheers,

Kristofer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20140624/2f95517f/attachment.html>


More information about the cmake-developers mailing list