The phrase “to set one’s cap for a person” means: To strive to gain the affection of a person.
Always said of a woman or maiden who, perhaps modestly or perhaps ostentatiously, puts her best foot forward in her efforts to gain the attention and win the admiration of the male she favors as a lifelong companion in matrimony.
The expression was once more literal than figurative.
Back in the days when women considered a light muslin cap a necessary part of ordinary indoor attire, it was but natural for a maiden, a spinster, or a widow to don her most becoming or fanciest cap when an eligible swain came to call.
Of course young brother or nephew Diccon would spot the dress-up headgear, and the family would adopt his remark that Molly or Aunty Prue was “setting her cap at” the young squire or the parson.
The common expression may go back to the seventeenth century, but was certainly known to Oliver Goldsmith in the eighteenth.
The younger generation of today probably does not know it.