Hundreds of firefighters on Wednesday battled a wildfire that has spread across a mountain near Cape Town and threatened South Africa's biggest naval base.

Five out of more than 300 firefighters deployed for the operation on hills overlooking Simon's Town have been injured, authorities said.

"Currently three choppers are water bombing the area while over 300 staff are still on the ground," the Cape Town city fire and rescue department told AFP.

Strong winds pushed the flames into the Simon's Town Naval Base, damaging one building, while nearly 40 nearby houses were evacuated in the early hours of Wednesday, the department said.

Simon's Town is about 45 kilometres (28 miles) south of Cape Town along a coast where wildfires in the key wine-growing districts have been common in recent years.

The Cape Town region has experienced repeat heatwaves with fierce hot winds that have been blamed on rising global temperatures. A 2015 drought was the driest in South Africa for 112 years.