[CMake] Explanation....

Rolf Eike Beer eike at sf-mail.de
Wed Apr 16 06:03:30 EDT 2014


Am 16.04.2014 11:39, schrieb Johannes Zarl:
> Hi,
> 
> On Monday, 14. April 2014, 19:23:19, Theodore Papadopoulo wrote:
>> > if ("${arg}" STREQUAL "TOTO") -> if ("TOTO" STREQUAL "TOTO") -> if
>> > (B STREQUAL B)
>> 
>> What I do not follow is why there is an implicit evaluation of "TOTO"
>> into "B" (in both this case or the next I explicitely asked for a
>> string containing the content of the variable ${arg}, if I had
>> intended the content of the variable which name is in ${arg} I would
>> have written ${${arg}}.
> 
> If it is any consolence to you, this is one of the most-hated 
> (anti-)features
> of cmake. The best you can do is to embrace this oddity (it's not going 
> to go
> away soon), and use a different idiom:
> 
> Instead of ``"${var}" STREQUAL "VALUE"'', write:
> 
> IF ( var MATCHES "^VALUE$" )

NOOOOO, please don't! I try hard to kill all those as it requires 
compiling a regular expression for a simple string match. Just change it 
to something that is no valid variable name, i.e. will never get 
expanded:

if (" ${arg}" STREQUAL " TOTO")

Eike


More information about the CMake mailing list