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

2014-09-03 Thread Clark Wang
Hi, I don't understand why the following code would not print "true" (tested with cmake-3.0): set(a b) set(b c) if(a STREQUAL b OR a STREQUAL c) message("true") endif() >From my understanding, no matter how magic the if command interprets its arguments, one of the expressions (a STRE

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

2014-09-03 Thread Chuck Atkins
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 STRE

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

2014-09-03 Thread Clark Wang
On Thu, Sep 4, 2014 at 1:36 PM, Chuck Atkins 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

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

2014-09-03 Thread Clark Wang
On Thu, Sep 4, 2014 at 1:44 PM, Clark Wang wrote: > On Thu, Sep 4, 2014 at 1:36 PM, Chuck Atkins > 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

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

2014-09-03 Thread Chuck Atkins
> But is there a way to check if the value of the variable a equals to "b" or "c"? Directly: if(a STREQUAL "b" OR a STREQUAL "c") But its a bit clumsy. Better would be to match a regex: if(a MATCHES "^(b|c)$") -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ

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

2014-09-03 Thread Nils Gladitz
On 09/04/2014 08:00 AM, Chuck Atkins wrote: > But is there a way to check if the value of the variable a equals to "b" or "c"? Directly: if(a STREQUAL "b" OR a STREQUAL "c") b is dereferenced as a variable even if it is quoted. Nils -- Powered by www.kitware.com Please keep messages on-top

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

2014-09-04 Thread Ruslan Baratov via CMake
On 04-Sep-14 09:58, Clark Wang wrote: On Thu, Sep 4, 2014 at 1:44 PM, Clark Wang > wrote: On Thu, Sep 4, 2014 at 1:36 PM, Chuck Atkins mailto:chuck.atk...@kitware.com>> wrote: Hi Clark The expression inside the if statement has it's variables

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

2014-09-04 Thread Chuck Atkins
> Command `if(a MATCHES ...)` has the same flaw: `if( > MATCHES regex)`: > .. > set(MYSTRING "B") > set(A "MYSTRING") > if("${A}" MATCHES "^MYSTRING$") > # do *not* go here even A is MYSTRING (use *variable* MYSTRING) > endif() > This should work without dereferencing A, i.e.: if(A MATCHES "^M

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

2014-09-04 Thread Ruslan Baratov via CMake
On 04-Sep-14 16:48, Chuck Atkins wrote: Command `if(a MATCHES ...)` has the same flaw: `if( MATCHES regex)`: .. set(MYSTRING "B") set(A "MYSTRING") if("${A}" MATCHES "^MYSTRING$") # do *not* go here even A is MYSTRING (use *variable* MYSTRING) endif() This sho

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

2014-09-04 Thread Anders Lindgren
As other has pointed out, this is caused by "if" interpreting its arguments as variables, if there is a variable with that name, and quoting the value don't help. However, by embedded both argument in some extra text, you can make sure that the argument don't form a valid variable name. To apply t

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

2014-09-04 Thread Ruslan Baratov via CMake
On 04-Sep-14 18:09, Anders Lindgren wrote: make sure that the argument don't form a valid variable name. It's not possible set(a b) set(b c) if(">${a}<" STREQUAL ">b<" OR ">${a}<" STREQUAL ">c<") message("true") endif() How about that: set(a "") # variable `a` is empty

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

2014-09-04 Thread Hendrik Sattler
On 4. September 2014 16:38:21 MESZ, Ruslan Baratov via CMake wrote: >On 04-Sep-14 18:09, Anders Lindgren wrote: >> make sure that the argument don't form a valid variable name. >It's not possible > >> >> set(a b) >> set(b c) >> if(">${a}<" STREQUAL ">b<" OR ">${a}<" STREQUAL ">c<")

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

2014-09-05 Thread Ruslan Baratov via CMake
On 04-Sep-14 20:40, Hendrik Sattler wrote: On 4. September 2014 16:38:21 MESZ, Ruslan Baratov via CMake wrote: On 04-Sep-14 18:09, Anders Lindgren wrote: make sure that the argument don't form a valid variable name. It's not possible set(a b) set(b c) if(">${a}<" STREQUAL "