views:

1034

answers:

2

Hi, since starting at a new company I've noticed that they use unity cpp files for the majority of our solution, and I was wondering if anyone is able to give me a definitive reason as to why and how these speed up the build process?, as I would've thought that editing one cpp file in the unity files will force recompilation of all of them.

thanks

+10  A: 

Very similar question and good answers here: http://stackoverflow.com/questions/543697/include-all-cpp-files-into-a-single-compilation-unit

The summary seems to be that less I/O overhead is the major benefit.

See also The Magic Of Unity Builds as linked in the above question as well.

akent
excellent answer, thanks a lot for your help, after reading those links im still none the wiser if editing files within the unit cpp force a complete recompilation of the entire source, any ideas about this?
Stowelly
Yes, it would. Whether that's a bad thing or not depends on how often you have to do a full rebuild already.
Head Geek
If one file changes, any decent build system would notice a changed dependency and recompile the lot. You may be able to mitigate some of that time with a compiler cache like the excellent ccache -- see http://ccache.samba.org/
akent
While day to day dev is definintely the big winner, Unity Builds make for rapid release builds compared to the old style builds. For any full rebuild, you can't beat a unity build. If you have a large codebase, you can even break up in the single unity file into a few smaller ones. Couple it with something like Incredibuild and you'll hardly have to wait for a build ever again!
OJ
+1  A: 

An introduction on "Unity Builds" along with benefits, disadvantages and a complete CMake integration can be found at cheind.wordpress.com.

hth, Christoph

Christoph Heindl