comparing variable contents

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

comparing variable contents

Steven Wilson-2
Is there a way to compare the contents of one variable with another?   I'm looking for something like:

if(${FOO} EQUAL ${BAR})

Thanks,

Steve

_______________________________________________
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 | Threaded
Open this post in threaded view
|

Re: comparing variable contents

Tyler Roscoe
On Tue, Sep 29, 2009 at 10:56:45AM -0600, Steven Wilson wrote:
> Is there a way to compare the contents of one variable with another?   I'm
> looking for something like:
> if(${FOO} EQUAL ${BAR})

Did you read the docs for the if() command?

cmake --help-command if


tyler
_______________________________________________
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 | Threaded
Open this post in threaded view
|

Re: comparing variable contents

Steven Wilson-2
Of course I read the docs for the if() command.   It doesn't contain any comments about comparing a variable's value to another variable's value.   Are you suggesting that if it isn't in the documentation then it isn't supported?   If so, please say so.   I was just hoping someone might know a way to do this kind of test/comparison.



On Tue, Sep 29, 2009 at 11:08 AM, Tyler Roscoe <[hidden email]> wrote:
On Tue, Sep 29, 2009 at 10:56:45AM -0600, Steven Wilson wrote:
> Is there a way to compare the contents of one variable with another?   I'm
> looking for something like:
> if(${FOO} EQUAL ${BAR})

Did you read the docs for the if() command?

cmake --help-command if


tyler


_______________________________________________
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 | Threaded
Open this post in threaded view
|

Re: comparing variable contents

Alexander Neundorf-3
On Tuesday 29 September 2009, Steven Wilson wrote:

> Of course I read the docs for the if() command.   It doesn't contain any
> comments about comparing a variable's value to another variable's value.
> Are you suggesting that if it isn't in the documentation then it isn't
> supported?   If so, please say so.   I was just hoping someone might know a
> way to do this kind of test/comparison.
>
> On Tue, Sep 29, 2009 at 11:08 AM, Tyler Roscoe <[hidden email]> wrote:
> > On Tue, Sep 29, 2009 at 10:56:45AM -0600, Steven Wilson wrote:
> > > Is there a way to compare the contents of one variable with another?
> >
> > I'm
> >
> > > looking for something like:
> > > if(${FOO} EQUAL ${BAR})

if(${FOO} STREQUAL ${BAR})

(to be completely sure do
if("${FOO}" STREQUAL "${BAR}")
)

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 | Threaded
Open this post in threaded view
|

Re: comparing variable contents

Nathaniel Waisbrot (Cont ARL/CISD)
In reply to this post by Steven Wilson-2
> Of course I read the docs for the if() command.   It doesn't contain
> any comments about comparing a variable's value to another variable's
> value.   Are you suggesting that if it isn't in the documentation then
> it isn't supported?   If so, please say so.   I was just hoping
> someone might know a way to do this kind of test/comparison.



Maybe the information that you're missing is that all CMake variables
are stored internally as strings.  So paths, lists, numbers, etc can be
compared with STREQUAL.


_______________________________________________
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 | Threaded
Open this post in threaded view
|

Re: comparing variable contents

Steven Wilson-2
Thanks all, I was missing the quotes around the initial ${FOO} in my tests...

if("${FOO}" STREQUAL "${BAR}") 

does what I wanted.

On Tue, Sep 29, 2009 at 1:51 PM, Nathaniel Waisbrot (Cont ARL/CISD) <[hidden email]> wrote:
> Of course I read the docs for the if() command.   It doesn't contain
> any comments about comparing a variable's value to another variable's
> value.   Are you suggesting that if it isn't in the documentation then
> it isn't supported?   If so, please say so.   I was just hoping
> someone might know a way to do this kind of test/comparison.



Maybe the information that you're missing is that all CMake variables
are stored internally as strings.  So paths, lists, numbers, etc can be
compared with STREQUAL.




_______________________________________________
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