[CMake] set(a b); set(b c); if(a STREQUAL b OR a STREQUAL c) ...

Clark Wang dearvoid at gmail.com
Thu Sep 4 01:58:14 EDT 2014


On Thu, Sep 4, 2014 at 1:44 PM, Clark Wang <dearvoid at gmail.com> wrote:

> On Thu, Sep 4, 2014 at 1:36 PM, Chuck Atkins <chuck.atkins at kitware.com>
> wrote:
>
>> Hi Clark
>>
>> The expression inside the if statement has it's variables dereferenced
>> before evaluating and the non-variables are treated as constant
>> expressions.  In this case, a resolves to "b", b resolves to "c", and c is
>> not a variable so it's treated as the constant expression "c".  Thus
>>
>>
>> if(a STREQUAL b OR a STREQUAL c)
>>
>> gets evaluated as
>>
>> if( ("b" STREQUAL "c") OR ("b" STREQUAL "c") )
>>
>
> Thanks a lot. It's clear now. But is there a way to check if the value of
> the variable a equals to "b" or "c"?
>

Found
http://stackoverflow.com/questions/19982340/cmake-compare-to-empty-string-with-strequal-failed
which suggests to use if(a MATCHES "^b$").

-clark

>
> -clark
>
>>
>> which is clearly false.  Hope that helps.
>>
>>  - Chuck
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20140904/2f00fe46/attachment-0001.html>


More information about the CMake mailing list