# unset cache variable in add\_custom\_target()

**URL:** <https://discourse.cmake.org/t/unset-cache-variable-in-add-custom-target/9366>\
**Category:** Code\
**Created:** [November 4, 2023, 10:51pm UTC](https://discourse.cmake.org/t/unset-cache-variable-in-add-custom-target/9366 "2023-11-04T22:51:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fabian188](https://discourse.cmake.org/user_avatar/discourse.cmake.org/fabian188/32/2934_2.png) [@Fabian188](https://discourse.cmake.org/u/Fabian188)\
**Post date:** [November 4, 2023, 10:51pm UTC](https://discourse.cmake.org/t/unset-cache-variable-in-add-custom-target/9366/1 "2023-11-04T22:51:24Z")

</div>

In my (limited) understanding, my required functionality is not possible, but I better ask.

Ich have custom targets called “clean-xyz” which remove files nicely via cmake -E remove …

I would like to also unset a cmake cache variable when I call clean-xyz but I believe, this is not possible as it would require CMakeCache.txt manipulation.

---

<div class="post-metadata">

**Author:** ![fdk17](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/f/ea666f/32.png) [@fdk17](https://discourse.cmake.org/u/fdk17)\
**Post date:** [November 17, 2023, 8:46am UTC](https://discourse.cmake.org/t/unset-cache-variable-in-add-custom-target/9366/2 "2023-11-17T08:46:47Z")

</div>

I’m not sure why you say it is not possible, I would have tried using `cmake -U <var>` from the custom command.

---

<div class="post-metadata">

**Author:** ![Fabian188](https://discourse.cmake.org/user_avatar/discourse.cmake.org/fabian188/32/2934_2.png) [@Fabian188](https://discourse.cmake.org/u/Fabian188)\
**Post date:** [November 17, 2023, 11:29am UTC](https://discourse.cmake.org/t/unset-cache-variable-in-add-custom-target/9366/3 "2023-11-17T11:29:24Z")

</div>

Thank you very much, I was not aware of this option. I added a cmake . -U … to my custom target and it works.

It would be a bonus, if cmake would only remove the variable from the cache and not process CMakeLists.txt the same time, but already the current state is an improvement! 🙂
