  We provide a framework for the numerical approximation of distributed optimal
control problems, based on least-squares finite element methods. Our proposed
method simultaneously solves the state and adjoint equations and is
$\inf$--$\sup$ stable for any choice of conforming discretization spaces. A
reliable and efficient a posteriori error estimator is derived for problems
where box constraints are imposed on the control. It can be localized and
therefore used to steer an adaptive algorithm. For unconstrained optimal
control problems, i.e., the set of controls being a Hilbert space, we obtain a
coercive least-squares method and, in particular, quasi-optimality for any
choice of discrete approximation space. For constrained problems we derive and
analyze a variational inequality where the PDE part is tackled by least-squares
finite element methods. We show that the abstract framework can be applied to a
wide range of problems, including scalar second-order PDEs, the Stokes problem,
and parabolic problems on space-time domains. Numerical examples for some
selected problems are presented.
