[CMake] if defined and boolean value

Matthew Woehlke matthew.woehlke at kitware.com
Mon Jul 15 16:13:57 EDT 2013


On 2013-07-13 17:54, Victor Aurélio Santos wrote:
> I'm trying to evaluate a expression "if variable X is defined and Y is ON":
> tried this:
> if (defined ${GETTEXT_LIB-NOTFOUND} and ${ENABLE_NLS})

For FOO not found, FOO-NOTFOUND gets defined? That'd be news to me... 
(Usually I expect FOO-NOTFOUND to be the value of FOO...)

Besides other comments re: case sensitivty, I'd expect to see a check 
like this written:

if(NOT GETTEXT_LIB AND ENABLE_NLS)

For the first, I don't know why you'd specifically want to check for 
'DEFINED GETTEXT_LIB-NOTFOUND' versus that GETTEXT_LIB is "valid" 
('if(FOO)' is false for FOO == FOO-NOTFOUND).

For the second, you probably do not want to expand ENABLE_NLS. Else I 
can break your build by doing something like '-DON=OFF'. (Granted that 
will probably make all kinds of problems, but in general I wouldn't 
expand variables when you want to Boolean-test them, because CMake will 
try to expand again the result of expansion.)

-- 
Matthew



More information about the CMake mailing list