Index: openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake =================================================================== --- openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake +++ openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake @@ -112,6 +112,9 @@ ################################################################################ # Looking for CUDA... ################################################################################ +if (CUDA_TOOLKIT_ROOT_DIR) + set(cuda_toolkit_root_dir_old TRUE) +endif() find_package(CUDA QUIET) set(LIBOMPTARGET_DEP_CUDA_FOUND ${CUDA_FOUND}) @@ -158,3 +161,32 @@ LIBOMPTARGET_DEP_CUDA_DRIVER_LIBRARIES) mark_as_advanced(LIBOMPTARGET_DEP_CUDA_DRIVER_LIBRARIES) + +################################################################################ +# Looking for CUDA libdevice subdirectory +# +# Special case for Debian/Ubuntu to have nvidia-cuda-toolkit work +# out of the box. More info on http://bugs.debian.org/882505 +################################################################################ + +set(cuda_libdevice_subdir nvvm/libdevice) + +# Don't alter CUDA_TOOLKIT_ROOT_DIR if the user specified it, if a value was +# already cached for it, or if it already has libdevice. Otherwise, on +# Debian/Ubuntu, look where the nvidia-cuda-toolkit package normally installs +# libdevice. +if (NOT cuda_toolkit_root_dir_old AND + NOT EXISTS "${CUDA_TOOLKIT_ROOT_DIR}/${cuda_libdevice_subdir}") + find_program(LSB_RELEASE lsb_release) + if (LSB_RELEASE) + execute_process(COMMAND ${LSB_RELEASE} -is + OUTPUT_VARIABLE LSB_RELEASE_ID + OUTPUT_STRIP_TRAILING_WHITESPACE) + set(candidate_dir /usr/lib/cuda) + if ((LSB_RELEASE_ID STREQUAL "Debian" OR LSB_RELEASE_ID STREQUAL "Ubuntu") + AND EXISTS "${candidate_dir}/${cuda_libdevice_subdir}") + set(CUDA_TOOLKIT_ROOT_DIR "${candidate_dir}" CACHE PATH + "Toolkit location." FORCE) + endif() + endif() +endif()