By default, CMake outputs lists without delimiters, eg
set(my_list a b c d)
message(${my_list})
Outputs
abcd
How can you (easily) make CMake output something like what is actually stored?
a;b;c;d
(A typical use case is for outputting a list of search paths)
Enclose the dereferenced variable in quotes.
set(my_list a b c d) message("${my_list}")
Outputs
a;b;c;d
You could write a function to join the items of a list together with a delimiter, and then print that out instead. For example, such a function:
function (ListToString result delim) list(GET ARGV 2 temp) math(EXPR N "${ARGC}-1") foreach(IDX RANGE 3 ${N}) list(GET ARGV ${IDX} STR) set(temp "${temp}${delim}${STR}") endforeach() set(${result} "${temp}" PARENT_SCOPE) endfunction(ListToString)
Then, you could use it like so:
set(my_list a b c d) ListToString(str ", " ${my_list}) message(STATUS "${str}")
Which outputs:
a, b, c, d
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With