[CMake] STREQUAL not functioning?

Michael Hertling mhertling at online.de
Thu Oct 6 18:25:22 EDT 2011


On 10/06/2011 08:51 PM, Robert Dailey wrote:
> Well there you go, deleting the cache & reconfiguring fixed it. That was
> weird.
> 
> Thanks for the help!

FYI, the attached CMakeLists.txt examines a variable's value in 5 cases:

NONEXIST: No value in current scope or in cache.
SCOPEONLY: Value in current scope, no value in cache.
CACHEONLY: No value in current scope, value in cache.
BOTHEQUAL: The same value in current scope and cache.
BOTHUNEQUAL: Different values in current scope and cache.

The findings are:

NOT STREQUAL, NONEXIST[SCOPE]=, NONEXIST[CACHE]=
STREQUAL, SCOPEONLY[SCOPE]=xyz, SCOPEONLY[CACHE]=
STREQUAL, CACHEONLY[SCOPE]=xyz, CACHEONLY[CACHE]=xyz
STREQUAL, BOTHEQUAL[SCOPE]=xyz, BOTHEQUAL[CACHE]=xyz
STREQUAL, BOTHUNEQUAL[SCOPE]=xyz, BOTHUNEQUAL[CACHE]=abc

AFAICS, this is exactly what one would expect, i.e. STREQUAL refers to
the variable's value in the current scope and uses the cached value as
fallback - in CACHEONLY - if the variable has no current-scope value.

This is with CMake 2.8.6; do you gain different results?

Regards,

Michael

> On Thu, Oct 6, 2011 at 1:50 PM, Robert Dailey <rcdailey at gmail.com> wrote:
> 
>> Ok interesting, it is working for me too. I guess my reproducible use case
>> was invalid.
>>
>> (BTW, I'm running through cmake-gui on Windows 7 x64 using CMake version
>> 2.8.5)
>>
>> My use case was a simplified version of the real code. FUBARTEST is
>> actually a cache variable defined by the root CMakeLists.txt file. In my
>> real test case, my STREQUAL statement is failing to execute the conditional
>> code when I do this:
>>
>> if( NEMO_TARGET STREQUAL "NSPR" )
>>
>> However if I do this, it works:
>>
>> if( "${NEMO_TARGET}" STREQUAL "NSPR" )
>>
>> I don't know why both would behave differently. Just to rule out the cache
>> variable being the issue, I tried this (I attempted to make the SET() call
>> override the originally defined cache variable. I did not actually remove
>> the variable from cache):
>>
>> set( NEMO_TARGET "NSPR" )
>> if( NEMO_TARGET STREQUAL "NSPR" )
>>
>> Of course, this statement did not result in the enclosed message() being
>> executed.
>>
>> I have tried creating a small test case to reproduce this issue but so far
>> I have been unsuccessful. I'll try clearing my cache to rule out any issues
>> there. In the meantime if you have any suspicions or have run into this
>> before, please give me some ideas on how to solve this :)
>>
>> Thanks.
>>
>> ---------
>> Robert Dailey
>>
>>
>>
>> On Thu, Oct 6, 2011 at 1:31 PM, Eric Noulard <eric.noulard at gmail.com>wrote:
>>
>>> 2011/10/6 Robert Dailey <rcdailey at gmail.com>:
>>>> According to the CMake documentation, the `STREQUAL` comparison is
>>> allowed
>>>> to take either a VARIABLE or a STRING as either parameter. So, in this
>>>> example below, the message does NOT print, which is broken:
>>>>     set( FUBARTEST "OK" )
>>>>     if( FUBARTEST STREQUAL "OK" )
>>>>     message( "It Worked" )
>>>>     endif()
>>>> Any reason why this isn't working as documented?
>>>
>>> Don't know but it works just fine for on Linux + CMake 2.8.6
>>> which cmake version are you using?
>>>
>>> Could you try running
>>> cmake --trace --debug-output -P  fubartest.cmake
>>>
>>> and tell us waht's printed out?
>>>
>>>
>>>
>>> --
>>> Erk
>>> Membre de l'April - « promouvoir et défendre le logiciel libre » -
>>> http://www.april.org
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: CMakeLists.txt
URL: <http://www.cmake.org/pipermail/cmake/attachments/20111007/951462ca/attachment.txt>


More information about the CMake mailing list