Though settlement in the area goes back to Roman times, the medieval town of Perpignan seems to have been founded around the beginning of the 10th century. Soon Perpignan became the capital of the counts of Roussillon. Historically, it was part of the region known as Septimania. In 1172 Count Girard II bequeathed his lands to the Counts of Barcelona. Perpignan acquired the institutions of a partly self-governing commune in 1197. French feudal rights over Roussillon were given up by Louis IX in the Treaty of Corbeil.