Pion and kaon fragmentation functions at next-to-next-to-leading order