[Cmake] Strange

Ken Martin ken . martin at kitware . com
Fri, 9 Aug 2002 11:29:49 -0400


This is a multi-part message in MIME format.

------=_NextPart_000_009B_01C23F98.128E4DD0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Hey Jim,

CMake uses immediate evaluation as you can see. The else clause evaluates
its arguments independently from the IF clause. Basically ELSE is the same
as:

ENDIF (foo)
IF (NOT foo)

This is a bit confusing and I'm pretty sure I can modify it. I don't think
anything relies on this behaviour right now so I'll take a stab at changing
it later today.

Thanks
Ken


  I may not be understanding how CMake handles IF/ELSE/ENDIF constructs. Or
this could
  be a bug.  The following CMakeLists.txt file outputs both "Not Bar" and
"Bar" indicating to
  me that both the IF clause and the ELSE clause are being executed.  If I
remove the SET
  command then the ELSE clause is not executed.

  What "should" happen in this case?


  PROJECT(FOO)

  IF (NOT BAR)
     MESSAGE("Not Bar")
     SET(BAR "garf")
  ELSE (NOT BAR)
     MESSAGE("Bar")
  ENDIF (NOT BAR)


------=_NextPart_000_009B_01C23F98.128E4DD0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns:o =3D "urn:schemas-microsoft-com:office:office"><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4916.2300" name=3DGENERATOR></HEAD>
<BODY>
<DIV><SPAN class=3D463181814-09082002><FONT face=3DArial size=3D2>Hey=20
Jim,</FONT></SPAN></DIV>
<DIV><SPAN class=3D463181814-09082002><FONT face=3DArial=20
size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D463181814-09082002><FONT face=3DArial =
size=3D2>CMake&nbsp;uses=20
immediate evaluation as you can see. The else clause evaluates its =
arguments=20
independently from the IF clause. Basically ELSE is the same=20
as:</FONT></SPAN></DIV>
<DIV><SPAN class=3D463181814-09082002><FONT face=3DArial=20
size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D463181814-09082002><FONT face=3DArial size=3D2>ENDIF=20
(foo)</FONT></SPAN></DIV>
<DIV><SPAN class=3D463181814-09082002><FONT face=3DArial size=3D2>IF =
(NOT=20
foo)</FONT></SPAN></DIV>
<DIV><SPAN class=3D463181814-09082002><FONT face=3DArial=20
size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D463181814-09082002><FONT face=3DArial size=3D2>This =
is a bit=20
confusing and I'm pretty sure I can modify it. I don't think anything =
relies on=20
this behaviour right now so&nbsp;I'll take a stab at changing it later =
today.=20
</FONT></SPAN></DIV>
<DIV><SPAN class=3D463181814-09082002><FONT face=3DArial=20
size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D463181814-09082002><FONT face=3DArial=20
size=3D2>Thanks</FONT></SPAN></DIV>
<DIV><SPAN class=3D463181814-09082002><FONT face=3DArial=20
size=3D2>Ken</FONT></SPAN></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px =
solid; MARGIN-RIGHT: 0px">
  <DIV class=3DOutlookMessageHeader dir=3Dltr align=3Dleft><FONT =
face=3DTahoma=20
  size=3D2><BR></FONT>&nbsp;</DIV>
  <DIV><SPAN class=3D144520814-09082002><FONT size=3D2>I may not be =
understanding=20
  how CMake handles IF/ELSE/ENDIF constructs. Or this could =
</FONT></SPAN></DIV>
  <DIV><SPAN class=3D144520814-09082002><FONT size=3D2>be a bug.&nbsp; =
The following=20
  CMakeLists.txt file outputs both "Not Bar" and "Bar" indicating to=20
  </FONT></SPAN></DIV>
  <DIV><SPAN class=3D144520814-09082002><FONT size=3D2>me that both the =
IF clause=20
  and the ELSE clause are being executed.&nbsp; If I remove the=20
  SET</FONT></SPAN></DIV>
  <DIV><SPAN class=3D144520814-09082002><FONT size=3D2>command then the =
ELSE clause=20
  is not executed.</FONT></SPAN></DIV>
  <DIV><SPAN class=3D144520814-09082002><FONT =
size=3D2></FONT></SPAN>&nbsp;</DIV>
  <DIV><SPAN class=3D144520814-09082002><FONT size=3D2>What "should" =
happen in this=20
  case?</FONT></SPAN></DIV>
  <DIV><FONT size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT size=3D2>PROJECT(FOO)</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT size=3D2>IF (NOT BAR)<BR>&nbsp;&nbsp; MESSAGE("Not=20
  Bar")<BR>&nbsp;&nbsp; SET(BAR "garf")<BR>ELSE (NOT =
BAR)<BR>&nbsp;&nbsp;=20
  MESSAGE("Bar")<BR>ENDIF (NOT BAR)</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT size=3D2></FONT>&nbsp;</DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_009B_01C23F98.128E4DD0--