If you mean only if the player founds the city and only when they found the city, then it would have to be done by an lua script.
The FreeBuilding in Traits will apply it to any city the player owns, whether they found it or annex it, assuming the player has the needed tech, and the terrain-requirements for the building are otherwise met. For example the free Harbor that Dido (?) gets is not applied to cities that are not on a coast.