When I try your suggestion on a fresh clone of the git with the minimal possible extra configuration, I get:
git clone --recursive https://github.com/pytorch/pytorch pytorch_test
cd pytorch_test/
git checkout --recurse-submodules v1.4.1
conda activate dl
source /usr/local/cuda-10.1/add_path.sh  # Defines CUDA_PATH and modifies PATH/LD_LIBRARY_PATH for CUDA 10.1
source /opt/nccl-2.4.8/add_path.sh  # Modifies LD_LIBRARY_PATH for NCCL 2.4.8

CMAKE_PREFIX_PATH="${CONDA_PREFIX:-"$(dirname $(which conda))/../"}" \
CUDA_LIB_PATH=/usr/local/cuda-10.1/extras/system \
NCCL_INCLUDE_DIR=/opt/nccl-2.4.8/include \
NCCL_LIB_DIR=/opt/nccl-2.4.8/lib \
USE_SYSTEM_NCCL=ON \
USE_NCCL=ON \
python setup.py build --cmake-only

-- Building version 1.4.0a0+7404463
cmake -GNinja -DBUILD_PYTHON=True -DBUILD_TEST=True -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/home/escarda/Programs/PyTorch/pytorch_test/torch -DCMAKE_PREFIX_PATH=/home/escarda/anaconda3/envs/dl -DNUMPY_INCLUDE_DIR=/home/escarda/anaconda3/envs/dl/lib/python3.6/site-packages/numpy/core/include -DPYTHON_EXECUTABLE=/home/escarda/anaconda3/envs/dl/bin/python -DPYTHON_INCLUDE_DIR=/home/escarda/anaconda3/envs/dl/include/python3.6m -DPYTHON_LIBRARY=/home/escarda/anaconda3/envs/dl/lib/libpython3.6m.so.1.0 -DTORCH_BUILD_VERSION=1.4.0a0+7404463 -DUSE_NCCL=ON -DUSE_NUMPY=True -DUSE_SYSTEM_NCCL=ON /home/escarda/Programs/PyTorch/pytorch_test
-- The CXX compiler identification is GNU 7.5.0
-- The C compiler identification is GNU 7.5.0
...
-- Found CUDA: /usr/local/cuda-10.1 (found version "10.1") 
-- Caffe2: CUDA detected: 10.1
-- Caffe2: CUDA nvcc is: /usr/local/cuda-10.1/bin/nvcc
-- Caffe2: CUDA toolkit directory: /usr/local/cuda-10.1
-- Caffe2: Header version is: 10.1
-- Found CUDNN: /usr/local/cuda-10.1/lib64/libcudnn.so  
-- Found cuDNN: v7.6.5  (include: /usr/local/cuda-10.1/include, library: /usr/local/cuda-10.1/lib64/libcudnn.so)
-- Autodetected CUDA architecture(s):  7.5 7.5 7.5 7.5
-- Added CUDA NVCC flags for: -gencode;arch=compute_75,code=sm_75
-- Found NCCL: /opt/nccl-2.4.8/include  
-- Determining NCCL version from /opt/nccl-2.4.8/include/nccl.h...
-- Looking for NCCL_VERSION_CODE
-- Looking for NCCL_VERSION_CODE - not found
-- NCCL version < 2.3.5-5
-- Found NCCL (include: /opt/nccl-2.4.8/include, library: /opt/nccl-2.4.8/lib/libnccl.so)
-- Could NOT find CUB (missing: CUB_INCLUDE_DIR) 
-- MPI include path: /usr/lib/x86_64-linux-gnu/openmpi/include/openmpi/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi/opal/mca/event/libevent2022/libevent/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi/opal/mca/event/libevent2022/libevent/include/usr/lib/x86_64-linux-gnu/openmpi/include
-- MPI libraries: /usr/lib/x86_64-linux-gnu/openmpi/lib/libmpi_cxx.so/usr/lib/x86_64-linux-gnu/openmpi/lib/libmpi.so
-- Found CUDA: /usr/local/cuda-10.1 (found suitable version "10.1", minimum required is "7.0") 
-- CUDA detected: 10.1
-- Determining NCCL version from the header file: /opt/nccl-2.4.8/include/nccl.h
-- NCCL_MAJOR_VERSION: 2
-- Found NCCL (include: /opt/nccl-2.4.8/include, library: /opt/nccl-2.4.8/lib/libnccl.so)

Finding NCCL the first time fails as before with the version check.
Is there any way to add custom arguments to the cmake command line without manually hacking it into the setup code?
This would allow things like --trace --trace-expand to be used to debug what’s going on, and would allow some variables to be set that are currently unchangeable. For example, the variable TENSORRT_ROOT is intended to be used to specify the TensorRT location, but the variable is ignored because $ENV{TENSORRT_ROOT} is never queried in the CMakelists, and TENSORRT_ROOT is stripped from the cmake command line essentially because it doesn’t start with BUILD_, USE_ or CMAKE_ (see tools/setup_helpers/cmake.py:257).