There is a CMake script:
unset(FOO) list(APPEND FOO "") list(APPEND FOO "") list(APPEND FOO "") list(APPEND FOO "") list(LENGTH FOO SIZE) message(FATAL_ERROR ${SIZE}) Waiting - 4. Reality - 0.
I found a workaround, but it looks like a crutch:
set(FOO "dummy") set(FOO "${FOO};") set(FOO "${FOO};") set(FOO "${FOO};") set(FOO "${FOO};") list(REMOVE_AT FOO 0) message(FATAL_ERROR ${SIZE}) The example is somewhat simpler than what I actually do, so don’t suggest writing set(FOO ";;;") :) Elements come from outside in an unknown quantity, and only some of them are empty. Like this:
function(do_smth LIST_WITH_EMPTY_ITEMS) unset(RESULT) foreach(X IN LISTS LIST_WITH_EMPTY_ITEMS) if(${CONDITION}) list(APPEND RESULT "${X}") endif() endforeach() endfunction()
nth_items("1;2;3;4;5;6;7" 1 3 RESULT) #RESULT = 1;4;7. And I do not want to "swallow" empty elements - yrHeTaTeJlb