list(SORT) removes backslashes from escaped semicolons in the output.
Consider the following snippet:
function(call_function)
cmake_parse_arguments(PARSE_ARGV 0 x "" "" "LIST")
# x_LIST is now a space separated list of three elements; the semi-colon was escaped.
message(STATUS "Input: \"${x_LIST}\".")
# Turn x_LIST into a list.
string(REGEX MATCHALL "[^ ]+" a_cmake_list "${x_LIST}")
# Prove that this worked; a_cmake_list has three elements.
foreach (element ${a_cmake_list})
message(STATUS "--> ${element}")
endforeach ()
# We can also confirm that with LENGTH.
list(LENGTH a_cmake_list number_of_elements)
message(STATUS "Number of elements in the list: ${number_of_elements}")
# Now show that list(SORT) is buggy:
list(SORT a_cmake_list)
list(LENGTH a_cmake_list number_of_elements)
message(STATUS "Number of elements after sorting: ${number_of_elements}")
endfunction()
set(element1 "D")
set(element2 "A")
set(element3 "C;B")
call_function(LIST "${element1}" "${element2}" "${element3}")
This outputs,
-- Input: "D;A;C\;B".
-- --> D
-- --> A
-- --> C;B
-- Number of elements in the list: 3
-- Number of elements after sorting: 4
And resorting the already sorted list changes it ;). It seems that the result is OK, but a backslash before a semicolon got lost somewhere.
Edited by Carlo Wood