[CMake] Reverse logic

Matthew Woehlke mw_triad at users.sourceforge.net
Thu Jan 30 10:34:51 EST 2014


On 2014-01-29 19:09, Rob McDonald wrote:
> I feel like this is a really dumb question, but I've got myself wrapped
> around the axel....
>
> I'd like to use a negative conditional on a variable that may or may not be
> defined...  say USE_SYSTEM_FOO
>
> So, I'd like to do something like this...
>
> IF( NOT ${USE_SYSTEM_FOO} )
>      # Build my own FOO
> ENDIF()
>
> However, this does not work as desired.  On the other hand, the following
> version does have the desired behavior (shouldn't these be the same?).
>
> IF( ${USE_SYSTEM_FOO} )
> ELSE()
>      # Build my own FOO
> ENDIF()
>
> I tried a couple of combinations with DEFINED thrown in.  They didn't work
> as desired either.  I didn't chase after a compound conditional like the
> following simply due to ugliness....
>
> IF( NOT DEFINED ${USE_SYSTEM_FOO} OR NOT ${USE_SYSTEM_FOO} )
>      # Build my own FOO
> ENDIF()

Expanding somewhat on JC's reply... do you realize you wrote e.g. 
'if(NOT DEFINED ON)' here? "${NAME}" means "before evaluating anything 
else, replace '${NAME}' with the value of the variable 'NAME' (or 
nothing, if 'NAME' is unset)".

Dereferencing is automatic in this context (especially 'DEFINED', which 
operates on a variable name). So as JC wrote, you will probably have 
better success omitting the dereference.

-- 
Matthew



More information about the CMake mailing list