[CMake] Re: Weird if nesting problem

Ken Martin ken.martin at kitware.com
Mon Dec 11 16:01:38 EST 2006


> IF(1)
> ELSE(1)
>    FIND_PROGRAM(P_1 p_1)
>    FIND_PROGRAM(P_2 p_2)
>    IF(EXISTS ${P_1} AND EXISTS ${P_2} )
>    ELSE(EXISTS ${P_1} AND EXISTS ${P_2} )
>    ENDIF(EXISTS ${P_1} AND EXISTS ${P_2} )
> ENDIF(1)

So :) This is effectively an implementation bug. I suspect it can be fixed
reasonably easily and when I get a sec I will try to fix it up. This fails
because P_1 and P_2 may be empty resulting in IF (EXISTS AND EXISTS) which
is an error.  In fact for this case they will almost certainly be empty
because the FIND_PROGRAM calls do not get made. You might think the nested
IF call would also not get made, but it does :) The implementation is such
that the tracking of nested ifs involves evaluating their arguments even if
they are inside a scope that is not being executed. No other commands get
executed inside such a scope except for IF. And in this case the arguments
are not valid because P_1 and P_2 have not been found (as we didn't execute
the FIND_PROGRAM) commands. It should be fixed as it is very counter
intuitive (and actually computationally slower than it needs to be) so feel
free to create a bug report and assign it to me if you can.

Thanks
Ken 




More information about the CMake mailing list