diff options
author | Brad King <brad.king@kitware.com> | 2020-02-03 16:29:31 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2020-02-03 16:29:48 (GMT) |
commit | 095d50598b7fe947937a03cb02d74e3ee13bb542 (patch) | |
tree | d8c2d7b318818c6874354842b4fd891b47da517f /Modules | |
parent | 20eeeeaa1a393584ddbc428afe5c6b4bf57f773d (diff) | |
parent | 60bb7a54d58920d6d70e3983161e2ae4ec530871 (diff) | |
download | CMake-095d50598b7fe947937a03cb02d74e3ee13bb542.zip CMake-095d50598b7fe947937a03cb02d74e3ee13bb542.tar.gz CMake-095d50598b7fe947937a03cb02d74e3ee13bb542.tar.bz2 |
Merge topic 'findCUDAToolkit_correct_cudart_static_deps'
60bb7a54d5 CUDAToolkit: Add required static runtime library dependencies
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !4294
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/FindCUDAToolkit.cmake | 25 |
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}) |