32

I am using CMake to generate the project files.

Is there a command with which I can clean up all those generated project files?

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Adam Lee
  • 23,314
  • 47
  • 144
  • 221
  • 2
    If it's a git repository, `git checkout . & git clean -dxf` will wipe everything clean to exactly the state of your git index. – Brent Jul 01 '17 at 20:47
  • I also looked for `cmake clean` command yesterday, found none. But now my question is why are there projects still building in root source folder instead of `build`? :) – Tien Do Sep 01 '18 at 06:35

1 Answers1

49

Is there a command with which I can clean up all those generated project files?

Yes - if you do an out-of-source build (as recommended).

To do so, create a directory - for example, build - within your projects directory and run CMake from there:

mkdir build
cd build
cmake ..
make

(Or tell your IDE to do so.)

Now all generated files are within build. To clean those, just remove the directory (rm -rf build).


PRO: You can keep all generated files out of your versioning system by adding build to its ignore ;-)

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
ollo
  • 24,053
  • 13
  • 97
  • 150
  • 4
    Just for completeness: There's no way to do it automatically in-source, is that correct? – Michael Jul 20 '16 at 08:22
  • 3
    if you call cmake from the root directory of your project it's in-source – all build files are then scattered into your project. Doing an out-of-source build will keep them within one place (eg. `build/`). So it's more an issue of how you use cmake. Did i get your question right? – ollo Jul 22 '16 at 18:11