0

When I build a CMake project, the dependency scanning is slow. Investigating with htop for my large project pointed me to the command

/usr/bin/cmake -E cmake_depends Makefiles [...]

which is running on a single thread. Can this be speed up? Maybe with parallelism / multi-threading?

"Solution"

I use ninja from now on, which is much faster in detecting deps and collecting needed data for compillation.

Thank you for all the answers!

Migsi
  • 107
  • 2
  • 10
  • Can you please give more background information? E.g. what OS, which CMake version etc. How long does it take at the moment and what is your goal? I would look into e.g. recompiling CMake and see where you get (see also [here](http://stackoverflow.com/questions/37327526)). Because just making something multi-threaded that was not written for multi-threading is not an easy task for the compiler mainly depending on how the data is organized (see auto-vectorization e.g. [here](https://msdn.microsoft.com/en-us/library/hh872235.aspx)). – Florian Oct 25 '16 at 07:51
  • I've added the info on the OS and CMake version to the question. It's taking around 15 seconds to look for the dependencies. The compilation and linking process itself is already very fast (and might be multithreaded as well). – Migsi Oct 25 '16 at 07:56
  • 2
    I struggle to see the point: CMake configuration in theory is a rare event. Furthermore, you can save in cache variable the result of your dependencies scan, and avoid scanning at further CMake rerun. Another point against multithreading: scanning for dependencies has its bottle neck in disk access, which in general cannot be parallelized. Use a solid state disk if you don't already. – Antonio Oct 25 '16 at 08:15
  • 1
    Reading your question a second time: Does your problem occur when you run `cmake` or when you start building your project? In the second case, try using Ninja instead of Make. Ninja is more then 10 times faster then make to track dependencies and to figure out what must be build, cf. http://jpospisil.com/2014/03/16/replacing-make-with-ninja.html – usr1234567 Oct 25 '16 at 09:12
  • I just figured out ninja is way better (faster) to use with this project, thank you for the information! – Migsi Oct 25 '16 at 09:54

1 Answers1

3

Strictly speaking, this is not a CMake question, but a question of how to use your build tools.

Use a better performing build tool!

DO USE PCH for projects
DO include commonly used system, runtime and third party headers in PCH
DO include rarely changing project specific headers in PCH
DO NOT include headers that change frequently
DO audit PCH regularly to keep it up to date with product churn
DO USE /MP
DO Remove /Gm in favor of /MP
DO resolve conflict with #import and use /MP
DO USE linker switch /incremental
DO USE linker switch /debug:fastlink
DO consider using a third party build accelerator

  • Consider faster hardware
usr1234567
  • 21,601
  • 16
  • 108
  • 128