def check_root_cmake_list(cmake_list_file):
    """ Check that the root CMakeLists is correct.

    * It should contain a cmake_minimum_required() line
    * It should contain a call to project()
    * If find_package(qibuild) is called, it should be
      called after project()

    """
    dirname = os.path.dirname(cmake_list_file)
    suggested_project_name = os.path.basename(dirname)
    message = ""
    lines = list()
    with open(cmake_list_file, "r") as fp:
        lines = fp.readlines()

    project_line_number = None
    find_qibuild_line_number = None
    minimum_required_found = False
    for (i, line) in enumerate(lines):
        if re.match(r'^\s*project\s*\(', line, re.IGNORECASE):
            project_line_number = i
        if re.match(r'^\s*find_package\s*\(.*qibuild\.*\)', line,
                    re.IGNORECASE):
            find_qibuild_line_number = i
        if re.match(r'^\s*cmake_minimum_required\(', line,
                    re.IGNORECASE):
            minimum_required_found = True

    if not minimum_required_found:
        message += """
* Missing call to cmake_minimum_required()
Add a line looking like:

cmake_minimum_required(VERSION 2.8)

At the top of the CMakeLists.txt file
"""

    if project_line_number is None:
        message += """
* Missing call to project().
Please fix this by editing the file so that it looks like

cmake_minimum_required(VERSION 2.8)
project({project_name})
find_package(qibuild)

""".format(
            project_name=suggested_project_name)

    if find_qibuild_line_number is not None and \
            project_line_number is not None and \
            project_line_number > find_qibuild_line_number:
        message += """
* The call to find_package(qibuild) should be AFTER the call to project()
"""
    if message:
        raise IncorrectCMakeLists(cmake_list_file, message)
dataset/ETHPy150Open aldebaran/qibuild/python/qibuild/cmake/__init__.py/check_root_cmake_list/original