MantisBT - CMake
View Issue Details
0014177CMakeCMakepublic2013-05-28 16:042016-06-10 14:31
mwoehlke 
Kitware Robot 
normalfeaturealways
closedmoved 
CMake 2.8.10.2 
 
0014177: RFE: built-in to join list of strings
On at least two projects I have found myself writing a simple CMake macro/function to take a list of strings and concatenate them into one string with a narbitrary separator.

This seems like very basic functionality. Would you consider adding a built-in function for this? (Maybe as an additional sub-command to either STRING or LIST?)
No tags attached.
has duplicate 0014583closed Kitware Robot Add convenience function to convert list into a string with a chosen separator 
Issue History
2013-05-28 16:04mwoehlkeNew Issue
2013-05-28 16:49Brad KingNote Added: 0033147
2013-05-28 16:52Brad KingNote Added: 0033148
2013-05-28 16:52Brad KingStatusnew => resolved
2013-05-28 16:52Brad KingResolutionopen => suspended
2013-05-29 17:12mwoehlkeNote Added: 0033150
2013-05-29 17:12mwoehlkeStatusresolved => feedback
2013-05-29 17:12mwoehlkeResolutionsuspended => reopened
2013-05-29 17:17mwoehlkeNote Added: 0033151
2013-05-29 17:17mwoehlkeStatusfeedback => new
2013-05-30 08:03Brad KingStatusnew => backlog
2013-05-30 08:03Brad KingResolutionreopened => open
2013-11-19 12:33mwoehlkeRelationship addedhas duplicate 0014583
2016-06-10 14:28Kitware RobotNote Added: 0042291
2016-06-10 14:28Kitware RobotStatusbacklog => resolved
2016-06-10 14:28Kitware RobotResolutionopen => moved
2016-06-10 14:28Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0033147)
Brad King   
2013-05-28 16:49   
Since lists are ;-separated one can just do

 string(REPLACE ";" "${mysep}" concatenated "${list}")
(0033148)
Brad King   
2013-05-28 16:52   
This is better discussed on the mailing list first. Resolving as "suspended" for now.
(0033150)
mwoehlke   
2013-05-29 17:12   
Without some sort of non-trivial additional processing, string(REPLACE) mishandles items with (escaped) ';'s in them.

Consider:


set(items
  hello
  "the\;world"
  is on fire
)
string(REPLACE ";" " " replace_quoted "${items}")
message(STATUS "replace quoted: '${replace_quoted}'")
string(REPLACE ";" " " replace_list ${items})
message(STATUS "replace list: '${replace_list}'")

set(join_items)
foreach(item ${items})
  if(join_items)
    set(join_items "${join_items} ${item}")
  else()
    set(join_items "${item}")
  endif()
endforeach()
message(STATUS "join items: '${join_items}'")

set(join_list)
foreach(item IN LISTS items)
  if(join_list)
    set(join_list "${join_list} ${item}")
  else()
    set(join_list "${item}")
  endif()
endforeach()
message(STATUS "join list: '${join_list}'")


...both of the tries using string(REPLACE) give a result other than is desired (and different from each other, as well). The versions using foreach both give the desired result.
(0033151)
mwoehlke   
2013-05-29 17:17   
Actually, the other main reason I would like this is to do things like:

join(output ", "
  "item1"
  "item2"
  ...
)

...which is how I am using it in the most recent project.
(0042291)
Kitware Robot   
2016-06-10 14:28   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.