Major heatwaves across southern Europe have left Spain, Portugal, Italy, and Greece in sweltering conditions of more than 40C (104F).