Obtaining the CUDA include dir in C++ targets with native-CUDA-support CMake?

不想你离开。 提交于 2019-11-29 15:28:34

The include directories, which are used by the compiler set by CMAKE_CUDA_COMPILER, can be retrieved from the CMake variable CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES.

For getting the libraries, the best way is probably to use find_library() in combination with CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES.

Example:

cmake_minimum_required(VERSION 3.9)
project(MyProject VERSION 1.0)
enable_language(CUDA)

find_library(CUDART_LIBRARY cudart ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES})

add_executable(binary_linking_to_cudart my_cpp_file_using_cudart.cpp)
target_include_directories(binary_linking_to_cudart PRIVATE ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
target_link_libraries(binary_linking_to_cudart ${CUDART_LIBRARY})

This issue is also discussed on the CMake bug tracker: Provide target libraries for cuda libraries.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!