I've tried integration by parts. I can integrate both factors:
$\int\cos(x)dx = \sin(x) + C_1$
$\int\cos(\frac a x) = a Si(\frac a x) + x \cos(\frac a x) + C_2$
However I'm stuck at this point. I think the way to proceed would be integration by parts, however that requires calculating the integral of $\int (u' \int v dx) dx$. However, I don't think there will be a nice closed form solution, no matter how many times I apply integration by parts, because I'll never be able to escape from $u$ being or containing $f(x)$, where $f$ is a periodic function, and $v$ being or containing $g(\frac a x)$, where $g$ is also a periodic function.
There's also some interesting ideas in Closed form of $\int_0^\infty \sin(x)\sin\left(\frac{1}{x}\right)dx$?, however I'm not sure how to adapt that solution to integrate from $0$ to $b$ instead of $0$ to $\infty$.