Either via feedback (measure the true stator current/voltage and and force if to converge to the desired waveform via a negative feedback law) or by modelling (estimate what the distortion will be depending on your driving electronics and operating state, and apply an approximate correction with some sot of lookup table). Which approach is more suitable depends on what sort of controller you have, and how much extra hardware you want to add.