Repository: pytorch
Issue: Can't specify compiler, leading to SUPPORT_GLIBCXX_USE_C99 failed
Labels: module: build,triaged

## 🐛 Bug

Trying to compile pytorch 1.7.1 from source, but it is using the wrong compiler.
Setting the CC / CXX variables seem to have no effect.
I am not admin on the machine, I only have access to the user space.


## To Reproduce

The system gcc is 9.3.1, and if I use cmake with CMAKE_C_COMPILER, instead of setup.py, the test pass (but I get another error later).
I also noticed that it does not find CUDA when running collect_environment.py, but I have 11.0, 11.1, and 11.2 installed on the system .

Run script:
```
export CMAKE_PREFIX_PATH=${CONDA_PREFIX:-"$(dirname $(which conda))/../"}
export CC=/opt/rh/devtoolset-9/root/usr/bin/gcc
export CXX=/opt/rh/devtoolset-9/root/usr/bin/g++
python setup.py install
```


Output:
```
instat6> gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-9/root/usr --mandir=/opt/rh/devtoolset-9/root/usr/share/man --infodir=/opt/rh/devtoolset-9/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --with-default-libstdcxx-abi=gcc4-compatible --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-9.3.1-20200408/obj-x86_64-redhat-linux/isl-install --disable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 9.3.1 20200408 (Red Hat 9.3.1-2) (GCC)

linstat6> /usr/local/cuda/bin/nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Mon_May__3_19:15:13_PDT_2021
Cuda compilation tools, release 11.3, V11.3.109
Build cuda_11.3.r11.3/compiler.29920130_0

linstat6> /usr/local/cuda-11.0/bin/nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Wed_Jul_22_19:09:09_PDT_2020
Cuda compilation tools, release 11.0, V11.0.221
Build cuda_11.0_bu.TC445_37.28845127_0


linstat6> ./setup.sh
/software/anaconda37/bin/../
Building wheel torch-1.7.0a0
-- Building version 1.7.0a0
cmake -GNinja -DBUILD_PYTHON=True -DBUILD_TEST=True -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/home/d/daviet/Projects/pytorch-1.7.1/pytorch/torch -DCMAKE_PREFIX_PATH=/software/anaconda37/bin/../ -DNUMPY_INCLUDE_DIR=/software/anaconda37/lib/python3.8/site-packages/numpy/core/include -DPYTHON_EXECUTABLE=/software/anaconda37/bin/python -DPYTHON_INCLUDE_DIR=/software/anaconda37/include/python3.8 -DPYTHON_LIBRARY=/software/anaconda37/lib/libpython3.8.so.1.0 -DTORCH_BUILD_VERSION=1.7.0a0 -DUSE_NUMPY=True /home/d/daviet/Projects/pytorch-1.7.1/pytorch
-- Performing Test SUPPORT_GLIBCXX_USE_C99
-- Performing Test SUPPORT_GLIBCXX_USE_C99 - Failed
CMake Error at cmake/MiscCheck.cmake:81 (message):
  The C++ compiler does not support required functions.  This is very likely
  due to a known bug in GCC 5 (and maybe other versions) on Ubuntu 17.10 and
  newer.  For more information, see:
  https://github.com/pytorch/pytorch/issues/5229
Call Stack (most recent call first):
  CMakeLists.txt:502 (include)
```

## Expected behavior

SUPPORT_GLIBCXX_USE_C99 not failed

## Environment

PyTorch version: 1.7.1+cu110
Is debug build: False
CUDA used to build PyTorch: 11.0
ROCM used to build PyTorch: N/A

OS: CentOS Linux 7 (Core) (x86_64)
GCC version: (GCC) 9.3.1 20200408 (Red Hat 9.3.1-2)
Clang version: Could not collect
CMake version: version 3.21.0
Libc version: glibc-2.17

Python version: 3.8.5 (default, Sep  4 2020, 07:30:14)  [GCC 7.3.0] (64-bit runtime)
Python platform: Linux-3.10.0-1160.11.1.el7.x86_64-x86_64-with-glibc2.10
Is CUDA available: False
CUDA runtime version: No CUDA
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A

Versions of relevant libraries:
[pip3] numpy==1.19.2
[pip3] numpydoc==1.1.0
[pip3] pytorch-sphinx-theme==0.0.24
[pip3] torch==1.7.1+cu110
[pip3] torchaudio==0.7.2
[pip3] torchvision==0.8.2+cu110
[conda] blas                      1.0                         mkl  
[conda] mkl                       2020.2                      256  
[conda] mkl-service               2.3.0            py38he904b0f_0  
[conda] mkl_fft                   1.2.0            py38h23d657b_0  
[conda] mkl_random                1.1.1            py38h0573a6f_0  
[conda] numpy                     1.19.2           py38h54aff64_0  
[conda] numpy-base                1.19.2           py38hfa32c7d_0  
[conda] numpydoc                  1.1.0              pyhd3eb1b0_1



cc @malfet @seemethere @walterddr