From 126d63c85da8cfc4c778c410d48c2a39c69b570f Mon Sep 17 00:00:00 2001 From: Eyal Rozenberg Date: Thu, 8 Feb 2024 20:46:21 +0200 Subject: [PATCH] Fixes #583: All wrapper library targets now depend on librt (on Linux), libm, a threads library (pthreads on Linux) and the dynamic linking library (libdl on Linux) --- CMakeLists.txt | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 90765236..23a959a1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,12 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "lib/") find_package(CUDAToolkit 9.0 REQUIRED) enable_language(CXX) # required for using Threads find_package(Threads REQUIRED) +include(CheckLibraryExists) +check_library_exists(m pow "" libm_exists) +if(libm_exists) + set(c_math_lib m) +endif() + if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 11.1) foreach(tgt in nvptxcompiler nvptxcompiler_static) if (NOT TARGET ${tgt}) @@ -46,6 +52,14 @@ foreach(wrapper_lib ${targets}) "$" ) target_link_libraries(${caw_lib} INTERFACE CUDA::cudart CUDA::cuda_driver) + + # These next three dependencies should be carried by the CUDA libraries themselves... + # but they aren't - this is CMake bug 25665 + target_link_libraries(${caw_lib} INTERFACE Threads::Threads ${CMAKE_DL_LIBS} ${c_math_lib} ) + if(UNIX AND NOT APPLE) + target_link_libraries(${caw_lib} INTERFACE rt) + endif() + # Targets using these libraries should be compiled with C++11 _at least_, # but it doesn't seem there's a way to express that at the CMake level @@ -70,10 +84,9 @@ if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 11.1) set(ptx_compiler_target nvptxcompiler_static) endif() target_link_libraries(caw_rtc INTERFACE CUDA::${ptx_compiler_target}) - target_link_libraries(caw_rtc INTERFACE Threads::Threads) # Because the NVIDIA PTX compiler itself uses threads endif() -target_link_libraries(caw_nvtx INTERFACE cuda-api-wrappers::runtime-and-driver ${CMAKE_DL_LIBS}) # libnvToolsExt uses dlclose +target_link_libraries(caw_nvtx INTERFACE cuda-api-wrappers::runtime-and-driver) if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 10.0) target_link_libraries(caw_nvtx INTERFACE CUDA::nvtx3)