cmake: extract common code