macro(obtain _name)
    find_package(${_name} REQUIRED ${ARGN})
    message(STATUS "${_name}_DIR = ${${_name}_DIR}")
    add_to_registry(${_name} "${${_name}_DIR}")
endmacro()

macro(add_to_registry _module _path)
    set_property(GLOBAL PROPERTY module.path.${_module} "${_path}")
endmacro()

macro(import _module)
    if (${_module} MATCHES "(.+)::(.+)")
        get_property(_path GLOBAL PROPERTY module.path.${CMAKE_MATCH_1})
        if (NOT _path)
            obtain(${CMAKE_MATCH_1} ${ARGN})
            if (${CMAKE_MATCH_1}_FOUND)
                get_property(_path GLOBAL PROPERTY module.path.${CMAKE_MATCH_1})
            else()
                message(FATAL_ERROR "obtain(${CMAKE_MATCH_1}) failed.")
            endif()
        endif()
        include(${_path}/${CMAKE_MATCH_2}.cmake)
    else()
        message(FATAL_ERROR "Use package::module form for importing")
    endif()
endmacro()
