I am working on a c++ codebase using CMake with 500k+ lines of code. One problem I realize is that the (incremental) build speed is really slow.
Partly because the dependencies graph is not fine grained enough. E.g. many targets from target_link_libraries
have unnecessary dependencies, e.g. linking(dependent on) objects(libraries) for a small part of the libraries but also containing many other unnecessary functions/classes to the target
. So when a small change is made to to those dependent files, a lot of targets not needing the change get compiled again.
I thought about refactoring all the CMakeLists.txt
such that each add_library
is used for one file only and target_link_libraries
only link necessary libraries. This way of refactoring is too time-consuming, not automatic enough and error-prone.
Can Bazel, Scons or other build system solve this problem?
related question: How to speed up Compile Time of my CMake enabled C++ Project?