# Excerpted from: https://stackoverflow.com/questions/7787823/cmake-how-to-get-the-name-of-all-subdirectories-of-a-directory
macro(get_submodule_list result curdir)
    file(GLOB children RELATIVE ${curdir} ${curdir}/*)
    set(dirlist "")
    foreach(child ${children})
        if(IS_DIRECTORY ${curdir}/${child})
            list(APPEND dirlist ${child})
        endif()
    endforeach()
    set(${result} ${dirlist})
endmacro()

macro(add_submodules_in_directory dirname)
    get_submodule_list(SUBMODULEDIRS ${CMAKE_CURRENT_SOURCE_DIR}/${dirname})
    foreach(subdir ${SUBMODULEDIRS})
        add_subdirectory(submodules/${subdir})
    endforeach()
endmacro()
