Cmake ARGV and Macro BUG?-Collection of common programming errors
In macros, ARGV1 etc. are not real CMake variables. Instead, ${ARGV1}
is the string replacement from the macro call. That means that your call with only one argument expands to
if( NOT false AND )
which explains the error message. By enclosing the string expansions in quotes, you now have
if( NOT "false" AND "")
giving the IF command an empty string to evaluate. Other solutions: use the ${ARGC} string replacement to decide whether the argument is present before trying to expand ARGV2. Or, as you’ve mentioned, switch to a function instead of a macro. In a function, ARGV1 is an actual CMake variable, and you can write it more sensibly, even without the ${} expansion at all:
function(foo in1)
message("Optional1: " ${ARGV1})
message("Optional2: " ${ARGV2})
if( NOT ARGV1 AND ARGV2 )
message("IF")
else()
message("ELSE")
endif()
endfunction()
Reference: http://www.cmake.org/cmake/help/v2.8.8/cmake.html#command:macro
Originally posted 2013-11-09 23:24:45.