Skip to content

check_language (CUDA) does not respect `CUDA_HOST_COMPILER`

cmake_minimum_required(VERSION 3.12.4)
project(my_project LANGUAGES CXX)

check_language(CUDA)
if (CMAKE_CUDA_COMPILER_LOADED)
    enable_language(CUDA)
endif()

If the project is configured with a CUDA_HOST_COMPILER that is not a valid host compiler for CUDA, check_language will pass, but the enable_language will fail.

check_language passes:

Looking for a CUDA compiler passed with the following output:
-- The CUDA compiler identification is NVIDIA 9.2.148
-- Check for working CUDA compiler: .../nvcc
-- Check for working CUDA compiler: .../nvcc -- works
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: .../CheckCUDA

enable_language fails:

Compiling the CUDA compiler identification source file "CMakeCUDACompilerId.cu" failed.
Compiler: .../nvcc
Build flags:~
Id flags:  -v;--keep;--keep-dir;tmp;-ccbin=.../clang-7.0.1/bin/clang++

The output was:
1   
nvcc fatal   : The version ('7.0') of the host compiler ('clang') is not supported


Compiling the CUDA compiler identification source file "CMakeCUDACompilerId.cu" failed.
Compiler: .../nvcc
Build flags:~
Id flags:  -v;--keep;--keep-dir;tmp;-ccbin=.../clang-7.0.1/bin/clang++

The output was:
1   
nvcc fatal   : The version ('7.0') of the host compiler ('clang') is not supported

Note that -ccbin was properly set in the call to enable_language.

The reason is pretty clear: https://github.com/Kitware/CMake/blob/master/Modules/CheckLanguage.cmake#L46 only sets CMAKE_CUDA_COMPILER, but for CUDA, it should also set CUDA_HOST_COMPILER.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information