  The measurement of the production of prompt D$^0$, D$^+$, D$^{*+}$, and
D$^+_s$ mesons in proton$-$lead (p$-$Pb) collisions at the centre-of-mass
energy per nucleon pair of $\sqrt{s_{\rm NN}}$ = 5.02 TeV, with an integrated
luminosity of $292\pm 11$ $\mu$b$^{-1}$, are reported. Differential production
cross sections are measured at mid-rapidity ($-0.96<y_{\rm cms}<0.04$) as a
function of transverse momentum ($p_{\rm T}$) in the intervals $0< p_{\rm T} <
36$ GeV/$c$ for D$^0$, $1< p_{\rm T} <36$ GeV/$c$ for D$^+$ and D$^{*+}$, and
$2< p_{\rm T} <24$ GeV/$c$ for D$^+_s$ mesons. For each species, the nuclear
modification factor $R_{\rm pPb}$ is calculated as a function of $p_{\rm T}$
using a proton-proton (pp) reference measured at the same collision energy. The
results are compatible with unity in the whole $p_{\rm T}$ range. The average
of the non-strange D mesons $R_{\rm pPb}$ is compared with theoretical model
predictions that include initial-state effects and parton transport model
predictions. The $p_{\rm T}$ dependence of the D$^0$, D$^+$, and D$^{*+}$
nuclear modification factors is also reported in the interval $1< p_{\rm T} <
36$ GeV/$c$ as a function of the collision centrality, and the
central-to-peripheral ratios are computed from the D-meson yields measured in
different centrality classes. The results are further compared with
charged-particle measurements and a similar trend is observed in all the
centrality classes. The ratios of the $p_{\rm T}$-differential cross sections
of D$^0$, D$^+$, D$^{*+}$, and D$^+_s$ mesons are also reported. The D$^+_s$
and D$^+$ yields are compared as a function of the charged-particle
multiplicity for several $p_{\rm T}$ intervals. No modification in the relative
abundances of the four species is observed with respect to pp collisions within
the statistical and systematic uncertainties.
