# from <http://www.itk.org/Wiki/CMakeMacroParseArguments>
MACRO(PARSE_ARGUMENTS prefix arg_names option_names)
  SET(DEFAULT_ARGS)
  FOREACH(arg_name ${arg_names})
    SET(${prefix}_${arg_name})
  ENDFOREACH(arg_name)
  FOREACH(option ${option_names})
    SET(${prefix}_${option} FALSE)
  ENDFOREACH(option)

  SET(current_arg_name DEFAULT_ARGS)
  SET(current_arg_list)
  FOREACH(arg ${ARGN})
    LIST_CONTAINS(is_arg_name ${arg} ${arg_names})
    IF (is_arg_name)
      SET(${prefix}_${current_arg_name} ${current_arg_list})
      SET(current_arg_name ${arg})
      SET(current_arg_list)
    ELSE (is_arg_name)
      LIST_CONTAINS(is_option ${arg} ${option_names})
      IF (is_option)
	SET(${prefix}_${arg} TRUE)
      ELSE (is_option)
	SET(current_arg_list ${current_arg_list} ${arg})
      ENDIF (is_option)
    ENDIF (is_arg_name)
  ENDFOREACH(arg)
  SET(${prefix}_${current_arg_name} ${current_arg_list})
ENDMACRO(PARSE_ARGUMENTS)

function(LIST_CONTAINS var value)
  #SET(${var})
  #FOREACH (value2 ${ARGN})
    #IF (${value} STREQUAL ${value2})
      #SET(${var} TRUE)
    #ENDIF (${value} STREQUAL ${value2})
  #ENDFOREACH (value2)
  set(LS ${ARGN})
  list(FIND LS ${value} ${var})
  if(${var} EQUAL -1)
      set(${var} FALSE PARENT_SCOPE)
  else()
      set(${var} TRUE PARENT_SCOPE)
  endif()
endfunction(LIST_CONTAINS)

MACRO(CAR var)
  SET(${var} ${ARGV1})
ENDMACRO(CAR)

MACRO(CDR var junk)
  SET(${var} ${ARGN})
ENDMACRO(CDR)
