# Can a parent detect what a function has changed with set(... PARENT\_SCOPE)?

**URL:** <https://discourse.cmake.org/t/can-a-parent-detect-what-a-function-has-changed-with-set-parent-scope/2864>\
**Category:** Code\
**Created:** [March 2, 2021, 3:09am UTC](https://discourse.cmake.org/t/can-a-parent-detect-what-a-function-has-changed-with-set-parent-scope/2864 "2021-03-02T03:09:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![axel](https://discourse.cmake.org/user_avatar/discourse.cmake.org/axel/32/1196_2.png) [@axel](https://discourse.cmake.org/u/axel)\
**Post date:** [March 2, 2021, 3:09am UTC](https://discourse.cmake.org/t/can-a-parent-detect-what-a-function-has-changed-with-set-parent-scope/2864/1 "2021-03-02T03:09:12Z")

</div>

Can a parent detect what a function has changed with `set(... PARENT_SCOPE)`?

My use case is that I have multiple layer of function. Previously, `func1()` simply called `func2()` but now `func1()` calls `func1_a()` which calls `func2()`. In `func1_a()` I want to transparently pass everything that `func2()` changes up to `func1()`.  
Note that I cannot make `func1_a()` simply a macro, it has to be a function. And I using cached/internal variables is also not really an option, as this would expose some internals that should not be exposed actually.

Thanks, Axel

---

<div class="post-metadata">

**Author:** ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)\
**Post date:** [March 2, 2021, 10:06am UTC](https://discourse.cmake.org/t/can-a-parent-detect-what-a-function-has-changed-with-set-parent-scope/2864/2 "2021-03-02T10:06:24Z")

</div>

You can use the [property `VARIABLES`](https://cmake.org/cmake/help/latest/prop_dir/VARIABLES.html) to retrieve the list of all variables accessible in the current scope (this includes cache variables). You could store the values of all variables of intereset before calling `func2()`, then compare their values after the call, and propagate upwards whatever changed. I can’t say I would recommend this solution (and it will have its performance costs), but it is _a_ solution.

---

<div class="post-metadata">

**Author:** ![axel](https://discourse.cmake.org/user_avatar/discourse.cmake.org/axel/32/1196_2.png) [@axel](https://discourse.cmake.org/u/axel)\
**Post date:** [March 2, 2021, 12:31pm UTC](https://discourse.cmake.org/t/can-a-parent-detect-what-a-function-has-changed-with-set-parent-scope/2864/3 "2021-03-02T12:31:24Z")

</div>

Thanks, that would be a technical solution indeed.  
I wonder, if I should raise a feature request, that CMake should set a variable that contains the list of modified variables? The other solution would work by cooperation, the called function should provide such a list

---

<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:** [March 2, 2021, 4:43pm UTC](https://discourse.cmake.org/t/can-a-parent-detect-what-a-function-has-changed-with-set-parent-scope/2864/4 "2021-03-02T16:43:45Z")

</div>

I’ve usually had such functions take variable names as parameters rather than using hard-coded variable names (if you can change the inner function signature).
