Managing the process of compilation
As programmers and build engineers, we need to consider the other aspects of compilation as well – the time it takes to complete, and how easy it is to spot and fix mistakes made during the process of building a solution.
Reducing compilation time
In busy projects that require many dozens of recompilations per day (or per hour), it's paramount that compilation is as quick as possible. This not only affects how tight your code-compile-test loop is but also affects your concentration and flow of work. Luckily, C++ is already pretty good at managing compilation time, thanks to separate translation units. CMake will take care of recompiling only sources that were impacted by recent changes. However, if we need to improve things even more, there are a couple of techniques we can use – header precompilation and unity builds.
Precompilation of headers
Header files (.h
) are included in the translation unit by the preprocessor...