0

My personal experience is that the build folder should be ignored in git by default. I've come across situations where one would want to add the build folder to git (and perhaps an additional README.txt in it) to let users know where to build the project. However, that is deviating from the general premise that anything automatically generated should never be part of a repository.

So why am I asking, then? Well, the GitHub's own gitignore repository did not include the build/ line in any one of the .gitignore files I combined together, not even in the CMake.gitignore itself. That to me is a reason to doubt my own judgement.

Should build/ be part of the CMake gitignore? Is it not there because of the assumption that users are always doing true out-of-source builds? To my experience, that is very false. In fact, I haven't seen a single guide recommend a true out-of-source build once. Not even the Microsoft's own VS Code CMake Tools extension does true out-of-source builds.

I assume it's safe to add build/ to my root .gitignore file. But what are the reasons to not do it?

Marty Cagas
  • 350
  • 5
  • 14
  • "_that is deviating from the general premise that anything automatically generated should never be part of a repository_": This is just a conventional opinion. It also assumes some other things such as (1) users visit your repository only in search of source code, and (2) if your project builds artifacts, that they are published and equally as discoverable as the source code or that (3) **every** user interested in such artifacts can build them (which is almost always a fallacy) – jsejcksn Aug 18 '22 at 18:47
  • @jsejcksn I see, thank you for the input. I'd like to say I'm geuinely trying to learn the reasons behind decisions others made (such as the ones in the gitignore repository), as the answers to "why" are at times hard to find. I appreciate hearing everything, even that I'm wrong. – Marty Cagas Aug 18 '22 at 18:57
  • [^](https://stackoverflow.com/questions/73408010/is-there-ever-a-reason-to-not-ignore-the-build-folder-in-git-when-building-with?noredirect=1#comment129637003_73408010) "_the answers to "why" are at times hard to find_": Yes, they can be, and (unfortunately toward that end), you'll find that this is not the right community for finding them because they are rooted in opinion, which is off-topic for questions. (Even specified standards take shape from conventionally-held opinions after deliberation in most cases). IMO, this kind of knowledge acquisition is an extreme pain point, esp. in OSS. – jsejcksn Aug 18 '22 at 19:03
  • @jsejcksn I am aware the question is... slightly opinionated. I was hoping I could at least get a non-exhaustive list of objective reasons why more experienced programmers are leaving the build folders in their repositories. That way I could look at the reasons and get my own idea. This is all motivated by the fact, that if something as well-known as the official gitignore repository doesn't leave have the build folder ignored there, there is probably a good reason for it and I'm hoping to learn what it is. – Marty Cagas Aug 18 '22 at 19:33
  • 2
    [^](https://stackoverflow.com/questions/73408010/is-there-ever-a-reason-to-not-ignore-the-build-folder-in-git-when-building-with?noredirect=1#comment129637623_73408010) You should ask the person who created/committed the file that you're wondering about. Templates, by definition, are designed to be generic. – jsejcksn Aug 18 '22 at 19:36
  • 1
    The use of the directory `build` in the same directory as the toplevel `CMakeLists.txt` is just something that's used by many cmake examples, but by no means is this the only place where you can set up the build directory. There's nothing preventing you from using `foo/bar` instead. In fact I'd consider the use of `build` impractical, since you may want to create multiple configurations e.g. debug/release for unix makefiles/ x64/Win32 for VS.There's a chance that your project may contain scripts aiding the build process in a dir`build`and in that case adding the dir to the ignores is dangerous – fabian Aug 19 '22 at 16:18
  • 1
    _By design_, the choice of the build folder in a CMake project is _up to any/the user who builds the project_. They can choose `./build/` (which is a common choice), but they can choose something else entirely. That could be a reason factoring into why it's not part of the GitHub template gitignore file. In my personal projects, I put `/build/` in my gitignore file (and later switched to `/out/` when I started working with multiple compilers). Choose something that you think makes sense for your project and your average users. There's a bit of subjectivity here I think. – starball Oct 27 '22 at 07:38

0 Answers0