diff options
author | Brad King <brad.king@kitware.com> | 2021-12-20 14:44:30 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2021-12-20 14:44:43 (GMT) |
commit | ece1900731a236fbb92ce89a8e47d09b1a6459a0 (patch) | |
tree | 43e072dbe6d01b5229d6df93173f0570bfac1139 | |
parent | 85833461af12c03f67d86167bd71fd9b198d99f5 (diff) | |
parent | a45e9227683f6832806c0d38d9ff9aadfa940e81 (diff) | |
download | CMake-ece1900731a236fbb92ce89a8e47d09b1a6459a0.zip CMake-ece1900731a236fbb92ce89a8e47d09b1a6459a0.tar.gz CMake-ece1900731a236fbb92ce89a8e47d09b1a6459a0.tar.bz2 |
Merge topic 'doc-if-defined'
a45e922768 Help: Clarify behavior of if(DEFINED) for cache and non-cache variables
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !6817
-rw-r--r-- | Help/command/if.rst | 11 |
1 files changed, 10 insertions, 1 deletions
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 <name>|CACHE{<name>}|ENV{<name>})`` True if a variable, cache variable or environment variable with given ``<name>`` 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 `<name>` 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{<name>}`` variables. |