When working with large C++ projects in Visual Studio built times can become a problem. I'm working on a project with 140000+ lines of code split into 23 Projects (1 Main App; 3 libs; 19 DLL's). Depending on the CPU speed built times could exceed 10 Minutes. May not sound much but if you have to change the framework often rebuilds are required several times a day and the total compilation time per day can quickly become a problem.
The usual time safers like precompiled headers, excessive use of forward declaration and building with support for multiple cores (/MP) were already in place. Time to try a solution I wouldn't touch under normal circumstances: Including all cpp files into a single compilation unit. (Kinda like precompiled headers just for the cpp files...)
Here is how it works:
- Create a few cpp files that include all your projects cpp files. For instance one to include all your gui code, one for the data handling, one for all utility files. Add those files to your project.
- Set the original cpp files to "exclude from build" in the project settings; Only your new include files shall be set to compile.
Instead of compiling a large number of small files you end up compiling a small number of large files. This is significantly faster.
Pros:
- You can continue working with your solution normally, all your files are still listed, they are just marked as "excluded from build"
- Built times will decrease dramatically
Cons:
- Name collisions are possible when using global variables.
- Partial build times will go up. This is managable if you don't put all your cpp files into a single include file. (use two or three)
This was'nt my idea so the credit goes to Noel Llopis from the gamesfromwithin blog. The original article is here:
http://gamesfromwithin.com/physical-structure-and-c-part-2-build-times
Read it to learn more about the background. I found this approach very helpfull for my case. Thanks to the original author for his in depth investigations into this.