A novel and flexible photonics-based scheme is proposed for generating phase-coded RF pulses suitable for coherent radar systems with pulse compression techniques. After selecting two modes from a mode-locked laser (MLL), the technique exploits an optical in-phase/quadrature modulator driven by a low-sample rate and low-noise direct digital synthesizer to modulate the phase of only one mode. The two laser modes are then heterodyned in a photodiode, and the RF pulse is properly filtered out. The scheme is experimentally validated implementing a 4-bit Barker code and a linear chirp on radar pulses with a carrier frequency of about 25 GHz, starting from an MLL at about 10 GHz. The measures of phase noise, amplitude- and phase-transients, and autocorrelation functions confirm the effectiveness of the scheme in producing compressed radar pulses without affecting the phase stability of the optically generated high-frequency carriers. An increase in the radar resolution from 150 to 37.5 m is calculated. The proposed scheme is capable of flexibly generating software-defined phase-modulated RF pulses with high stability, even at very high carrier frequency, using only a single commercial device with potentials for wideband modulation. It can therefore allow a new generation of high-resolution coherent radars with reduced complexity and cost.