Wind-farm–boundary layer interaction does not occur only locally; in fact, it has been discovered that non-local effects such as gravity waves can have strong implications on the wind-farm energy extraction. These atmospheric gravity waves are triggered by the upward displacement of the boundary layer due to the flow blockage that occurs in large farms and they modify the wind conditions several kilometres upstream of the farm. In the current study, we investigate the idea of controlling the wind-farm in order to mitigate the efficiency drop due to wind-farm induced gravity waves. The analysis is performed using a fast boundary-layer model which divides the vertical structure of the atmosphere in three layers; the wind-farm drag force is applied over the whole wind-farm area and is directly proportional to the thrust set-point of the wind turbines. We implement an optimization model in order to derive the optimal turbine thrust coefficient space distribution which maximizes the wind-farm energy extraction; the input of the model are the turbine thrust set points in space, the wind-farm layout and the atmospheric conditions. Moreover, we use the continuous adjoint method in order to speed up the optimization algorithm. Interestingly, we find that the turbine-level optimal setting is non-uniform in space and assumes different spatial distributions according to the atmospheric conditions. In particular, when the flow is sub-critical the optimal wind turbine thrust set-point assumes a sinusoidal behavior in the streamwise direction while it becomes a U-shaped curve when the flow is super-critical. We estimate the energy extraction gain due to these turbine-level optimal set-point distributions to be of the order of 6 to 10 %.