cmake_parse_arguments.cmake 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Copyright (C) 2007 MySQL AB, 2009 Sun Microsystems,Inc
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; version 2 of the License.
  6. #
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. # GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program; if not, write to the Free Software
  14. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  15. # Handy macro to parse macro arguments
  16. MACRO(MYSQL_PARSE_ARGUMENTS prefix arg_names option_names)
  17. SET(DEFAULT_ARGS)
  18. FOREACH(arg_name ${arg_names})
  19. SET(${prefix}_${arg_name})
  20. ENDFOREACH(arg_name)
  21. FOREACH(option ${option_names})
  22. SET(${prefix}_${option} FALSE)
  23. ENDFOREACH(option)
  24. SET(current_arg_name DEFAULT_ARGS)
  25. SET(current_arg_list)
  26. FOREACH(arg ${ARGN})
  27. SET(larg_names ${arg_names})
  28. LIST(FIND larg_names "${arg}" is_arg_name)
  29. IF (is_arg_name GREATER -1)
  30. SET(${prefix}_${current_arg_name} ${current_arg_list})
  31. SET(current_arg_name ${arg})
  32. SET(current_arg_list)
  33. ELSE (is_arg_name GREATER -1)
  34. SET(loption_names ${option_names})
  35. LIST(FIND loption_names "${arg}" is_option)
  36. IF (is_option GREATER -1)
  37. SET(${prefix}_${arg} TRUE)
  38. ELSE (is_option GREATER -1)
  39. SET(current_arg_list ${current_arg_list} ${arg})
  40. ENDIF (is_option GREATER -1)
  41. ENDIF (is_arg_name GREATER -1)
  42. ENDFOREACH(arg)
  43. SET(${prefix}_${current_arg_name} ${current_arg_list})
  44. ENDMACRO()