CMAKE_CUDA_HOST_COMPILER does not override CUDAHOSTCXX as documented
https://cmake.org/cmake/help/v3.21/envvar/CUDAHOSTCXX.html states
For any configuration run (including the first), the environment variable will be ignored if the CMAKE_CUDA_HOST_COMPILER variable is defined.
But this does not seem to be true, it seems that the CUDAHOSTCXX
environment variable takes precedence over CMAKE_CUDA_HOST_COMPILER
if the latter is set on the CMake command line.
I added a small example to https://gitlab.kitware.com/olupton/cmake-cuda-host-compiler that demonstrates the issue.
In essence,
CUDAHOSTCXX=$(command -v true) cmake -DCMAKE_CUDA_HOST_COMPILER=$(command -v gcc) ..
with CMakeLists.txt
:
project(test LANGUAGES CUDA)
should succeed, but it does not:
$ CUDAHOSTCXX=$(command -v true) cmake -DCMAKE_CUDA_HOST_COMPILER=$(command -v gcc) ..
CMake Error at {prefix}/cmake-3.21.4-cdyb7k/share/cmake-3.21/Modules/CMakeDetermineCompilerId.cmake:706 (message):
Compiling the CUDA compiler identification source file
"CMakeCUDACompilerId.cu" failed.
Compiler:
{prefix}/cuda-11.5.1-fyf4dd/bin/nvcc
Build flags:
Id flags: --keep;--keep-dir;tmp;-ccbin=/usr/bin/true -v
I also checked that I see the same with CMake 3.22.1.