The phrase to build castles in the air, or in Spain, means to form unattainable projects.
While castles in the air is self-explanatory, castles in Spain requires some elucidation.
It first appeared in The Romaunt of the Rose, a partial translation into Middle English, made in the time of the English poet Geoffrey Chaucer (circa 1342-1400), of Le Roman de la rose:
Thou shalt make castles than in Spaine,
And dreame of joy, all but in vaine,
And thee delighten of right nought,
While thou so slumbrest in that thought,
That is so sweete and delitable*,
For which in sooth n’is but a fable.
(* delitable: delightful)
An extremely influential French poem of the 13th century, Le Roman de la rose is an allegorical romance embodying the aristocratic ethic of courtly love; it was composed by two different authors some forty years apart. The French text is:
Lors feras chastiaus en Espaigne
E avras joie de neient
Tant con tu iras foleiant
En la pensee delitable
Ou il n’a que mençonge e fable.
According to Arthur Långfors in Châteaux en Brie et — en Espagne, published in Neuphilologische Mitteilungen in 1914, the metaphor originated in Aymeri de Narbonne, an early-13th-century chanson de geste (i.e. a medieval French historical verse romance). Returning home after the Battle of Roncesvalles, in northern Spain, during which the rearguard of his army was attacked by the Basques and massacred, Charlemagne comes upon the city of Narbonne, a Saracen sronghold, and offers it as a fief to whichever of his knights will conquer it, but, exhausted, they all refuse. One of them, Richard de Normandie, declares that if he were at home:
Ja en Espaigne n’avroie manantie,
Ne de Narbone n’avroie seignorie
Never in Spain I should have lordship
Nor of Narbonne I should have seigneury
In this passage therefore, what is referred to is something that is difficult or even impossible to conquer. The phrase itself appeared in a similar context in a chanson de geste of the 14th century, Baudouin de Sebourc, in which Baudouin replies to the king, who has just granted him the lordship of Edessa (in modern-day Turkey)—a city that, however, he must first reconquer:
« Sire, dit Baudewin, vous me donnés biau don !
Un chastel en Espaigne, tant qu’en comparison
Conquerre le m’estuet au fer et au baston. »
“Sire, says Baudouin, you are giving me a beautiful gift!
A castle in Spain, so much so that in comparison
I must conquer it with iron and stick [i.e. by military force].”
The image became a topos and Spain could be replaced by any other place name depending on the poetic rhyme that was needed. For example, in Les menus propos (1521), by the French poet and playwright Pierre Gringore (circa 1475-circa 1538), Asie rhymes with rassasie:
Le songer fait chasteaulx en Asie,
Le grant desir la chair ne rassasie.
The dreaming makes castles in Asia,
The great desire the flesh does not satisfy.
Likewise, in Le Verger d’honneur (1496?), by the French poet André de La Vigne (circa 1470-circa 1526), Albanye rhymes with nye:
Je dis ung mot, puis après je le nye,
Et si bastis sans reigle ne compas
Tout fin seullet les chasteaux d’Albanye.
I say a word, then afterwards I disown it,
And thus build without ruler nor compasses
On my own the castles of Albania.
The name did not necessarily denote a foreign place; for instance, the French abbot, poet and musical arranger Gautier de Coincy (1177-1236) wrote, about the monks who pray and sing while their hearts remain concerned with material values (Brie is in northern France):
Que me vaut chose que je die,
Quant mes cuers fait chastiaus en Brie ?
What is the value of what I say,
When my heart is making castles in Brie?
Although most people do not know its origin, châteaux en Espagne continues to be the French phrase to this day.
The English castles in the air perhaps appeared because the cultural reference to castles in Spain had been lost. Its first known user was the English author and translator William Painter (circa 1540-1594) in The palace of pleasure beautified, adorned and well furnished, with pleasaunt histories and excellent nouelles, selected out of diuers good and commendable authors (London, 1566); one of these stories is titled The loue of Alerane of Saxone, and of Adelasia the Daugther of the Emperour Otho the thirde of that name. Their flight and departure into Italie, and how they were knowen agayne, and what noble houses of Italie descended of their race; it contains:
The morrowe at the houre that Alerane should come, Adelasia fayning her selfe to be yll at ease, caused her maydes to goe to bed, making her alone to tarry with her: that was the messanger of her loue, who a little while after, went to séeke Alerane, which was a building of Castels in the ayre, fantasying a thousand deuises in his minde.