How giant moons form around exoplanets