[CMake] If syntax

Michael Wild themiwi at gmail.com
Mon May 2 08:16:55 EDT 2011


[fixed top-posting and missing quotation characters]
On 05/02/2011 12:20 PM, Mika.Rajala at patria.fi wrote:
>> On 05/01/2011 10:30 PM, David Doria wrote:
>>> According to this:
>>> http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:if
> <http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:if>
>>>
>>> the syntax is:
>>>
>>>   if(expression)
>>>     ...
>>>   elseif(expression2)
>>>     ...
>>>   else(expression)
>>>     ...
>>>   endif(expression)
>>>
>>> I was recently made aware that:
>>>
>>>
>>>   if(expression)
>>>     ...
>>>   elseif(expression2)
>>>     ...
>>>   else()
>>>     ...
>>>   endif()
>>>
>>> should also work. Should the documentation be updated to reflect this
>>> possibility? Or are they different in some way?
>>>
>>> David
>> 
>> From the documentation of the IF() command:
>> 
>>> Note that the expression in the else and endif clause is optional.
>> 
>> Michael
>
>
> Hi
>
> if(expression)
>  ...
> endif(expression2)
>
> Makes an error since the expressions didn't match
>
> I think this is the case with "else" as well.
>
> However, i'm uncertain how to write it when you use elseif, maybe it
> still needs to match with the expression in the IF thing
>
>
> The reasoning behind this, AFAIK, is to provide checking for errors in
> your scripts.
>
> Feel free to leave those out from else and endif if you trust
> yourself : )
>
> -mika
>

In the else() and endif() clause you have to use the expression used in
the initial if() clause.

Michael


More information about the CMake mailing list