import re


def get_repo_cmake_info(names, file_path):
    """
    Function to find information about submodules from cpp/CMakeLists file

    Parameters
        ----------
        name : List of Strings
            List containing the names of the repos to be cloned. Must match
            the names of the cmake git clone instruction
            `ExternalProject_Add(name`
        file_path : String
            Relative path of the location of the CMakeLists.txt to extract the
            information.

    Returns
        -------
        results : dictionary
            Dictionary where results[name] contains an array,
            where results[name][0] is the url of the repo and
            repo_info[repo][1] is the tag/commit hash to be cloned as
            specified by cmake.

    """
    with open(file_path) as f:
        s = f.read()

    results = {}

    for name in names:
        res = re.findall(r'ExternalProject_Add\(' + re.escape(name)
                         + '\s.*GIT_REPOSITORY.*\s.*GIT_TAG.*',  # noqa: W605
                         s)

        res = re.sub(' +', ' ', res[0])
        res = res.split(' ')
        res = [res[2][:-1], res[4]]
        results[name] = res

    return results