list.rst 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. list
  2. ----
  3. List operations.
  4. ::
  5. list(LENGTH <list> <output variable>)
  6. list(GET <list> <element index> [<element index> ...]
  7. <output variable>)
  8. list(APPEND <list> [<element> ...])
  9. list(FILTER <list> <INCLUDE|EXCLUDE> REGEX <regular_expression>)
  10. list(FIND <list> <value> <output variable>)
  11. list(INSERT <list> <element_index> <element> [<element> ...])
  12. list(REMOVE_ITEM <list> <value> [<value> ...])
  13. list(REMOVE_AT <list> <index> [<index> ...])
  14. list(REMOVE_DUPLICATES <list>)
  15. list(REVERSE <list>)
  16. list(SORT <list>)
  17. ``LENGTH`` will return a given list's length.
  18. ``GET`` will return list of elements specified by indices from the list.
  19. ``APPEND`` will append elements to the list.
  20. ``FILTER`` will include or remove items from the list that match the
  21. mode's pattern.
  22. In ``REGEX`` mode, items will be matched against the given regular expression.
  23. For more information on regular expressions see also the :command:`string`
  24. command.
  25. ``FIND`` will return the index of the element specified in the list or -1
  26. if it wasn't found.
  27. ``INSERT`` will insert elements to the list to the specified location.
  28. ``REMOVE_AT`` and ``REMOVE_ITEM`` will remove items from the list. The
  29. difference is that ``REMOVE_ITEM`` will remove the given items, while
  30. ``REMOVE_AT`` will remove the items at the given indices.
  31. ``REMOVE_DUPLICATES`` will remove duplicated items in the list.
  32. ``REVERSE`` reverses the contents of the list in-place.
  33. ``SORT`` sorts the list in-place alphabetically.
  34. The list subcommands ``APPEND``, ``INSERT``, ``FILTER``, ``REMOVE_AT``,
  35. ``REMOVE_ITEM``, ``REMOVE_DUPLICATES``, ``REVERSE`` and ``SORT`` may create new
  36. values for the list within the current CMake variable scope. Similar to the
  37. :command:`set` command, the LIST command creates new variable values in the
  38. current scope, even if the list itself is actually defined in a parent
  39. scope. To propagate the results of these operations upwards, use
  40. :command:`set` with ``PARENT_SCOPE``, :command:`set` with
  41. ``CACHE INTERNAL``, or some other means of value propagation.
  42. NOTES: A list in cmake is a ``;`` separated group of strings. To create a
  43. list the set command can be used. For example, ``set(var a b c d e)``
  44. creates a list with ``a;b;c;d;e``, and ``set(var "a b c d e")`` creates a
  45. string or a list with one item in it. (Note macro arguments are not
  46. variables, and therefore cannot be used in LIST commands.)
  47. When specifying index values, if ``<element index>`` is 0 or greater, it
  48. is indexed from the beginning of the list, with 0 representing the
  49. first list element. If ``<element index>`` is -1 or lesser, it is indexed
  50. from the end of the list, with -1 representing the last list element.
  51. Be careful when counting with negative indices: they do not start from
  52. 0. -0 is equivalent to 0, the first list element.