def build_target_list(targets, target_ids, target_file):
    """
    Build a list of the targets to be processed.

    Parameters
    ----------
    targets: str[]
        List of the component names of possible targets.
    target_ids: int[]
        List of the numerical ids of the subset of targets to be processed.
    target_file: str
        Name of the file listing the comonent names of the subset of targets to be processed.
    
    Returns
    -------
    List of the numerical ids of the subset of targets to be processed.
    """
    if target_ids:
        return target_ids
    if not target_file:
        return None

    target_list = []
    with open(target_file, 'r') as tgt_file:
        for line in tgt_file:
            comp_name = line.strip()
            if len(comp_name) == 0 or comp_name.startswith('#'):
                continue
            found = False
            for idx, tgt in enumerate(targets):
                if tgt == comp_name:
                    target_list.append(idx+1)
                    found = True
                    continue
            if not found:
                print ("Source {} is not known. Ignoring.".format(comp_name))
    
    # Make sure we don't run everything if a list was supplied but nothing is found
    if len(target_list) == 0:
        msg = 'ERROR: None of the targets listed in {} were found.'.format(target_file)
        print (msg)
        raise Exception(msg)
    
    return target_list