Oddly, the legality depends on the country. In the UK for example, it's a civil offense against the landowner, but not illegal. And as an added bonus, if you 'live' there for 10 years, you can claim ownership! (This has actually happened).
More often than not, it's homeless people that squat, rather than travellers. It's so common in the UK, that there's even a website - "Advisory Service for Squatters".
TheSite also offers some advice and information on squatting, and finishes with a suggestion on alternatives:
Squatting is, however, a last resort when it comes to accommodation. A
good compromise is becoming a property guardian instead. This is where
you move into a disused property, such as a school or office block,
with a number of other property guardians, and look after the building
legally on behalf of the owners. All your bills are paid for and you
pay a very minimal rent - say £100 a month.
You will need to register with - and be vetted by - a property
guardian company first, which will then inform you of accommodation
that becomes available. But the benefit is it's all above board, legal
and - most importantly - safe.