Theory of frequency comb generation in cavity enhanced second harmonic generation