list.rst 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. Sorting
  98. ^^^^^^^
  99. REVERSE
  100. """""""
  101. ::
  102. list(REVERSE <list>)
  103. Reverses the contents of the list in-place.
  104. SORT
  105. """"
  106. ::
  107. list(SORT <list>)
  108. Sorts the list in-place alphabetically.