CMake List of all Project Targets

Does CMake not support recursive functions?

I have something like

function(getAllSubdirs dir dirs)
    message("called with dir (${dir}) and dirs (${dirs})")
    set(_dirs "")
    # get subdirectories for dir
    get_property(subdirs DIRECTORY ${dir} PROPERTY SUBDIRECTORIES)
    # iterate any found subdirectories
    foreach(subdir ${subdirs})
        # append each sub directory
        list(APPEND _dirs ${subdir})
        set(${dirs} _dirs PARENT_SCOPE)
        getAllSubdirs(${subdir} ${_dirs})
    endforeach()
endfunction()

set(dirs ".")
getAllSubDirs(. ${dirs})
message("all dirs " ${dirs})

It seems like any recursive calls to getAllSubdirs doesn’t actually pass the updated _dirs to that function…