Development and performance of triple-gem detectors for the upgrade of the muon system of the cms experiment