在最新的 CMAKE 中找不到 CUDA_INCLUDE_DIRS

ale*_*.tu 5 cuda cmake

由于在 CMAKE 3.10 中,默认情况下支持 CUDA 宏(https://cmake.org/cmake/help/latest/module/FindCUDA.html)。

但我找不到变量 CUDA_INCLUDE_DIRS

cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
project(cmake_and_cuda LANGUAGES CXX CUDA)

message(${CUDA_INCLUDE_DIRS})
Run Code Online (Sandbox Code Playgroud)

错误是

-- The CXX compiler identification is GNU 5.4.0
-- The CUDA compiler identification is NVIDIA 10.0.130
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- 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: /usr/local/cuda/bin/nvcc
-- Check for working CUDA compiler: /usr/local/cuda/bin/nvcc -- works
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - done
CMake Error at CMakeLists.txt:7 (message):
  message called with incorrect number of arguments


-- Configuring incomplete, errors occurred!
See also "/home/tumh/code-samples/posts/cmake/build/CMakeFiles/CMakeOutput.log".
Run Code Online (Sandbox Code Playgroud)

任何的想法?

小智 10

只需使用${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}.

在所有 .cu src 文件中,无需手动添加

include_directories(${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}),
Run Code Online (Sandbox Code Playgroud)

因为 CMake 会为你做这件事。

但是对于.cpp src文件,如果需要include <cuda_runtime.h>,必须手动添加

include_directories(${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}) 
Run Code Online (Sandbox Code Playgroud)

在您的 CMakeLists.txt 中。