diff options
author | Rong Ou <rong.ou@gmail.com> | 2021-01-08 00:20:24 (GMT) |
---|---|---|
committer | Rong Ou <rong.ou@gmail.com> | 2021-01-11 08:18:04 (GMT) |
commit | fb2afef620e623c28e3251f3dfc56a91d37efd2f (patch) | |
tree | 4a52efa4fe674e25bf3e46a924a5557d324fe9fb /Modules/FindCUDA.cmake | |
parent | 1fb0670f4bb2bb56bff655913df5b5b38e5d500d (diff) | |
download | CMake-fb2afef620e623c28e3251f3dfc56a91d37efd2f.zip CMake-fb2afef620e623c28e3251f3dfc56a91d37efd2f.tar.gz CMake-fb2afef620e623c28e3251f3dfc56a91d37efd2f.tar.bz2 |
CUDA: Support nvcc symlinking to ccache
Invoke `nvcc -v` to find the real CUDA bin directory.
This is needed if `nvcc` is a symlink to `ccache` or `colornvcc`.
Fixes: #21177
Diffstat (limited to 'Modules/FindCUDA.cmake')
-rw-r--r-- | Modules/FindCUDA.cmake | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/Modules/FindCUDA.cmake b/Modules/FindCUDA.cmake index 6daf81d..240f0a5 100644 --- a/Modules/FindCUDA.cmake +++ b/Modules/FindCUDA.cmake @@ -834,7 +834,20 @@ if(NOT CUDA_TOOLKIT_ROOT_DIR AND NOT CMAKE_CROSSCOMPILING) ) if (CUDA_TOOLKIT_ROOT_DIR_NVCC) - get_filename_component(CUDA_TOOLKIT_ROOT_DIR_NVCC_PAR "${CUDA_TOOLKIT_ROOT_DIR_NVCC}" DIRECTORY) + # 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 ${CUDA_TOOLKIT_ROOT_DIR_NVCC}) + execute_process(COMMAND ${CUDA_TOOLKIT_ROOT_DIR_NVCC} "-v" "__cmake_determine_cuda" ERROR_VARIABLE NVCC_ERR) + if(NVCC_ERR MATCHES " _HERE_=([^\r\n]*)") + set(CUDA_TOOLKIT_ROOT_DIR_NVCC_PAR "${CMAKE_MATCH_1}") + else() + message(FATAL_ERROR "Could not execute nvcc with -v.") + endif() + unset(NVCC_ERR) + else() + get_filename_component(CUDA_TOOLKIT_ROOT_DIR_NVCC_PAR "${CUDA_TOOLKIT_ROOT_DIR_NVCC}" DIRECTORY) + endif() + get_filename_component(CUDA_TOOLKIT_ROOT_DIR "${CUDA_TOOLKIT_ROOT_DIR_NVCC_PAR}" DIRECTORY CACHE) string(REGEX REPLACE "[/\\\\]?bin[64]*[/\\\\]?$" "" CUDA_TOOLKIT_ROOT_DIR ${CUDA_TOOLKIT_ROOT_DIR}) # We need to force this back into the cache. |