I've been using Loctite Express Power Grab Heavy Duty Exterior Construction Adhesive with HMF. A thin bead around the edges and a cross from corner to corner is plenty. Press in place and you're done. The "Instant Grab" part really works. There are several similar looking variations. The one I've found to be the best says: "Stronger & Faster Than Power Grab Clear". Available at hardware stores for a few dollars a tube. Fits in a caulk gun.
Loctite Express Power Grab Heavy Duty Exterior Construction Adhesive is ideal for places where the HMF is well protected. The HMF can be removed with minimal damage, if needed. It also lets you reposition the piece.
In the few applications where there is space above a sunroof when retracted, I use 3M Super 90. Spay it on the HMF, press the HMF into place to transfer some adhesive, separate and let both surfaces tack up a little. Press the HMF into place and it will never budge.
A single edged razor blade is the fastest and cleanest way to cut Hydrophobic melamine foam.