list.rst 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. Search
  47. ^^^^^^
  48. FIND
  49. """"
  50. ::
  51. list(FIND <list> <value> <output variable>)
  52. Returns the index of the element specified in the list or -1
  53. if it wasn't found.
  54. Modification
  55. ^^^^^^^^^^^^
  56. APPEND
  57. """"""
  58. ::
  59. list(APPEND <list> [<element> ...])
  60. Appends elements to the list.
  61. FILTER
  62. """"""
  63. ::
  64. list(FILTER <list> <INCLUDE|EXCLUDE> REGEX <regular_expression>)
  65. Includes or removes items from the list that match the mode's pattern.
  66. In ``REGEX`` mode, items will be matched against the given regular expression.
  67. For more information on regular expressions see also the
  68. :command:`string` command.
  69. INSERT
  70. """"""
  71. ::
  72. list(INSERT <list> <element_index> <element> [<element> ...])
  73. Inserts elements to the list to the specified location.
  74. REMOVE_ITEM
  75. """""""""""
  76. ::
  77. list(REMOVE_ITEM <list> <value> [<value> ...])
  78. Removes the given items from the list.
  79. REMOVE_AT
  80. """""""""
  81. ::
  82. list(REMOVE_AT <list> <index> [<index> ...])
  83. Removes items at given indices from the list.
  84. REMOVE_DUPLICATES
  85. """""""""""""""""
  86. ::
  87. list(REMOVE_DUPLICATES <list>)
  88. Removes duplicated items in the list.
  89. Sorting
  90. ^^^^^^^
  91. REVERSE
  92. """""""
  93. ::
  94. list(REVERSE <list>)
  95. Reverses the contents of the list in-place.
  96. SORT
  97. """"
  98. ::
  99. list(SORT <list>)
  100. Sorts the list in-place alphabetically.