Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
MacroParseArguments.cmake
Go to the documentation of this file.
1 # macro(MACRO_PARSE_ARGUMENTS prefix arg_names option_names)
2 #
3 # From http://www.cmake.org/Wiki/CMakeMacroParseArguments:
4 #
5 # The MACRO_PARSE_ARGUMENTS macro will take the arguments of another macro and
6 # define several variables:
7 #
8 # 1) The first argument to is a prefix to put on all variables it creates.
9 # 2) The second argument is a quoted list of names,
10 # 3) and the third argument is a quoted list of options.
11 #
12 # The rest of MACRO_PARSE_ARGUMENTS are arguments from another macro to be
13 # parsed.
14 #
15 # MACRO_PARSE_ARGUMENTS(prefix arg_names options arg1 arg2...)
16 #
17 # For each item in options, MACRO_PARSE_ARGUMENTS will create a variable
18 # with that name, prefixed with prefix_. So, for example, if prefix is
19 # MY_MACRO and options is OPTION1;OPTION2, then PARSE_ARGUMENTS will create
20 # the variables MY_MACRO_OPTION1 and MY_MACRO_OPTION2. These variables will
21 # be set to true if the option exists in the command line or false otherwise.
22 #
23 # For each item in arg_names, MACRO_PARSE_ARGUMENTS will create a variable
24 # with that name, prefixed with prefix_. Each variable will be filled with the
25 # arguments that occur after the given arg_name is encountered up to the next
26 # arg_name or the end of the arguments. All options are removed from these
27 # lists.
28 #
29 # MACRO_PARSE_ARGUMENTS also creates a prefix_DEFAULT_ARGS variable containing
30 # the list of all arguments up to the first arg_name encountered.
31 
32 if(NOT COMMAND MACRO_PARSE_ARGUMENTS)
33 
34 macro(MACRO_PARSE_ARGUMENTS prefix arg_names option_names)
35 
36  message(WARNING "The MACRO_PARSE_ARGUMENTS macro is deprecated. Use cmake_parse_arguments instead.")
37 
38  set(DEFAULT_ARGS)
39 
40  foreach(arg_name ${arg_names})
41  set(${prefix}_${arg_name})
42  endforeach(arg_name)
43 
44  foreach(option ${option_names})
45  set(${prefix}_${option} FALSE)
46  endforeach(option)
47 
48  set(current_arg_name DEFAULT_ARGS)
49  set(current_arg_list)
50 
51  foreach(arg ${ARGN})
52 
53  set(larg_names ${arg_names})
54  list(FIND larg_names "${arg}" is_arg_name)
55 
56  if(is_arg_name GREATER -1)
57 
58  set(${prefix}_${current_arg_name} ${current_arg_list})
59  set(current_arg_name "${arg}")
60  set(current_arg_list)
61 
62  else(is_arg_name GREATER -1)
63 
64  set(loption_names ${option_names})
65  list(FIND loption_names "${arg}" is_option)
66 
67  if(is_option GREATER -1)
68  set(${prefix}_${arg} TRUE)
69  else(is_option GREATER -1)
70  set(current_arg_list ${current_arg_list} "${arg}")
71  endif(is_option GREATER -1)
72 
73  endif(is_arg_name GREATER -1)
74 
75  endforeach(arg ${ARGN})
76 
77  set(${prefix}_${current_arg_name} ${current_arg_list})
78 
79 endmacro(MACRO_PARSE_ARGUMENTS)
80 
81 endif(NOT COMMAND MACRO_PARSE_ARGUMENTS)
MACRO_PARSE_ARGUMENTS(prefix, arg_names, option_names)