[cmake-developers] [CMake 0015555]: Ninja: C compilation targets unnecessarily depend on libraries

Mantis Bug Tracker mantis at public.kitware.com
Tue May 5 17:49:36 EDT 2015


The following issue has been SUBMITTED. 
====================================================================== 
http://www.cmake.org/Bug/view.php?id=15555 
====================================================================== 
Reported By:                Todd Lipcon
Assigned To:                
====================================================================== 
Project:                    CMake
Issue ID:                   15555
Category:                   CMake
Reproducibility:            always
Severity:                   minor
Priority:                   normal
Status:                     new
====================================================================== 
Date Submitted:             2015-05-05 17:49 EDT
Last Modified:              2015-05-05 17:49 EDT
====================================================================== 
Summary:                    Ninja: C compilation targets unnecessarily depend on
libraries
Description: 
When the Ninja generator generates targets for .cc files, it adds dependencies
on any libraries that their target depend on. This means that in a parallel
build, ninja won't start building any .cc files from one library until all
depended-upon libraries have been built -- an unnecessary restriction. The only
requirement should be that a target cannot be _linked_ until its required
libraries are built.

This severely limits build parallelism in large projects. I manually
post-processed a build.ninja file from a medium-size C++ project to remove these
dependencies, and a parallel build using icecc on a small cluster was reduced
from 1m30s to 1m0s. Looking at a Gantt chart of the build, I could see that all
of the cluster cores were kept occupied much better after the fix, especially at
the start of the build.

Steps to Reproduce: 
todd at todd-ThinkPad-T540p:/tmp/test$ cat foo.cc 
extern int bar();
int main() {
  return bar();
}
todd at todd-ThinkPad-T540p:/tmp/test$ cat bar.cc 
int bar() {
  return 1;
}
todd at todd-ThinkPad-T540p:/tmp/test$ cat CMakeLists.txt 
add_library(bar bar.cc)
add_executable(foo foo.cc)
target_link_libraries(foo bar)
todd at todd-ThinkPad-T540p:/tmp/test$ cmake -GNinja .
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/test
todd at todd-ThinkPad-T540p:/tmp/test$ grep 'build.*foo.cc.o:' build.ninja 
build CMakeFiles/foo.dir/foo.cc.o: CXX_COMPILER foo.cc || libbar.a


I attached the above directory to this bug report.
====================================================================== 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2015-05-05 17:49 Todd Lipcon    New Issue                                    
2015-05-05 17:49 Todd Lipcon    File Added: test.tar.gz                      
======================================================================



More information about the cmake-developers mailing list