The list() Command
Let's learn about the list() command in CMake.
We'll cover the following
This command provides basic operations on lists:
Reading
Searching
Modification
Ordering
Some modes will change the list (mutate the original value). Be sure to copy the original value if we'll need it later. Full details can be found in the online documentation.
Reading
The following modes are available:
list(LENGTH <list> <out>)
counts the elements in the<list>
variable and stores the result in the<out>
variable.list(GET <list> <index>... <out>)
copies the<list>
elements specified with the list of<index>
indexes to the<out>
variable.list(JOIN <list> <glue> <out>)
interleaves<list>
elements with the<glue>
delimiter and stores the resulting string in the<out>
variable.list(SUBLIST <list> <begin> <length> <out>)
works like theGET
mode, but operates on range instead of explicit indexes. If<length>
is-1
, elements from<begin>
index to the end of the list provided in the<list>
variable will be returned.
Searching
This mode simply finds the index of the <needle>
element in the <list>
variable and stores the result in the <out>
variable (or -1
if the element wasn't found):
Get hands-on with 1400+ tech skills courses.