What does Rambam say about a person whose charitable donation depends on his getting recognition for it. Example: a person will donate the cost of building only if his name is on the building?
The Rambam in Hilchot Matnot Aniyim 10:7 codifies the hierarchy of giving in his view. Anonymous giving comes second
The second level is to give to the poor without knowing to whom one gives, and without the recipient knowing from who he received.
The highest level is someone who supports a fellow Jew by endowing him with a gift or loan, or entering into a partnership with him, or finding employment for him.
R Asher Meir learns from this that
The highest level of giving is someone who establishes a personal relationship with the needy person, helping him with a loan or a partnership in a way that doesn't make him feel subordinate.
R Meir explains the value of anonymity as avoiding to shame the recipient (which wouldn't be relevant to your building example)
Part of the value of anonymity valued in this scheme is indeed due to modesty, as Maimonides writes that an anonymous gift is "a commandment fulfilled for its own sake", rather than done in order to obtain honor. But an equally important consideration is to avoid shaming the recipient.
and continues with thoughts relevant to your question
Is it wrong to give charity in order to obtain honor? There are contradictory sources on this issue. Many sources indicate that there is no problem with this. Indeed, one of the most widespread methods of collecting charity is precisely to sell honors, such as the Torah readings in synagogue, and even so this is considered to be a perfectly legitimate form of giving. [...] But it is permissible to give the money if it will provide honor or status.
Yet the Talmud tells us that giving charity in order to boast about it is actually a sin! (Baba Batra 10b)
We can resolve this paradox by examining the motivation. A person who is motivated by the desire to help others deserves to be honored for his efforts; it follows that he is perfectly permitted to enjoy the honor, in a modest way. Even a person who seeks only honor but decides to obtain it by helping others is still showing concern, though at a lower level; it is certainly better than trying to gain recognition by pride or excess.
But if the original motivation is only to obtain recognition, and there is no concern whatsoever for the needy individual, the gift is not "charitable" at all. The donor is exploiting the recipient's state more than he is trying to alleviate it.
Elsewhere R Asher Meir writes that
The prominent medieval authority Rabbi Shlomo Adret writes that honoring donors is not just a gesture to their vanity; it is a mitzvah in and of itself to give honor to those who perform good deeds - including giving charity.