aheinecke@1: # Parse arguments passed to a function into several lists separated by
aheinecke@1: # upper-case identifiers and options that do not have an associated list e.g.:
aheinecke@1: #
aheinecke@1: # SET(arguments
aheinecke@1: #   hello OPTION3 world
aheinecke@1: #   LIST3 foo bar
aheinecke@1: #   OPTION2
aheinecke@1: #   LIST1 fuz baz
aheinecke@1: #   )
aheinecke@1: # PARSE_ARGUMENTS(ARG "LIST1;LIST2;LIST3" "OPTION1;OPTION2;OPTION3" ${arguments})
aheinecke@1: #
aheinecke@1: # results in 7 distinct variables:
aheinecke@1: #  * ARG_DEFAULT_ARGS: hello;world
aheinecke@1: #  * ARG_LIST1: fuz;baz
aheinecke@1: #  * ARG_LIST2:
aheinecke@1: #  * ARG_LIST3: foo;bar
aheinecke@1: #  * ARG_OPTION1: FALSE
aheinecke@1: #  * ARG_OPTION2: TRUE
aheinecke@1: #  * ARG_OPTION3: TRUE
aheinecke@1: #
aheinecke@1: # taken from http://www.cmake.org/Wiki/CMakeMacroParseArguments 
aheinecke@1: 
aheinecke@1: MACRO(PARSE_ARGUMENTS prefix arg_names option_names)
aheinecke@1:     SET(DEFAULT_ARGS)
aheinecke@1:     FOREACH(arg_name ${arg_names})    
aheinecke@1:         SET(${prefix}_${arg_name})
aheinecke@1:     ENDFOREACH(arg_name)
aheinecke@1:     FOREACH(option ${option_names})
aheinecke@1:         SET(${prefix}_${option} FALSE)
aheinecke@1:     ENDFOREACH(option)
aheinecke@1:     
aheinecke@1:     SET(current_arg_name DEFAULT_ARGS)
aheinecke@1:     SET(current_arg_list)
aheinecke@1:     FOREACH(arg ${ARGN})            
aheinecke@1:         SET(larg_names ${arg_names})    
aheinecke@1:         LIST(FIND larg_names "${arg}" is_arg_name)                   
aheinecke@1:         IF (is_arg_name GREATER -1)
aheinecke@1:             SET(${prefix}_${current_arg_name} ${current_arg_list})
aheinecke@1:             SET(current_arg_name ${arg})
aheinecke@1:             SET(current_arg_list)
aheinecke@1:         ELSE (is_arg_name GREATER -1)
aheinecke@1:             SET(loption_names ${option_names})    
aheinecke@1:             LIST(FIND loption_names "${arg}" is_option)            
aheinecke@1:             IF (is_option GREATER -1)
aheinecke@1:                 SET(${prefix}_${arg} TRUE)
aheinecke@1:             ELSE (is_option GREATER -1)
aheinecke@1:                 SET(current_arg_list ${current_arg_list} ${arg})
aheinecke@1:             ENDIF (is_option GREATER -1)
aheinecke@1:         ENDIF (is_arg_name GREATER -1)
aheinecke@1:     ENDFOREACH(arg)
aheinecke@1:     SET(${prefix}_${current_arg_name} ${current_arg_list})
aheinecke@1: ENDMACRO(PARSE_ARGUMENTS)