On a larger project, I have an issue with cmake (with ninja) and CUDA. I have reproduced on a minimal project, without source code. The problem boils down to the following.
I open the project in Visual Studio using the following batch script (located in the project root):
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvarsall.bat" x64 10.0.18362.0 -vcvars_ver=14.1
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\devenv.exe" "%~dp0"
and the CMake generation fails with the following error:
Severity Code Description Project File Line Suppression State
Error CMake Error at C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.17/Modules/CMakeTestCUDACompiler.cmake:46 (message):
The CUDA compiler
"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.0/bin/nvcc.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/CMakeTestCuda/out/build/x64-Debug/CMakeFiles/CMakeTmp
Run Build Command(s):C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe cmTC_c13ee && [1/2] Building CUDA object CMakeFiles\cmTC_c13ee.dir\main.cu.obj
FAILED: CMakeFiles/cmTC_c13ee.dir/main.cu.obj
cmd.exe /C "C:\PROGRA~1\NVIDIA~2\CUDA\v10.0\bin\nvcc.exe -ccbin=C:\PROGRA~2\MICROS~2\2019\PROFES~1\VC\Tools\MSVC\1416~1.270\bin\HostX64\x64\cl.exe -x cu -c main.cu -o CMakeFiles\cmTC_c13ee.dir\main.cu.obj && C:\PROGRA~1\NVIDIA~2\CUDA\v10.0\bin\nvcc.exe -ccbin=C:\PROGRA~2\MICROS~2\2019\PROFES~1\VC\Tools\MSVC\1416~1.270\bin\HostX64\x64\cl.exe -x cu -M main.cu -MT CMakeFiles\cmTC_c13ee.dir\main.cu.obj -o CMakeFiles\cmTC_c13ee.dir\main.cu.obj.d"
'cl.exe' n'est pas reconnu en tant que commande interne
ou externe, un programme exécutable ou un fichier de commandes.
main.cu
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project. C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.17/Modules/CMakeTestCUDACompiler.cmake 46
The project consists only of a CMakeLists.txt:
project ("CMakeTestCuda")
enable_language (CUDA)
set (CMAKE_CUDA_COMPILER "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.0/bin/nvcc.exe")
and a CMakeSettings.json
{
"configurations": [
{
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": ""
}
]
}
Note 1: if I comment the enable_language (CUDA) line the generation succeeds.
Note 2: adding
set (CMAKE_CUDA_HOST_COMPILER "C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/cl.exe")
does not fix the issue.
This used to work for me in the past, but one day, all of the sudden, CMake generation stopped working due to the issue just described. Can someone help, please?