  The $\gamma$-ray emission of star-forming (SF) galaxies is attributed to
hadronic interactions of cosmic ray (CR) protons with the interstellar gas and
contributions from CR electrons via bremsstrahlung and inverse Compton (IC)
scattering. The relative importance of these processes in different galaxy
types is still unclear. We model these processes in three-dimensional
magneto-hydrodynamical (MHD) simulations of the formation of isolated galactic
discs using the moving-mesh code AREPO, including dynamically coupled CR
protons and adopting different CR transport models. We calculate steady-state
CR spectra and also account for the emergence of secondary electrons and
positrons. This allows us to produce detailed $\gamma$-ray maps, luminosities
and spectra of our simulated galaxies at different evolutionary stages. Our
simulations with anisotropic CR diffusion and a low CR injection efficiency at
supernovae (SNe, $\zeta_{\mathrm{SN}}=0.05$) can successfully reproduce the
observed far infrared (FIR)-$\gamma$-ray relation. Starburst galaxies are close
to the calorimetric limit, where CR protons lose most of their energy due to
hadronic interactions and hence, their $\gamma$-ray emission is dominated by
neutral pion decay. However, in low SF galaxies, the increasing diffusive
losses soften the CR proton spectra due to energy-dependent diffusion, and
likewise steepen the pionic $\gamma$-ray spectra. In turn, IC emission hardens
the total spectra and can contribute up to $\sim40$ per cent of the total
luminosity in low SF galaxies. Furthermore, in order to match the observed
$\gamma$-ray spectra of starburst galaxies, we require a weaker energy
dependence of the CR diffusion coefficient, $D\propto{E}^{0.3}$, in comparison
to Milky Way-like galaxies.
