list: Enabling lists with elements that contain semicolons
From my recent experimentation as part of https://github.com/TriBITSPub/TriBITS/pull/464, I think that three new CMake operations would be needed to make lists workable to preserve semi-colons inside of elements (and then passing around the names of lists instead of the elements in a list).
First, we need two new list()
operations:
list(APPEND_ELEMENT <list> <element>)
list(COPY <list-from> <list-to> [PARENT_SCOPE])
The new operation list(APPEND_ELEMENT ...)
adds a single element and preserves internal semi-colons ;
in the element <element>
. (The list(APPEND ...)
operation flattens out the input elements if they contain semi-colons ;
.)
The new operation list(COPY ...)
preserves the element boundaries with elements with internal semi-colons ,
and the PARENT_SCOPE
option allows intact lists to be copied from a function to its parent scope (or up directory scopes).
Also, you need version of cmake_parse_arguments(PARSE_LIST ... <listName>)
that takes a list variable name <listName>
instead of the list elements themselves. (I tried implementing a version of this myself but it was foiled because list(APPEND ...)
does not respect element boundaries for elements containing semi-colons ;
. And a native CMake implementation would be much faster.)
These additions preserve 100% backward compatibility and makes general-purpose lists (with elements containing semi-colons ;
) usable in the current CMake language. This enables idioms where most lists are passed to and from functions using the list names and it maintains the integrity of the list elements. With that and element forwarding techniques like cmake_parse_arguments(PARSE_ARGV 0 "" "" "")
and cmake_language()
, you would not need unfortunate workarounds like LIST_SEPERATOR
.