Potential automorphy over CM fields and the Ramanujan conjecture