# Cleaning policy?

**URL:** <https://discourse.cmake.org/t/cleaning-policy/331>\
**Category:** Code\
**Created:** [December 6, 2019, 2:44pm UTC](https://discourse.cmake.org/t/cleaning-policy/331 "2019-12-06T14:44:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DavidA](https://discourse.cmake.org/user_avatar/discourse.cmake.org/davida/32/128_2.png) [@DavidA](https://discourse.cmake.org/u/DavidA)\
**Post date:** [December 6, 2019, 2:44pm UTC](https://discourse.cmake.org/t/cleaning-policy/331/1 "2019-12-06T14:44:32Z")

</div>

I am about to introduce CMake to our organisation. A question likely to come up is how to ‘clean’ a build directory. My understanding is that CMake doesn’t offer support for ‘clean’.

What is the recommendation? Should users simply delete all items in the build directory using:

rm -rf \*

and then issue a fresh cmake command to recreate the cache etc?

---

<div class="post-metadata">

**Author:** ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)\
**Post date:** [December 6, 2019, 2:55pm UTC](https://discourse.cmake.org/t/cleaning-policy/331/2 "2019-12-06T14:55:21Z")

</div>

A target `clean` is automatically generated by `CMake` (at least for `Nina` and `Makefile` generators) which can be used to clean-up build artifacts (not the `CMake` generated files).

`CMake` also generate dependencies over its own files (i.e. CMakeListrs.txt files), so editing any `CMake` file will relaunch `CMake` generation at the next build action.

And, if you want to change your configuration (impacting the cache), the easiest way is effectively to remove all the stuff under your build directory and relaunch a generation.

---

<div class="post-metadata">

**Author:** ![DavidA](https://discourse.cmake.org/user_avatar/discourse.cmake.org/davida/32/128_2.png) [@DavidA](https://discourse.cmake.org/u/DavidA)\
**Post date:** [December 6, 2019, 3:06pm UTC](https://discourse.cmake.org/t/cleaning-policy/331/3 "2019-12-06T15:06:51Z")

</div>

@marc.chevrier Thanks for your answer.

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [December 6, 2019, 7:59pm UTC](https://discourse.cmake.org/t/cleaning-policy/331/4 "2019-12-06T19:59:48Z")

</div>

> [@marc.chevrier](#):
>
> And, if you want to change your configuration (impacting the cache), the easiest way is effectively to remove all the stuff under your build directory and relaunch a generation.

There’s also [`ctest_empty_binary_directory`](https://cmake.org/cmake/help/latest/command/ctest_empty_binary_directory.html) if you’re building things from a CTest script to clean the directory.
