Sounds really tricky if you actually mean comparing gerbers with KiCad footprints. For example rounded rectangles, when KiCad exports them to gerbers, are made with several flashes. It’s impossible to know where each flash belongs to if there’s no metadata, so you can’t even create pads, not speaking of whole footprints. Round and rectangle pads should be easier. Even then I would do it like this (not an exact description, just some rough outlines):
- Export whole board, exporting each pad as one footprint.
- Write “create footprint out of items” script.
- Select items from the board for one footprint and create a footprint out of them, saving it to a library.
- Compare all board items with the items of the new footprint and find matching collections of items. Make footprints out of them, using the first footprint as the library footprint.
This could be extended so that first you should manually create a 1-pad footprint out of several flashes. I would be compared with all groups of flashes. That way it might be possible to find complex pad shapes.
EDIT: this would be semi-manual at best. I can’t see a way to make it fully automatic. And it wouldn’t be very useful to reverse-engineer gerbers exported by KiCad. It would be needed for gerbers from other EDA software, and only God knows how they have used gerber specs to create copper features.