list.rst 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. JOIN
  40. """"
  41. ::
  42. list(JOIN <list> <glue> <output variable>)
  43. Returns a string joining all list's elements using the glue string.
  44. To join multiple strings, which are not part of a list, use ``JOIN`` operator
  45. from :command:`string` command.
  46. SUBLIST
  47. """""""
  48. ::
  49. list(SUBLIST <list> <begin> <length> <output variable>)
  50. Returns a sublist of the given list.
  51. If ``<length>`` is 0, an empty list will be returned.
  52. If ``<length>`` is -1 or the list is smaller than ``<begin>+<length>`` then
  53. the remaining elements of the list starting at ``<begin>`` will be returned.
  54. Search
  55. ^^^^^^
  56. FIND
  57. """"
  58. ::
  59. list(FIND <list> <value> <output variable>)
  60. Returns the index of the element specified in the list or -1
  61. if it wasn't found.
  62. Modification
  63. ^^^^^^^^^^^^
  64. APPEND
  65. """"""
  66. ::
  67. list(APPEND <list> [<element> ...])
  68. Appends elements to the list.
  69. FILTER
  70. """"""
  71. ::
  72. list(FILTER <list> <INCLUDE|EXCLUDE> REGEX <regular_expression>)
  73. Includes or removes items from the list that match the mode's pattern.
  74. In ``REGEX`` mode, items will be matched against the given regular expression.
  75. For more information on regular expressions see also the
  76. :command:`string` command.
  77. INSERT
  78. """"""
  79. ::
  80. list(INSERT <list> <element_index> <element> [<element> ...])
  81. Inserts elements to the list to the specified location.
  82. REMOVE_ITEM
  83. """""""""""
  84. ::
  85. list(REMOVE_ITEM <list> <value> [<value> ...])
  86. Removes the given items from the list.
  87. REMOVE_AT
  88. """""""""
  89. ::
  90. list(REMOVE_AT <list> <index> [<index> ...])
  91. Removes items at given indices from the list.
  92. REMOVE_DUPLICATES
  93. """""""""""""""""
  94. ::
  95. list(REMOVE_DUPLICATES <list>)
  96. Removes duplicated items in the list.
  97. TRANSFORM
  98. """""""""
  99. ::
  100. list(TRANSFORM <list> <ACTION> [<SELECTOR>]
  101. [OUTPUT_VARIABLE <output variable>])
  102. Transforms the list by applying an action to all or, by specifying a
  103. ``<SELECTOR>``, to the selected elements of the list, storing result in-place
  104. or in the specified output variable.
  105. .. note::
  106. ``TRANSFORM`` sub-command does not change the number of elements of the
  107. list. If a ``<SELECTOR>`` is specified, only some elements will be changed,
  108. the other ones will remain same as before the transformation.
  109. ``<ACTION>`` specify the action to apply to the elements of list.
  110. The actions have exactly the same semantics as sub-commands of
  111. :command:`string` command.
  112. The ``<ACTION>`` may be one of:
  113. ``APPEND``, ``PREPEND``: Append, prepend specified value to each element of
  114. the list. ::
  115. list(TRANSFORM <list> <APPEND|PREPEND> <value> ...)
  116. ``TOUPPER``, ``TOLOWER``: Convert each element of the list to upper, lower
  117. characters. ::
  118. list(TRANSFORM <list> <TOLOWER|TOUPPER> ...)
  119. ``STRIP``: Remove leading and trailing spaces from each element of the
  120. list. ::
  121. list(TRANSFORM <list> STRIP ...)
  122. ``GENEX_STRIP``: Strip any
  123. :manual:`generator expressions <cmake-generator-expressions(7)>` from each
  124. element of the list. ::
  125. list(TRANSFORM <list> GENEX_STRIP ...)
  126. ``REPLACE``: Match the regular expression as many times as possible and
  127. substitute the replacement expression for the match for each element
  128. of the list
  129. (Same semantic as ``REGEX REPLACE`` from :command:`string` command). ::
  130. list(TRANSFORM <list> REPLACE <regular_expression>
  131. <replace_expression> ...)
  132. ``<SELECTOR>`` select which elements of the list will be transformed. Only one
  133. type of selector can be specified at a time.
  134. The ``<SELECTOR>`` may be one of:
  135. ``AT``: Specify a list of indexes. ::
  136. list(TRANSFORM <list> <ACTION> AT <index> [<index> ...] ...)
  137. ``FOR``: Specify a range with, optionally, an increment used to iterate over
  138. the range. ::
  139. list(TRANSFORM <list> <ACTION> FOR <start> <stop> [<step>] ...)
  140. ``REGEX``: Specify a regular expression. Only elements matching the regular
  141. expression will be transformed. ::
  142. list(TRANSFORM <list> <ACTION> REGEX <regular_expression> ...)
  143. Sorting
  144. ^^^^^^^
  145. REVERSE
  146. """""""
  147. ::
  148. list(REVERSE <list>)
  149. Reverses the contents of the list in-place.
  150. SORT
  151. """"
  152. ::
  153. list(SORT <list>)
  154. Sorts the list in-place alphabetically.