summaryrefslogtreecommitdiffstats
path: root/Modules/FindCUDAToolkit.cmake
diff options
context:
space:
mode:
authorRobert Maynard <robert.maynard@kitware.com>2020-01-22 18:03:22 (GMT)
committerRobert Maynard <robert.maynard@kitware.com>2020-01-30 15:18:21 (GMT)
commit60bb7a54d58920d6d70e3983161e2ae4ec530871 (patch)
tree4d04455b6a9d84fea51e3650371c16bce87a5f9d /Modules/FindCUDAToolkit.cmake
parent7dd5ca66c911a422878f53d998eb457297eaf804 (diff)
downloadCMake-60bb7a54d58920d6d70e3983161e2ae4ec530871.zip
CMake-60bb7a54d58920d6d70e3983161e2ae4ec530871.tar.gz
CMake-60bb7a54d58920d6d70e3983161e2ae4ec530871.tar.bz2
CUDAToolkit: Add required static runtime library dependencies
CUDAToolkit now adds the correct libraries that are required by the static runtime.
Diffstat (limited to 'Modules/FindCUDAToolkit.cmake')
-rw-r--r--Modules/FindCUDAToolkit.cmake25
1 files changed, 25 insertions, 0 deletions
diff --git a/Modules/FindCUDAToolkit.cmake b/Modules/FindCUDAToolkit.cmake
index 3edea05..62749ed 100644
--- a/Modules/FindCUDAToolkit.cmake
+++ b/Modules/FindCUDAToolkit.cmake
@@ -766,6 +766,31 @@ if(CUDAToolkit_FOUND)
_CUDAToolkit_find_and_add_import_lib(cudart)
_CUDAToolkit_find_and_add_import_lib(cudart_static)
+ # setup dependencies that are required for cudart_static when building
+ # on linux. These are generally only required when using the CUDA toolkit
+ # when CUDA language is disabled
+ if(NOT TARGET CUDA::cudart_static_deps
+ AND TARGET CUDA::cudart_static)
+
+ add_library(CUDA::cudart_static_deps IMPORTED INTERFACE)
+ target_link_libraries(CUDA::cudart_static INTERFACE CUDA::cudart_static_deps)
+
+ if(UNIX AND (CMAKE_C_COMPILER OR CMAKE_CXX_COMPILER))
+ find_package(Threads REQUIRED)
+ target_link_libraries(CUDA::cudart_static_deps INTERFACE Threads::Threads ${CMAKE_DL_LIBS})
+ endif()
+
+ if(UNIX AND NOT APPLE)
+ # On Linux, you must link against librt when using the static cuda runtime.
+ find_library(CUDAToolkit_rt_LIBRARY rt)
+ if(NOT CUDAToolkit_rt_LIBRARY)
+ message(WARNING "Could not find librt library, needed by CUDA::cudart_static")
+ else()
+ target_link_libraries(CUDA::cudart_static_deps INTERFACE ${CUDAToolkit_rt_LIBRARY})
+ endif()
+ endif()
+ endif()
+
_CUDAToolkit_find_and_add_import_lib(culibos) # it's a static library
foreach (cuda_lib cublas cufft curand cusparse nppc nvjpeg)
_CUDAToolkit_find_and_add_import_lib(${cuda_lib})