CheckLanguage: CMAKE_CUDA_HOST_COMPILER always defined after check_language(CUDA)
I couldn't see this being reported already, so here it goes. With CMake 3.21 (3.20 does not seem to exhibit this issue), the following simple configuration always produces a warning on Windows. (As long as CUDA is available.)
cmake_minimum_required( VERSION 3.21 )
project( CUDATest VERSION 1.0.0 LANGUAGES CXX )
include( CheckLanguage )
check_language( CUDA )
if( CMAKE_CUDA_COMPILER )
enable_language( CUDA )
endif()
The warning I see is:
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.19043.
-- The CXX compiler identification is MSVC 19.29.30133.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for a CUDA compiler
-- Looking for a CUDA compiler - C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.4/bin/nvcc.exe
CMake Warning at C:/Program Files/CMake/share/cmake-3.21/Modules/CMakeDetermineCUDACompiler.cmake:15 (message):
Visual Studio does not support specifying CUDAHOSTCXX or
CMAKE_CUDA_HOST_COMPILER. Using the C++ compiler provided by Visual
Studio.
Call Stack (most recent call first):
CMakeLists.txt:7 (enable_language)
-- The CUDA compiler identification is NVIDIA 11.4.100
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - done
-- Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.4/bin/nvcc.exe - skipped
-- Detecting CUDA compile features
-- Detecting CUDA compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: ...
The problem is that Modules/CheckLanguage.cmake always sets up the CMAKE_CUDA_HOST_COMPILER
variable. In this setup it sets it to an empty string. But
https://gitlab.kitware.com/cmake/cmake/-/blob/v3.21.3/Modules/CMakeDetermineCUDACompiler.cmake#L14
still considers that warning-worthy. So the logic between these two should be tweaked a bit. (I'm not necessarily sure what the most simple/robust logic should be though.)
Edited by Brad King