# How to clean up unused cache variables?

**URL:** <https://discourse.cmake.org/t/how-to-clean-up-unused-cache-variables/3076>\
**Category:** Usage\
**Created:** [April 2, 2021, 9:19pm UTC](https://discourse.cmake.org/t/how-to-clean-up-unused-cache-variables/3076 "2021-04-02T21:19:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ymba9g8j9cjp0wloqf5y/32/1244_2.png) [@YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/u/YMba9g8j9CJp0wLoQf5y)\
**Post date:** [April 2, 2021, 9:19pm UTC](https://discourse.cmake.org/t/how-to-clean-up-unused-cache-variables/3076/1 "2021-04-02T21:19:39Z")

</div>

I have a project that has an option:

```auto
option(FOOBAR "hello world")

```

After a while I realize I don’t need this option. So I remove it from my project.

However, it’s still in my cache. This can cause confusion for other developers who don’t realize I removed it. Since the value will still show up in cmake-gui.

Is there a way to automatically delete unused project cache variables?

---

<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:** [April 3, 2021, 1:42pm UTC](https://discourse.cmake.org/t/how-to-clean-up-unused-cache-variables/3076/2 "2021-04-03T13:42:16Z")

</div>

Automatically? No.

[This (old) feature request](https://gitlab.kitware.com/cmake/cmake/-/issues/14756) might be of interest though since it would basically end up tracking cache variables anyways. It could be extended to track non-advanced variables that aren’t used at all (though it’d likely be an extension).

---

<div class="post-metadata">

**Author:** ![YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ymba9g8j9cjp0wloqf5y/32/1244_2.png) [@YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/u/YMba9g8j9CJp0wLoQf5y)\
**Post date:** [April 5, 2021, 2:25pm UTC](https://discourse.cmake.org/t/how-to-clean-up-unused-cache-variables/3076/3 "2021-04-05T14:25:00Z")

</div>

Well if there is no way to clean up unused cache variables, then what’s the workflow for CMake supposed to look like? Delete the cache once a month?

---

<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:** [April 5, 2021, 3:31pm UTC](https://discourse.cmake.org/t/how-to-clean-up-unused-cache-variables/3076/4 "2021-04-05T15:31:46Z")

</div>

I don’t think there’s a “supposed to” for this. Generally they just accumulate and if they start to get noisy, a refreshing the build tree is always an option.

---

<div class="post-metadata">

**Author:** ![YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ymba9g8j9cjp0wloqf5y/32/1244_2.png) [@YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/u/YMba9g8j9CJp0wLoQf5y)\
**Post date:** [April 5, 2021, 5:58pm UTC](https://discourse.cmake.org/t/how-to-clean-up-unused-cache-variables/3076/5 "2021-04-05T17:58:38Z")

</div>

Can’t this be fixed? I’m 100% sure this is going to cause confusion at my company eventually.

---

<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:** [April 5, 2021, 6:20pm UTC](https://discourse.cmake.org/t/how-to-clean-up-unused-cache-variables/3076/6 "2021-04-05T18:20:49Z")

</div>

That issue is the closest thing I’m aware of on the issue tracker. Anything related to this is likely going to share similar roots with what that needs.

---

<div class="post-metadata">

**Author:** ![YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ymba9g8j9cjp0wloqf5y/32/1244_2.png) [@YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/u/YMba9g8j9CJp0wLoQf5y)\
**Post date:** [April 5, 2021, 6:49pm UTC](https://discourse.cmake.org/t/how-to-clean-up-unused-cache-variables/3076/7 "2021-04-05T18:49:36Z")

</div>

Gotcha.
