Generalized Curie-Weiss model and quadratic pressure in ergodic theory