[CMake] Testing whether a variable has already been assigned
a non-null value
Brad King
brad.king at kitware.com
Mon Oct 2 10:39:07 EDT 2006
Alan W. Irwin wrote:
> I have noticed tests like
>
> IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
>
> in, e.g., CheckFunctionExists.cmake where VARIABLE is a macro argument.
> From
> the context I assume it is a test for whether the actual variable used in
> the macro call has been assigned a non-null value, but I don't get why
> it works. Could somebody please explain?
>
> What is the best way to decide if the variable X has been assigned a
> non-null value when X is not an argument of a macro? Something like
> "IF(NOT
> X)" ? Or is there some transformation of the above MATCHES text that is
> recommended?
IF(DEFINED X)
The MATCHES hack is left over from code written before IF(DEFINED ...)
was implemented.
-Brad
More information about the CMake
mailing list