# Is setting empty-named variable defined behaviour?

**URL:** https://discourse.cmake.org/t/is-setting-empty-named-variable-defined-behaviour/15305
**Category:** Code
**Created:** [November 14, 2025, 9:44am UTC](https://discourse.cmake.org/t/is-setting-empty-named-variable-defined-behaviour/15305 "2025-11-14T09:44:22Z")
**Posts on this page:** 3
**Page:** 1

<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: [November 14, 2025, 9:44am UTC](https://discourse.cmake.org/t/is-setting-empty-named-variable-defined-behaviour/15305/1 "2025-11-14T09:44:22Z")

</div>

Hi all.

**Short version:**  
`set("" value PARENT_SCOPE)` currently works, and does nothing. Is that behaviour well-defined and can it be relied on?

**Long version:**  
I’m simplifying some CMake code in a project and there are several functions which the caller can ask for different pieces of information. In effect, each such function is a long sequence of code like this:

```auto
if(arg_COMPILE_OPTIONS)
  set(${arg_COMPILE_OPTIONS} /WX- /vmg /vmv PARENT_SCOPE)
endif()
if(arg_BASE_DIR)
  set({$arg_BASE_DIR} some/path PARENT_SCOPE)
endif()

```

The conditionals effectively make the function 3x as long in terms of code lines. Experimentally, I’ve found that doing `set("${arg_BASE_DIR}" some/path PARENT_SCOPE)` works just as this situation requires: nothing happens when `arg_BASE_DIR` is empty.

If I could rely on this behaviour, it would make our functions much shorter and more readable. However, I wouldn’t want to introduce undefined or unsupported code. Hence my question:

Can I rely on `set("" value PARENT_SCOPE)` remaining valid code and behaving reasonably? That is, remaining a no-op as it is now, or setting an empty-named variable in the parent scope. Or is this considered an error, just not diagnosed?

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [November 14, 2025, 9:58pm UTC](https://discourse.cmake.org/t/is-setting-empty-named-variable-defined-behaviour/15305/2 "2025-11-14T21:58:20Z")

</div>

Without looking at the implementation, my view is that should be a fatal error. I would not rely on it continuing to be supported in future CMake versions, although we’d probably need to change that behavior with a policy.

---

<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: [February 19, 2026, 8:52pm UTC](https://discourse.cmake.org/t/is-setting-empty-named-variable-defined-behaviour/15305/3 "2026-02-19T20:52:51Z")

</div>

See also this issue: [https://gitlab.kitware.com/cmake/cmake/-/issues/23954](https://gitlab.kitware.com/cmake/cmake/-/issues/23954)
