9

In my (primarily C++) development, I have long adhered to using out-of-source builds. That is, my source usually sits in a /project/src directory and the builds live in a /project/build/bin/release, /project/build/bin/debug directories. I have done this because it keeps my source directories clean from intermediate files, I have one location for all of my binaries, packaging is easier, cleaning is easier, and version control is easier. (Did I miss anything?)

I am inheriting a (large) project now that uses in-source builds. What is the motivation for this type of structure and what are its advantages? (I am most concerned with engineering-level reasons vs. personal preference types of reasons.)

I was hoping Lakos' "Large-Scale C++ Software Design" would have weighed in on it, but I missed it if it did.

  • 2
    Apologies. I’m looking for “In source builds improve ‘x’” or “they help with ensuring ‘y’” or “automated tests can then ‘z’”. Not a rant. I’m specifically not wanting to get into a war of opinions here! – DiB Feb 6 '18 at 18:34
  • 10
    In-source builds are a curse you owe to the laziness of your predecessor. They are awful for about everything (source control, cross-building, text-finding, etc.) but are incredibly easy to create using bare makefiles. Sorry, this was a rant. But an objective one. – user44761 Feb 6 '18 at 19:48
  • 1
    What exactly do you mean by "in-source" builds? Something like /project/src/bin/release, or really all intermediate and output files in /project/src? The latter can be indeed a mess if there are more than a dozen source files, the former is ok. – Doc Brown Feb 6 '18 at 19:50
  • 2
    @Tibo, it is not only incredibly easy with makefiles, but seems to be the default with most IDEs as well (at least when I checked last a few years ago). – Bart van Ingen Schenau Feb 6 '18 at 19:58
  • 4
    @BartvanIngenSchenau Really? what IDE have you been using where this is the case? Qt doesn't do this, in fact it seems to put the build as far away as possible as it can from the source, Eclipse doesn't do this, You might argue that Clion sort of does this, but only as a consequence of main.cpp initially being in the top level of your project, it still creates a separate cmake build directory away from your source at that top level. I believe MSVS is similar to Clion in this regard as well. – whn Feb 6 '18 at 20:58
8

After asking the community here and continuing my search online, I have not been able to find significant engineering justification for using in-source builds. (There are many examples of reasons to avoid them.)

The only objective reason I have found (as alluded to in the comment by @BartvanIngenSchenau) is that in-source builds are sometimes defaulted to by a build system. Because of this default, they require no overhead in setup time, which may be perfectly acceptable for a very small (or scratch) project.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.