Update the cmake build configuration for AppleClang compiler (#15820)
Summary:
This pr try to merge the https://github.com/pytorch/pytorch/pull/11563 again and fix the linking error in https://github.com/pytorch/pytorch/pull/14837.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/15820
Differential Revision: D13942024
Pulled By: ezyang
fbshipit-source-id: dc6d1e9c4b0f177914f3745665244272a03ce33c