In this paper we study the distributed optimal control for the CahnHilliard system. A general class of free energy potentials is allowed which, in particular, includes the double-obstacle potential. The latter potential yields an optimal control problem of a parabolic variational inequality which is of fourth order in space. We show the existence of optimal controls to approximating problems where the potential is replaced by a mollified version of its MoreauYosida approximation. Corresponding first-order optimality conditions for the mollified problems are given. For this purpose a new result on the continuous Fréchet differentiability of superposition operators with values in Sobolev spaces is established. Besides the convergence of optimal controls of the mollified problems to an optimal control of the original problem, we also derive first-order optimality conditions for the original problem by a limit process. The newly derived stationarity system corresponds to a function space version of C-stationarity.