How to speed up Compile Time of my CMake enabled C++ Project?
<p>I came across several SO questions regarding specific aspects of improving the turn-around time of CMake enabled C++ projects lately (like <a href="https://stackoverflow.com/questions/37276312/at-what-level-should-i-distribute-my-build-process">"At what level should I distribute my build process?"</a> or <a href="https://stackoverflow.com/questions/35436945/cmake-rebuild-cache-for-just-a-subdirectory">"cmake rebuild_cache for <em>just</em> a subdirectory?"</a>), I was wondering if there is a more general guidance utilizing the specific possibilities CMake offers. If there is probably no cross-platform compile time optimization, I'm mainly interested in Visual Studio or GNU toochain based approaches.</p>

<p>And I'm already aware of and investing into the generally recommended areas to speed up C++ builds:</p>

<ol>
<li><p>Change/Optimize/fine-tune the toolchain</p></li>
<li><p>Optimize your code base/software architecture (e.g by reducing the dependencies and use well-defined sub-projects - unit tests)</p></li>
<li><p>Invest in a better hardware (SSD, CPU, memory)</p></li>
</ol>

<p>like recommended <a href="https://stackoverflow.com/questions/373142/what-techniques-can-be-used-to-speed-up-c-compilation-times">here</a>, <a href="https://stackoverflow.com/questions/3396958/how-to-speed-up-g-compile-time-when-using-a-lot-of-templates">here</a> or <a href="https://stackoverflow.com/questions/6321679/effective-c-35-minimize-compilation-dependencies-between-files-is-it-still">here</a>. So my focus in this question is on the first point.</p>

<p>Plus I know of the recommendations to be found in CMake's Wiki:</p>

<ul>
<li><a href="https://blog.kitware.com/cmake-building-with-all-your-cores/" rel="noreferrer">CMake: building with all your cores</a></li>
<li><a href="https://cmake.org/Wiki/CMake_Performance_Tips" rel="noreferrer">CMake Performance Tips</a> </li>
</ul>

<p>The former just handles the basics (parallel make), the later handles mostly how to speed-up parsing CMake files.</p>

<p>Just to make this a little more concrete, if I take my CMake example from <a href="https://stackoverflow.com/questions/35436945/cmake-rebuild-cache-for-just-a-subdirectory/35826669#35826669">here</a> with 100 libraries using MSYS/GNU I got the following <code>time</code> measurement results:</p>

<pre><code>$ cmake --version
cmake version 3.5.2
CMake suite maintained and supported by Kitware (kitware.com/cmake).

$ time -p cmake -G "MSYS Makefiles" ..
-- The CXX compiler identification is GNU 4.8.1
...
-- Configuring done
-- Generating done
-- Build files have been written to: [...]
real 27.03
user 0.01
sys 0.03        

$ time -p make -j8
...
[100%] Built target CMakeTest
real 113.11
user 8.82
sys 33.08
</code></pre>

<p>So I have a total of ~140 seconds and my goal - for this admittedly very simple example - would be to get this down to about 10-20% of what I get with the standard settings/tools.</p>