Empty CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES despite CUDA being found
I have CMake 3.13.2 on Windows 10, generator Visual Studio 14 2015 Win64.
My CMakeLists.txt
defines a C++ and (native) CUDA project. Everything works, C++ and CUDA files get compiled without any errors.
The problem:
I need to find a path to CUDA includes and according to the documentation and this StackOverflow thread, I should use CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES
. Unfortunately, this variable is empty even though CUDA was found correctly and compiling works without any issues.
This is a minimal reproducible example:
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
project(blahblah LANGUAGES CXX CUDA)
add_executable(blahblah test.cu)
message("cuda include:" ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
Output: (see the empty cuda include:
line)
Output is from cmake-gui, but same issue when ran from command line directly.
Selecting Windows SDK version 10.0.14393.0 to target Windows 10.0.17134.
The CXX compiler identification is MSVC 19.0.24215.1
The CUDA compiler identification is NVIDIA 9.0.176
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.0/bin/nvcc.exe
Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.0/bin/nvcc.exe -- works
Detecting CUDA compiler ABI info
Detecting CUDA compiler ABI info - done
cuda include:
Configuring done
After configuring, file build/CMakeFiles/3.13.2/CMakeCUDACompiler.cmake
contains the following line:
set(CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES "")
But file build/CMakeFiles/3.13.2/CompilerIdCUDA/Debug/CMakeCUDACompilerId.cu.cache
contains:
Include=;;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\include
When building / compiling, the path is correctly passed to nvcc.exe
:
"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin\nvcc.exe" -gencode=arch=compute_30,code=\"sm_30,compute_30\" --use-local-env --cl-version 2015 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64" -x cu -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\include" --keep-dir x64\Debug -maxrregcount=0 --machine 64 --compile -cudart static -Xcompiler="/EHsc -Zi -Ob0" -g -D_WINDOWS -D"CMAKE_INTDIR=\"Debug\"" -D"CMAKE_INTDIR=\"Debug\"" -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /FS /Zi /RTC1 /MDd /GR" -o blahblah.dir\Debug\test.obj "BLAH\cmaketest\test.cu"
notice the -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\include"
part of the command.