<P> According to legend, the apostle Saint James the Great brought Christianity to the Iberian Peninsula . In 44 AD, he was beheaded in Jerusalem . His remains were later brought back to Galicia, Spain . Following Roman persecutions of Spanish Christians, his tomb was abandoned in the 3rd century . According to legend, this tomb was rediscovered in 814 AD by the hermit Pelagius, after he witnessed strange lights in the night sky . Bishop Theodomirus of Iria recognized this as a miracle and informed king Alfonso II of Asturias and Galicia (791--842). The king ordered the construction of a chapel on the site . Legend has it that the king was the first pilgrim to this shrine . This was followed by the first church in 829 AD and then in 899 AD by a pre-Romanesque church, ordered by king Alfonso III of León, which caused the gradual development of this major place of pilgrimage . </P> <P> In 997 the early church was reduced to ashes by Al - Mansur Ibn Abi Aamir (938--1002), army commander of the caliph of Córdoba . The Al - Andalus commander was accompanied on his raid by his vassal Christian lords, who received a share of the loot, while St James' tomb and relics were left undisturbed . The gates and the bells, carried by local Christian captives to Córdoba, were added to the Aljama Mosque . When Córdoba was taken by king Ferdinand III of Castile in 1236, these same gates and bells were then transported by Muslim captives to Toledo, to be inserted in the Cathedral of Saint Mary of Toledo . </P> <P> Construction of the present cathedral began in 1075 under the reign of Alfonso VI of Castile (1040--1109) and the patronage of bishop Diego Peláez . It was built according to the same plan as the monastic brick church of Saint Sernin in Toulouse, probably the greatest Romanesque edifice in France . It was built mostly in granite . Construction was halted several times and, according to the Liber Sancti Iacobi, the last stone was laid in 1122 . But by then, the construction of the cathedral was certainly not finished . The cathedral was consecrated in 1211 in the presence of king Alfonso IX of Leon . </P> <P> According to the Codex Calixtinus the architects were "Bernard the elder, a wonderful master", his assistant Robertus Galperinus, and, later possibly, "Esteban, master of the cathedral works". In the last stage "Bernard, the younger" was finishing the building, while Galperinus was in charge of the coordination . He also constructed a monumental fountain in front of the north portal in 1122 . </P>

When was catedral de santiago de compostela built
find me the text answering this question