[CMake] Double Substitution in IF Statement

Michael Wild themiwi at gmail.com
Thu Nov 19 04:34:30 EST 2009


No, it should be empty because he wants to test whether HELLO is in  
LIBS. But inside the IF statement, the ${VALUE} that evaluates to LIB  
(a member of LIBS) gets then expanded again to HELLO.

Quite funny actually. However, reading the manpage closely only the  
left-hand value of STREQUAL gets expanded, so reversing the statement  
solves the problem.


Michael

On 19. Nov, 2009, at 9:40 , Marcel Loose wrote:

> Hi Aaron,
>
> If I run your script (using CMake 2.6.2) I get
>
> -- CONTAINS_LIB = TRUE
>
> as output. Isn't that what you expected? If not, then I'm missing the
> point of your macro LIST_CONTAINS. What version of CMake are you  
> using?
>
> Best regards,
> Marcel Loose.
>
> On Wed, 2009-11-18 at 09:54 -0800, Aaron_Wright at selinc.com wrote:
>> I have a little question about how to prevent double substitution in
>> an IF statement.
>>
>> Consider this macro that looks through a list for a string, and  
>> sets a
>> variable to TRUE if it is found. The problem I have is that the IF
>> statement substitutes ${VALUE2} with LIB, and then substitutes LIB
>> with HELLO, and finds what it's looking for, even though it wasn't
>> really there. I want it to stop at the first substitution to prevent
>> this weird behavior. Ideas?
>>
>> MACRO(LIST_CONTAINS VAR VALUE)
>>        SET(${VAR})
>>
>>        FOREACH(VALUE2 ${ARGN})
>>                IF(${VALUE} STREQUAL ${VALUE2})
>>                        SET(${VAR} TRUE)
>>                ENDIF()
>>        ENDFOREACH()
>> ENDMACRO()
>>
>> SET(LIB HELLO)
>> SET(LIBS LIB IS GREAT)
>>
>> LIST_CONTAINS(CONTAINS_LIB ${LIB} ${LIBS})
>>
>> MESSAGE(STATUS "CONTAINS_LIB = ${CONTAINS_LIB}")
>> ---------------------------------------------------------
>> Aaron Wright
>> Software Engineer - DCS Group
>> Schweitzer Engineering Laboratories, Inc.
>> Pullman, WA 99163
>> 509-334-8087
>> _______________________________________________
>> 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
>
> _______________________________________________
> 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



More information about the CMake mailing list