Using a function to add items to a list

You pass the list name to the function, so you have to evaluate the variable THE_LIST to get your list:

function(appendToList THE_LIST)

    message("On entering appendToList, THE_LIST = ${${THE_LIST}}")
    list(APPEND ${THE_LIST} "item2")
    list(APPEND ${THE_LIST} "item3")
    
    set(${THE_LIST} "${${THE_LIST}}" PARENT_SCOPE)

endfunction()

And you can simplify the propagation of the result by using return(PROPAGATE) (require CMake 3.25 or upper).

function(appendToList THE_LIST)

    message("On entering appendToList, THE_LIST = ${${THE_LIST}}")
    list(APPEND ${THE_LIST} "item2")
    list(APPEND ${THE_LIST} "item3")
    
    return(PROPAGATE ${THE_LIST})

endfunction()