# How do I change a cache variable which is used in my code

**URL:** <https://discourse.cmake.org/t/how-do-i-change-a-cache-variable-which-is-used-in-my-code/7094>\
**Category:** Code\
**Created:** [December 18, 2022, 11:20am UTC](https://discourse.cmake.org/t/how-do-i-change-a-cache-variable-which-is-used-in-my-code/7094 "2022-12-18T11:20:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![abteikartei](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/4491bb/32.png) [@abteikartei](https://discourse.cmake.org/u/abteikartei)\
**Post date:** [December 18, 2022, 11:20am UTC](https://discourse.cmake.org/t/how-do-i-change-a-cache-variable-which-is-used-in-my-code/7094/1 "2022-12-18T11:20:07Z")

</div>

Hi!  
I have a boolean cache variable `MY_VARIABLE` that is used via `configure_file` and `#ifdef` to change what parts of my code are build. By default it is turned off. But if I change the variable with `-DMY_VARIABLE=ON` during the configure step the configure file is not updated.

That is probably because the input configure file has not changed. But how do I get `MY_VARIABLE` into my program so that `#ifdef` works? I tried to run `cmake -E touch` on my input configure file, but that also didn’t lead to any changes. The only way it works for me is to completely delete the build directory and reconfigure.

Thanks in advance for any pointers on this, I have been trying to get this to work for weeks.

---

<div class="post-metadata">

**Author:** ![abteikartei](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/4491bb/32.png) [@abteikartei](https://discourse.cmake.org/u/abteikartei)\
**Post date:** [December 18, 2022, 11:40am UTC](https://discourse.cmake.org/t/how-do-i-change-a-cache-variable-which-is-used-in-my-code/7094/2 "2022-12-18T11:40:51Z")

</div>

I think I finally solved it, just as I made this post. In the end I started using `#cmakedefine MY_VARIABLE` and I simply misread the documentation. So the important (and surprising) part with `#cmakedefine` for me was that **I did not need @'s around my variable**!

So this is wrong: ~~`#cmakedefine @MY_VARIABLE@`~~. Instead use `#cmakedefine MY_VARIABLE`.
