summaryrefslogtreecommitdiffstats
path: root/Modules/FindCUDAToolkit.cmake
diff options
context:
space:
mode:
authorRobert Maynard <rmaynard@nvidia.com>2021-02-03 22:39:26 (GMT)
committerRobert Maynard <rmaynard@nvidia.com>2021-02-08 20:13:01 (GMT)
commit3cef91a32159bd3e311b5c1d76798ae40a156ccb (patch)
treec6ab164a9c0ee9566074e008573accdf0c86b3d5 /Modules/FindCUDAToolkit.cmake
parentb06a480b5726a44cefb98cf84f0d874c37d1a95c (diff)
downloadCMake-3cef91a32159bd3e311b5c1d76798ae40a156ccb.zip
CMake-3cef91a32159bd3e311b5c1d76798ae40a156ccb.tar.gz
CMake-3cef91a32159bd3e311b5c1d76798ae40a156ccb.tar.bz2
CUDA: Always extract CUDA Toolkit root from nvcc verbose output
Fixes #21750, #21763 Given that NVCC can be provided by multiple different sources (NVIDIA HPC SDK, CUDA Toolkit, distro) each of which has a different layout, we need to extract the CUDA toolkit root from the compiler itself, allowing us to support numerious different scattered toolkit layouts. The NVIDIA HPC SDK specifically ships two copies of nvcc one in `compilers/bin/` and one in `cuda/bin`. Thus when using `compilers/bin/nvcc` the Toolkit root logic fails.
Diffstat (limited to 'Modules/FindCUDAToolkit.cmake')
-rw-r--r--Modules/FindCUDAToolkit.cmake25
1 files changed, 12 insertions, 13 deletions
diff --git a/Modules/FindCUDAToolkit.cmake b/Modules/FindCUDAToolkit.cmake
index ac2516c..83de97b 100644
--- a/Modules/FindCUDAToolkit.cmake
+++ b/Modules/FindCUDAToolkit.cmake
@@ -518,24 +518,23 @@ else()
)
endif()
- if(CUDAToolkit_NVCC_EXECUTABLE)
- # If NVCC is a symlink due to a wrapper script (e.g. ccache or colornvcc), then invoke it to find the
- # real non-scattered toolkit.
- if(IS_SYMLINK ${CUDAToolkit_NVCC_EXECUTABLE})
- execute_process(COMMAND ${CUDAToolkit_NVCC_EXECUTABLE} "-v" "__cmake_determine_cuda" ERROR_VARIABLE NVCC_ERR)
- if(NVCC_ERR MATCHES " _HERE_=([^\r\n]*)")
- set(CUDAToolkit_BIN_DIR "${CMAKE_MATCH_1}")
- else()
- message(FATAL_ERROR "Could not execute nvcc with -v.")
- endif()
- unset(NVCC_ERR)
+ if(EXISTS "${CUDAToolkit_NVCC_EXECUTABLE}")
+ # If NVCC exists then invoke it to find the toolkit location.
+ # This allows us to support wrapper scripts (e.g. ccache or colornvcc), CUDA Toolkit,
+ # NVIDIA HPC SDK, and distro's splayed layouts
+ execute_process(COMMAND ${CUDAToolkit_NVCC_EXECUTABLE} "-v" "__cmake_determine_cuda" ERROR_VARIABLE NVCC_ERR)
+ if(NVCC_ERR MATCHES "TOP=([^\r\n]*)")
+ get_filename_component(CUDAToolkit_BIN_DIR "${CMAKE_MATCH_1}/bin" ABSOLUTE)
else()
get_filename_component(CUDAToolkit_BIN_DIR "${CUDAToolkit_NVCC_EXECUTABLE}" DIRECTORY)
endif()
+ unset(NVCC_ERR)
- set(CUDAToolkit_BIN_DIR "${CUDAToolkit_BIN_DIR}" CACHE PATH "" FORCE)
mark_as_advanced(CUDAToolkit_BIN_DIR)
- elseif(CUDAToolkit_SENTINEL_FILE)
+ set(CUDAToolkit_BIN_DIR "${CUDAToolkit_BIN_DIR}" CACHE PATH "" FORCE)
+ endif()
+
+ if(CUDAToolkit_SENTINEL_FILE)
get_filename_component(CUDAToolkit_BIN_DIR ${CUDAToolkit_SENTINEL_FILE} DIRECTORY ABSOLUTE)
set(CUDAToolkit_BIN_DIR "${CUDAToolkit_BIN_DIR}/bin")