This is the problem of choosing a launch velocity to hit a target on a parabolic trajectory. I couldn’t figure out the math for a general solution but I made two simplified cases:
(1) Cannon and target on a horizontal line, launch speed is fixed, solve for launch angle
(2) Launch horizontal speed is fixed, solve for vertical speed
This is a little unrealistic but for small vertical distances it looks fine.