I'm in this situation now, so I'll tell you what I know.
In France in particular, you are eligible to apply for French citizenship if you fluently speak French and can pass a test after 5 years of living in France. However, for people who do Masters or PhD in France, this time period is reduced to 2 years (meaning you could apply in the second year of your PhD). However this is misleading; you also need to submit evidence of 3 French tax returns (which happen once per year) meaning you will actually only be able to apply in your third year in the country (bearing in mind that the PhD only lasts 3 years). It is possible to extend your Scientific Researcher visa for a postdoctoral position.
However, the tricky part about academia is that it's generally expected that you will work in several institutions for postdocs before settling down into a 'permanent' (not permanent) academic position, which may well mean moving countries, which will reset the 'residence' timer for citizenship. See the problem?
So, your best bet would be to do a PhD in a country which offers a similar citizenship pipeline (Germany, for example, will let you extend your stay to find employment, as will France), and then do your first and perhaps even second postdoc in that country. But given the job market in your field and in academia in general, this may be difficult or even impossible.
The laws are different in every country. For example, Switzerland has a 12 year residency requirement, which isn't compatible with many academic career timelines unless you never leave Switzerland. The UK is also making it exceedingly difficult for any non-European to live there, via a recent initiative requiring that any non-EEA resident make at least £36000 per year, or they'll be deported.
But yes, your position is a common one. And I'm in it too. My "solution" is that I am trying get Portuguese citizenship via Ancestry (Portuguese grandfather), which is both costly and time-consuming. Examine your family tree and see if perhaps you're eligible for anything similar based on the heritage of your parents or grandparents.