Quantum anomalous Hall effect in single-layer and bilayer graphene