I always thought it was the closest building to the troop when deployed. But, I think it might be the building closest to the maximum range of the troop?
Just a bit confusing.
Here is a picture of a troop deploying and targeting a building that is not the closest to it.
Attachment 30441

