Thanks, I will be using this method:<br><br>if (myvar MATCHES "^somestring$")<br>endif()<br><br>Do NOT use "${myvar}" because that forces CMake to treat the value of myvar as a variable name if it exists. That will give you accidentally indirection that may point to the value of another string.<br>
<br><br><div class="gmail_quote">On Fri, Feb 15, 2013 at 12:13 PM, Alexander Neundorf <span dir="ltr"><<a href="mailto:a.neundorf-work@gmx.net" target="_blank">a.neundorf-work@gmx.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On Thursday 14 February 2013, Shaun Williams wrote:<br>
> I'm slowly realizing the gravity of this behavior:<br>
><br>
> if(build_system STREQUAL "windows")<br>
> ...<br>
> endif()<br>
><br>
> If someone creates a variable named "windows", then this code will not work<br>
> as intended.<br>
><br>
> I'm starting to convert our scripts to use this hopefully foolproof<br>
> alternative:<br>
><br>
> string(COMPARE EQUAL "${build_system}" windows _cmp)<br>
> if (_cmp)<br>
> ...<br>
> endif()<br>
><br>
> It will make it ugly to create a nested if else block, but it'll work.<br>
<br>
</div>You can do<br>
if("${myvar}" MATCHES "somestring")<br>
or more strict<br>
<br>
if("${myvar}" MATCHES "^somestring$")<br>
<br>
Alex<br>
</blockquote></div><br>