-4

I've checked quite a few related questions on source tree organization, but couldn't find the answer for my exact need:

For a project I'm working on, my source tree is organized this way

  • build: all build scripts and resources required by continuous integration
  • src: all first-party source code and IDE projects of our team
  • test: all the code and data required for automated tests
  • thirdparty: all external dependencies
    • _original_: all downloaded open-source library archives
    • libthis: unzipped open-source lib with possible custom changes
    • libthat: ...
    • ....

So far I've been building our first-party build products right in the src folder inside each IDE projects, such as Visual Studio and Xcode; and build the third-party products in their own working copy folders.

Problem

However, this reveals several drawbacks, e.g.:

  • In order to accommodate the variety of dependency locations, the lib search paths of the first-party IDE projects become messy
  • it's hard to track the output products through the file system

Intentions

So I'd love to centralize all the build products including dependencies and our first-party products, so that

  • the build products don't mess up the repo SCM tidiness
  • all the targets and intermediates are easy to rebuild, archive, or purge
  • it's easy to track down to the sub source tree of the products from file system

Current Ideas

I've tried to create another folder, e.g., _prebuilt_ under thirdparty folder so that it looks like this

  • thirdparty
    • _original_
    • _prebuilt_: holding build products from all thirdparty libs for all platforms
      • platform1
      • platform2
      • platform3
      • ....
    • libthis
    • libthat
    • ...

One complaint I have towards this scheme: mixing derivatives with working copies (lib...) and archives (original) forces me to make folders of derivatives and archives stand out by naming them with ugly markups, in this case underscores (_).

Another idea is to use a universal folder right at the root of the repo and have all the artifacts of dependencies and project products sit there in a jumble. But then, it sounds messy and would be hard to track the artifacts' sources.

Either way, some post-build scripts must be set in action to move artifacts out of their original working copies.

Question

In general, what would be the best practice to organize the build products? Any justifications?

I'd love to achieve at least the goals in the Intentions above.

kakyo
  • 95
  • 4
  • It depends on your operating system (e.g. different on Linux and Windows), your programming language (different with Ocaml and C++ and Go), your build automation tool (different if using [ninja](http://ninja-build.org/) or [GNU make](https://www.gnu.org/software/make/) or [omake](http://projects.camlcity.org/projects/omake.html)..). Read also more about [package managers](https://en.wikipedia.org/wiki/Package_manager) and see also https://linuxfromscratch.org/ – Basile Starynkevitch Jul 02 '20 at 04:26
  • @BasileStarynkevitch The problem is that most dependencies use different build systems, so I'm asking about a general high-level approach. My project combines native C/C++ and some hight-level languages. The dependencies are mostly C/C++ projects. – kakyo Jul 02 '20 at 04:35
  • Why the downvotes? I believe I'm asking a specific question that's not a duplicate of anything I can find on this stack site. – kakyo Jul 02 '20 at 04:37
  • 3
    I downvoted because the question is too general and too broad. There cannot be a single general high-level approach. For example, look into the source code of [Debian](http://debian.org/) and study the source code of [ocsigen](https://ocsigen.org/), of [GNU emacs](https://www.gnu.org/software/emacs/), of [GHC](https://www.haskell.org/ghc), of [FLTK](http://fltk.org/) – Basile Starynkevitch Jul 02 '20 at 04:39
  • @BasileStarynkevitch well, there were upvotes for all my cited questions on the same stack. Those questions are much broader than mine. Could you kindly refer to the beginning of my question? – kakyo Jul 02 '20 at 04:43
  • 1
    Study also for inspiration the source code of the [Linux kernel](http://kernel.org/), of [Clang](http://clang.llvm.org/), of [GCC](http://gcc.gnu.org/), of [Qt](https://qt.io/), of [Opam](https://opam.ocaml.org/), [Gnome](https://www.gnome.org/) – Basile Starynkevitch Jul 02 '20 at 04:46
  • Look also into the source code of [SBCL](http://sbcl.org/) – Basile Starynkevitch Jul 02 '20 at 04:53
  • @BasileStarynkevitch Good advice on checking out renowned projects. Thanks! – kakyo Jul 03 '20 at 06:21
  • 1
    For .Net see https://softwareengineering.stackexchange.com/questions/369504/directory-structure-for-a-net-solution/369507#369507 – Michael Freidgeim Dec 02 '20 at 20:10

1 Answers1

2

Many build tools nowadays support "out of source" builds, where the intermediate and final build artifacts are stored in a location outside of the source tree. This is comparable to your idea of a folder at the root of the repo.

But this central folder does not have to contain a jumble of files. You could also organize it like this:

  • artifacts
    • libthis: Build artifacts from libthis
    • libthat: Build artifacts from libthat
    • project: Build artifacts from your own project

That should meet your objectives.

As a side note, a common convention when using out-of-source builds is to put the build artifacts in a folder called build. I used artifacts above because you already have a build folder for a different purpose, so that is something to be aware of when you see a build folder being referenced.

Bart van Ingen Schenau
  • 71,712
  • 20
  • 110
  • 179