The integral in the question is an acceptable definition; when we write,
$$I = \int dm \, r^2$$
we mean here that $r$ is the distance a point of the object is from the axis of rotation, as a function of mass. An equivalent definition of $I$ would be,
$$I = \int_V dV \, \rho \, r^2$$
where again $r$ is the distance from the axis, but this time as a function of the position of the point.
Illustrative Example
Consider a rod of infinitesimal thickness and length $\ell$ in the $xy$-plane, say, resting on the $x$ axis from the origin to $x= \ell$, and we are rotating it about the $z$-axis. Then, the mass of a point a distance $x$ from the origin will be, $m(x) = \lambda x$, where $\lambda$ is the linear density. Inverting this means,
$$r^2_{\mathrm{axis}} = \frac{m^2}{\lambda^2}$$
and using the first definition of $I$, by integrating over all masses, we have,
$$I = \int_0^{\lambda \ell} dm \, \frac{m^2}{\lambda^2} = \frac{1}{3}\lambda \ell^3 = \frac{1}{3}M\ell^2$$
where $M = \lambda \ell$ is the total mass. Now, proceeding with the second definition, note the density is $\rho(x,y) = \lambda \delta(y)\mathbb{1}_{[0,\ell]}( x)$ and that the distance from the axis is given by $r^2_{\mathrm{axis}} = x^2 + y^2$. Integrating,
$$\int_V dy dx \, \rho (x^2 + y^2) = \left[ \frac{1}{3}\lambda x^3\right]^{\ell}_0 = \frac{1}{3}\lambda \ell^3 = \frac{1}{3}M\ell^2.$$
From this example, you can see why the definitions are equivalent, but we often use the second, particularly because expressing the distance from the axis as a function of mass is not always as simple, and it is rather odd to think of them relating in that way.
\mathbf
sign as I wrote in the chat. – Nov 11 '16 at 11:45