Probably not hardcoded to allow for change via consensus?
the consensus rules involving supply can change whether the total supply is hardcoded or not. it won't change because it is one of the basic principles of bitcoin to have such a cap.
the reason why it is not hardcoded is probably because there is no reason to do it. each block is being verified
individually and the amount of new coins it produces is checked based on its height. no additional check is needed for "total" supply.