[CMake] Strange problem with parsing variables

wedekind wedekind at caesar.de
Fri Jan 26 11:02:31 EST 2007


Hello all,

I've encountered a strange parsing problem with a 2-month old checkout from
CMake's cvs repository. Please have a look at the following sample
CMakeLists.txt:

SET(SOME_VAR 1)

IF(SOME_VAR)
   MESSAGE("SOME_VAR is set to true")
ENDIF(SOME_VAR)

IF(NOT SOME_VAR)
   SET(SOME_OTHER_VAR some_value)
   MESSAGE("SOME_VAR set to false")
   IF(some_value STREQUAL ${SOME_OTHER_VAR})
      MESSAGE("SOME_OTHER_VAR is set to some_value")
   ENDIF(some_value STREQUAL ${SOME_OTHER_VAR})
ENDIF(NOT SOME_VAR)

When running cmake on it, cmake throws an error like this:

CMakeLists.txt:10:
IF had incorrect arguments: some_value STREQUAL ${SOME_OTHER_VAR} (Unknown
arguments specified).

I guess, what happens is, that cmake does not know about any variables
defined in the second IF (IF(NOT SOME_VAR)...), i.e. SOME_OTHER_VAR is not
known to cmake's parser. But it complains about this "missing" variable
because it is used in another IF-statement (IF(some_value STREQUAL
${SOME_OTHER_VAR})...). This is strange, because cmake does not need to
parse the content of the second IF, if SOME_VAR is set to "1". Or it should
parse the variables too.

If you define SOME_OTHER_VAR outside of the second IF, everything works
fine:

SET(SOME_VAR 1)

IF(SOME_VAR)
   MESSAGE("SOME_VAR is set to true")
ENDIF(SOME_VAR)

SET(SOME_OTHER_VAR some_value)

IF(NOT SOME_VAR)
   MESSAGE("SOME_VAR set to false")
   IF(some_value STREQUAL ${SOME_OTHER_VAR})
      MESSAGE("SOME_OTHER_VAR is set to some_value")
   ENDIF(some_value STREQUAL ${SOME_OTHER_VAR})
ENDIF(NOT SOME_VAR)

It also works, if you put the content of the second IF-statement into a
separate file, which is included in the second if:

SET(SOME_VAR 1)

IF(SOME_VAR)
   MESSAGE("SOME_VAR is set to true")
ENDIF(SOME_VAR)

IF(NOT SOME_VAR)
   INCLUDE(include.cmake)
ENDIF(NOT SOME_VAR)

include.cmake is:

SET(SOME_OTHER_VAR some_value)
MESSAGE("SOME_VAR set to false")
IF(some_value STREQUAL ${SOME_OTHER_VAR})
   MESSAGE("SOME_OTHER_VAR is set to some_value")
ENDIF(some_value STREQUAL ${SOME_OTHER_VAR})

Why does cmake work this way?

Cheers

Marco




More information about the CMake mailing list