Cristiano Ronaldo notched a hat-trick as Portugal came from behind to beat Northern Ireland 4-2 in their Group F qualifier at Windsor Park.