The aim of this paper is to study problems of the form: $inf_{(u\in V)}J(u)$ with $J(u):=\int_0^1 L(s,y_u(s),u(s)){\rm d}s+g(y_u(1))$ where V is a set of admissible controls and y u is the solution of the Cauchy problem: $\dot{x}(t) =\langle f(.,x(.)), \nu_t \rangle + u(t), t \in (0,1)$ , $x(0) = x_{\rm 0}$ and each $\nu_t$ is a nonnegative measure with support in [0,t]. After studying the Cauchy problem, we establish existence of minimizers, optimality conditions (in particular in the form of a nonlocal version of the Pontryagin principle) and prove some regularity results. We also consider the more general case where the control also enters the dynamics in a nonlocal way.