[CMake] Double Substitution in IF Statement

Aaron_Wright at selinc.com Aaron_Wright at selinc.com
Wed Nov 18 12:54:31 EST 2009


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20091118/f1d2444d/attachment.htm>


More information about the CMake mailing list