Thanks, I will be using this method:

if (myvar MATCHES "^somestring$")
endif()

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.


On Fri, Feb 15, 2013 at 12:13 PM, Alexander Neundorf <
a.neundorf-w...@gmx.net> wrote:

> On Thursday 14 February 2013, Shaun Williams wrote:
> > I'm slowly realizing the gravity of this behavior:
> >
> > if(build_system STREQUAL "windows")
> > ...
> > endif()
> >
> > If someone creates a variable named "windows", then this code will not
> work
> > as intended.
> >
> > I'm starting to convert our scripts to use this hopefully foolproof
> > alternative:
> >
> > string(COMPARE EQUAL "${build_system}" windows _cmp)
> > if (_cmp)
> > ...
> > endif()
> >
> > It will make it ugly to create a nested if else block, but it'll work.
>
> You can do
> if("${myvar}" MATCHES "somestring")
> or more strict
>
> if("${myvar}" MATCHES "^somestring$")
>
> Alex
>
--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to