What is common way to split string into list with CMAKE?

Replace your separator by a ;. I don’t see any other way to do it.

cmake_minimum_required(VERSION 2.8)

set(SEXY_STRING "I love CMake")
string(REPLACE " " ";" SEXY_LIST ${SEXY_STRING})

message(STATUS "string = ${SEXY_STRING}")
# string = I love CMake

message(STATUS "list = ${SEXY_LIST}")
# list = I;love;CMake

list(LENGTH SEXY_LIST len)
message(STATUS "len = ${len}")
# len = 3

Leave a Comment