From a45e9227683f6832806c0d38d9ff9aadfa940e81 Mon Sep 17 00:00:00 2001 From: Craig Scott Date: Mon, 20 Dec 2021 19:27:39 +1100 Subject: Help: Clarify behavior of if(DEFINED) for cache and non-cache variables Fixes: #23023 --- Help/command/if.rst | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Help/command/if.rst b/Help/command/if.rst index 5dba13e..6957142 100644 --- a/Help/command/if.rst +++ b/Help/command/if.rst @@ -126,7 +126,16 @@ Existence Checks ``if(DEFINED |CACHE{}|ENV{})`` True if a variable, cache variable or environment variable with given ```` is defined. The value of the variable - does not matter. Note that macro arguments are not variables. + does not matter. Note the following caveats: + + * Macro arguments are not variables. + * It is not possible to test directly whether a `` is a non-cache + variable. The expression ``if(DEFINED someName)`` will evaluate to true + if either a cache or non-cache variable ``someName`` exists. In + comparison, the expression ``if(DEFINED CACHE{someName})`` will only + evaluate to true if a cache variable ``someName`` exists. Both expressions + need to be tested if you need to know whether a non-cache variable exists: + ``if(DEFINED someName AND NOT DEFINED CACHE{someName})``. .. versionadded:: 3.14 Added support for ``CACHE{}`` variables. -- cgit v0.12