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:
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?