2

Currently my project structure looks like this:

  • project
    • .git
    • include
    • source
    • test

and I want to add a "build" directory to it, so that people know where to build with cmake.

I want the build directory to be empty, so in my .gitignore I added:
build/*
so that it ignores everything in that directory.

The problem is that git also doesn't track the directory because its empty. So I tried adding a README.txt (containing "build cmake solutions here") to make it so that git would track it, (And I edited the .gitignore file, obviously) but, unfortunately, that seem to mess up cmake.

When I try to build on windows using the cmake gui and choose the build directory, it doesn't generate the visual studio solution, but when I remove the README.txt file from the folder, cmake works again.

I'm guessing it's because cmake doesn't allow any other files in the build directory.

So I cant have the README.txt file in the folder because it messes up cmake for some reason, but I also can't leave the directory empty because that will make git stop tracking it....

So what do I do?

8bittree
  • 1,769
  • 2
  • 18
  • 25
stav
  • 199
  • 4
  • 2
    This question is off topic for this site, but spot on for StackOverflow. – Greg Burghardt Jun 28 '17 at 01:07
  • Does CMake break when there's _any_ file in the directory? Would it work if you create an empty `.gitkeep` file? – Greg Navis Jun 28 '17 at 02:43
  • 2
    Git tracks file contents, not folders. If you need a particular folder structure, the usual way is to generate this structure via a script. In your case, your CMake files should create the directory if it doesn't exist. Maybe someone who knows the correct syntax for that could write an answer. – amon Jun 28 '17 at 06:01
  • 3
    Possible duplicate of [How can I add an empty directory to a Git repository?](https://stackoverflow.com/questions/115983/how-can-i-add-an-empty-directory-to-a-git-repository) – Stargateur Jun 28 '17 at 06:01
  • Your arrangement assumes the developer only uses one build directory, but it is not unusual to have multiple build directories for a single source tree. For example, different build dirs might have different build configurations (e.g. Debug, Release, etc.) and devs might move between them depending on what they are testing. It's also common to completely delete a build directory and start again, so you don't really want to make the build dir itself part of the git repo. – Craig Scott Jun 29 '17 at 11:28

2 Answers2

1

In the "project" directory, I have a .gitignore file containing:

!.gitignore
!/build/*

In the "project/build" directory, I have a .gitignore file containing:

# Ignore everything in this directory
*
# - except .gitignore and README files
!.gitignore
!README*

I even put in a "project/build/README.txt" file with "build cmake solutions here" as text.

Everything checks into git, including the "build" and .gitignore files.

Everything builds correctly with Visual Studio 2015 Win64 and Ninja generators with cmake-gui and cmake from command line.

utopia
  • 1,477
  • 8
  • 7
0

I mean it might sound odd, but why not just put that README.txt file you created at the top most folder in your project hierarchy. That way you can explain it to anyone who uses the project, and your not checking in empty folders into your VCS.

Rhys Johns
  • 109
  • 3