def _add_comp_def(doc, comp_def):
    """Add the component definition while checking if it already existss

    :param doc: The SBOL Document object
    :param comp_def: Component definition
    
    :type doc: Document
    :type comp_def: ComponentDefinition
    
    :rtype: ComponentDefinition
    :return: The updated component definition
    """
    if comp_def.identity not in [comp_def.identity
                                 for comp_def in doc.componentDefinitions]:
        doc.addComponentDefinition(comp_def)
    else:
        comp_def = doc.getComponentDefinition(comp_def.identity)

    return comp_def