18

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.

13
  • 3
    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, 2018 at 18:34
  • 14
    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, 2018 at 19:48
  • 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). Feb 6, 2018 at 19:58
  • 5
    @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.
    – Krupip
    Feb 6, 2018 at 20:58
  • 2
    @snb: I was using MS Visual Studio and its predecessors regularly over more than 20 years, and the default was always to have some separate folders for output files (though the concentions how and where those folders were placed differed slightly between older and newer versions and programming languages).
    – Doc Brown
    Feb 7, 2018 at 6:34

1 Answer 1

17

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.

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.