list.rst 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. list
  2. ----
  3. .. only:: html
  4. .. contents::
  5. List operations.
  6. The list subcommands ``APPEND``, ``INSERT``, ``FILTER``, ``REMOVE_AT``,
  7. ``REMOVE_ITEM``, ``REMOVE_DUPLICATES``, ``REVERSE`` and ``SORT`` may create
  8. new values for the list within the current CMake variable scope. Similar to
  9. the :command:`set` command, the LIST command creates new variable values in
  10. the current scope, even if the list itself is actually defined in a parent
  11. scope. To propagate the results of these operations upwards, use
  12. :command:`set` with ``PARENT_SCOPE``, :command:`set` with
  13. ``CACHE INTERNAL``, or some other means of value propagation.
  14. .. note::
  15. A list in cmake is a ``;`` separated group of strings. To create a
  16. list the set command can be used. For example, ``set(var a b c d e)``
  17. creates a list with ``a;b;c;d;e``, and ``set(var "a b c d e")`` creates a
  18. string or a list with one item in it. (Note macro arguments are not
  19. variables, and therefore cannot be used in LIST commands.)
  20. .. note::
  21. When specifying index values, if ``<element index>`` is 0 or greater, it
  22. is indexed from the beginning of the list, with 0 representing the
  23. first list element. If ``<element index>`` is -1 or lesser, it is indexed
  24. from the end of the list, with -1 representing the last list element.
  25. Be careful when counting with negative indices: they do not start from
  26. 0. -0 is equivalent to 0, the first list element.
  27. Capacity and Element access
  28. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  29. LENGTH
  30. """"""
  31. ::
  32. list(LENGTH <list> <output variable>)
  33. Returns the list's length.
  34. GET
  35. """
  36. ::
  37. list(GET <list> <element index> [<element index> ...] <output variable>)
  38. Returns the list of elements specified by indices from the list.
  39. Search
  40. ^^^^^^
  41. FIND
  42. """"
  43. ::
  44. list(FIND <list> <value> <output variable>)
  45. Returns the index of the element specified in the list or -1
  46. if it wasn't found.
  47. Modification
  48. ^^^^^^^^^^^^
  49. APPEND
  50. """"""
  51. ::
  52. list(APPEND <list> [<element> ...])
  53. Appends elements to the list.
  54. FILTER
  55. """"""
  56. ::
  57. list(FILTER <list> <INCLUDE|EXCLUDE> REGEX <regular_expression>)
  58. Includes or removes items from the list that match the mode's pattern.
  59. In ``REGEX`` mode, items will be matched against the given regular expression.
  60. For more information on regular expressions see also the
  61. :command:`string` command.
  62. INSERT
  63. """"""
  64. ::
  65. list(INSERT <list> <element_index> <element> [<element> ...])
  66. Inserts elements to the list to the specified location.
  67. REMOVE_ITEM
  68. """""""""""
  69. ::
  70. list(REMOVE_ITEM <list> <value> [<value> ...])
  71. Removes the given items from the list.
  72. REMOVE_AT
  73. """""""""
  74. ::
  75. list(REMOVE_AT <list> <index> [<index> ...])
  76. Removes items at given indices from the list.
  77. REMOVE_DUPLICATES
  78. """""""""""""""""
  79. ::
  80. list(REMOVE_DUPLICATES <list>)
  81. Removes duplicated items in the list.
  82. Sorting
  83. ^^^^^^^
  84. REVERSE
  85. """""""
  86. ::
  87. list(REVERSE <list>)
  88. Reverses the contents of the list in-place.
  89. SORT
  90. """"
  91. ::
  92. list(SORT <list>)
  93. Sorts the list in-place alphabetically.