6

Since in CMAKE 3.10, CUDA macro is supported by default (https://cmake.org/cmake/help/latest/module/FindCUDA.html).

But I can't find the variable CUDA_INCLUDE_DIRS

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

message(${CUDA_INCLUDE_DIRS})

the errors are

-- 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".

Any idea?

alec.tu
  • 1,647
  • 2
  • 20
  • 41
  • 2
    If you haven't used the legacy CUDA build macros, whiy would you expect a legacy build variable like CUDA_INCLUDE_DIRS to be set? – talonmies Apr 18 '19 at 07:49
  • So How to find the cuda include directories in newer version of cmake? – alec.tu Apr 18 '19 at 07:57
  • 1
    That is a different question from what you initially asked -- but probably something like this https://stackoverflow.com/a/6904431/681865 – talonmies Apr 18 '19 at 08:13
  • It looks like original question, but it couldn't get as much popularity like this later one: https://stackoverflow.com/questions/51756562/obtaining-the-cuda-include-dir-in-c-targets-with-native-cuda-support-cmake – Andrei Sep 10 '19 at 01:09

1 Answers1

15

Just use the ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}.

In all .cu src files, there is no need to manually add

include_directories(${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}),

because CMake will do it for you.

But for .cpp src files, if you need to include <cuda_runtime.h>, you must manually add

include_directories(${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}) 

in your CMakeLists.txt.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Leo Xu
  • 201
  • 1
  • 5