On Thursday 21 March 2013, Matthew Woehlke wrote:
> On 2013-03-21 16:55, David Cole wrote:
> > I almost always do one of these for string compare to a CMake variable
> > 
> > value:
> >      if("${var}" STREQUAL "some string constant")
> >      if("${var}" STREQUAL "${some_other_variable}")
> > 
> > However, this is only because I am almost always certain that ${var}
> > does not evaluate to the name of yet another CMake variable.
> > If it did, I would get unintended results.
> > 
> > So I wouldn't say it's necessarily a best-practice. It's "close enough"
> > for many lines of code I've written, but a monkey-wrench could easily
> > be thrown at it.
> > 
> > Does forcing the if(VARIABLE usage rather than the if("string" usage
> > make things work all the time? (Now I've thought about it too hard,
> > and I can't remember if this works all the time or not...)
> > 
> >      set(x "${var}")
> >      if(x STREQUAL "some string constant")
> 
> I think this would be the only way to be 100% safe. 

I think the right side also needs to be a variable, there might be a variable 
named "some string constant" (ok, usually there isn't).

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://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers

Reply via email to