  We analyze superconductivity in the cuprates near the onset of an
incommensurate charge density wave (CDW) order with momentum ${\bf Q} =
(Q,0)/(0,Q)$, as observed in the experiments. We first consider a
semi-phenomenological charge-fermion model in which hot fermions, separated by
${\bf Q}$, attract each other by exchanging soft CDW fluctuations. We find that
in a quantum-critical region near CDW transition, $T_c = A {\bar g}_c$, where
${\bar g}_c$ is charge-fermion coupling and $A$ is the prefactor which we
explicitly compute. We then consider the particular microscopic scenario in
which CDW order parameter emerges as a composite field made out of primary
spin-density-wave fields. We show that charge-fermion coupling ${\bar g}_c$ is
of order of spin-fermion coupling ${\bar g}_s$. As the consequence,
superconducting $T_c$ is substantially enhanced near the onset of CDW order.
Finally we analyze the effect of an external magnetic field $H$. We show that,
as $H$ increases, optimal $T_c$ decreases and the superconducting dome becomes
progressively more confined to the CDW quantum-critical point. These results
are consistent with the experiments.
