list.rst 2.3 KB

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