Best/Shortest way to join a list in CMake

前端 未结 4 490
温柔的废话
温柔的废话 2021-02-04 06:07

What is the best way to join a list in CMake into a string?

By joining I mean convert SET(somelist \"a\" \"b\" \"c\\;c\") to \"a:b:c;c\" where the glue string (\":\") i

4条回答
  •  盖世英雄少女心
    2021-02-04 06:18

    You can use the string REPLACE function:

    function(JOIN VALUES GLUE OUTPUT)
      string (REPLACE ";" "${GLUE}" _TMP_STR "${VALUES}")
      set (${OUTPUT} "${_TMP_STR}" PARENT_SCOPE)
    endfunction()
    
    #USAGE:
    SET(somelist a b c)
    JOIN("${somelist}" ":" output)
    MESSAGE("${output}") # will output "a:b:c"
    

提交回复
热议问题