/share/cmake/ParseArguments.cmake

http://github.com/imageworks/OpenColorIO · CMake · 57 lines · 30 code · 2 blank · 25 comment · 0 complexity · f4c30ba38a1b7293c0490dab996ec2b6 MD5 · raw file

  1. #-------------------------------------------------------------------------------
  2. # The PARSE_ARGUMENTS macro will take the arguments of another macro and define
  3. # several variables. The first argument to PARSE_ARGUMENTS is a prefix to put
  4. # on all variables it creates. The second argument is a list of names, and the
  5. # third argument is a list of options. Both of these lists should be quoted.
  6. # The rest of the PARSE_ARGUMENTS args are arguments from another macro to be
  7. # parsed.
  8. #
  9. # PARSE_ARGUMENTS(prefix arg_names options arg1 arg2...)
  10. #
  11. # For each item in options, PARSE_ARGUMENTS will create a variable with that
  12. # name, prefixed with prefix_. So, for example, if prefix is MY_MACRO and
  13. # options is OPTION1;OPTION2, then PARSE_ARGUMENTS will create the variables
  14. # MY_MACRO_OPTION1 and MY_MACRO_OPTION2. These variables will be set to true if
  15. # the option exists in the command line or false otherwise.
  16. #
  17. # For each item in arg_names, PARSE_ARGUMENTS will create a variable with that
  18. # name, prefixed with prefix_. Each variable will be filled with the arguments
  19. # that occur after the given arg_name is encountered up to the next arg_name or
  20. # the end of the arguments. All options are removed from these lists.
  21. # PARSE_ARGUMENTS also creates a prefix_DEFAULT_ARGS variable containing the
  22. # list of all arguments up to the first arg_name encountered.
  23. #
  24. # Downloaded from: http://www.itk.org/Wiki/CMakeMacroParseArguments
  25. #
  26. cmake_minimum_required(VERSION 2.4.7)
  27. MACRO(PARSE_ARGUMENTS prefix arg_names option_names)
  28. SET(DEFAULT_ARGS)
  29. FOREACH(arg_name ${arg_names})
  30. SET(${prefix}_${arg_name})
  31. ENDFOREACH(arg_name)
  32. FOREACH(option ${option_names})
  33. SET(${prefix}_${option} FALSE)
  34. ENDFOREACH(option)
  35. SET(current_arg_name DEFAULT_ARGS)
  36. SET(current_arg_list)
  37. FOREACH(arg ${ARGN})
  38. SET(larg_names ${arg_names})
  39. LIST(FIND larg_names "${arg}" is_arg_name)
  40. IF (is_arg_name GREATER -1)
  41. SET(${prefix}_${current_arg_name} ${current_arg_list})
  42. SET(current_arg_name ${arg})
  43. SET(current_arg_list)
  44. ELSE (is_arg_name GREATER -1)
  45. SET(loption_names ${option_names})
  46. LIST(FIND loption_names "${arg}" is_option)
  47. IF (is_option GREATER -1)
  48. SET(${prefix}_${arg} TRUE)
  49. ELSE (is_option GREATER -1)
  50. SET(current_arg_list ${current_arg_list} ${arg})
  51. ENDIF (is_option GREATER -1)
  52. ENDIF (is_arg_name GREATER -1)
  53. ENDFOREACH(arg)
  54. SET(${prefix}_${current_arg_name} ${current_arg_list})
  55. ENDMACRO(PARSE_ARGUMENTS)