summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-01-12 15:27:11 (GMT)
committerKitware Robot <kwrobot@kitware.com>2021-01-12 15:27:19 (GMT)
commitd87a8934e0570731b25c7bdec9f835921548928b (patch)
tree807acd817f1e86f220dcdea6a17f94b5b587ef8a /Modules
parentdb8e2e711a1d34944c7939ef4e0eec1fee8e35f2 (diff)
parentfb2afef620e623c28e3251f3dfc56a91d37efd2f (diff)
downloadCMake-d87a8934e0570731b25c7bdec9f835921548928b.zip
CMake-d87a8934e0570731b25c7bdec9f835921548928b.tar.gz
CMake-d87a8934e0570731b25c7bdec9f835921548928b.tar.bz2
Merge topic 'cuda-nvcc-ccache-symlink'
fb2afef620 CUDA: Support nvcc symlinking to ccache Acked-by: Kitware Robot <kwrobot@kitware.com> Reviewed-by: Raul Tambre <raul@tambre.ee> Tested-by: Raul Tambre <raul@tambre.ee> Merge-request: !5620
Diffstat (limited to 'Modules')
-rw-r--r--Modules/CMakeDetermineCUDACompiler.cmake15
-rw-r--r--Modules/FindCUDA.cmake15
-rw-r--r--Modules/FindCUDAToolkit.cmake14
3 files changed, 41 insertions, 3 deletions
diff --git a/Modules/CMakeDetermineCUDACompiler.cmake b/Modules/CMakeDetermineCUDACompiler.cmake
index 578729c..c77fc3a 100644
--- a/Modules/CMakeDetermineCUDACompiler.cmake
+++ b/Modules/CMakeDetermineCUDACompiler.cmake
@@ -172,7 +172,20 @@ if(NOT CMAKE_CUDA_COMPILER_ID_RUN)
endif()
endif()
- get_filename_component(CMAKE_CUDA_COMPILER_TOOLKIT_ROOT "${_CUDA_NVCC_EXECUTABLE}" 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_NVCC_EXECUTABLE})
+ execute_process(COMMAND ${_CUDA_NVCC_EXECUTABLE} "-v" "__cmake_determine_cuda" ERROR_VARIABLE NVCC_ERR)
+ if(NVCC_ERR MATCHES " _HERE_=([^\r\n]*)")
+ set(CMAKE_CUDA_COMPILER_TOOLKIT_ROOT "${CMAKE_MATCH_1}")
+ else()
+ message(FATAL_ERROR "Could not execute nvcc with -v.")
+ endif()
+ unset(NVCC_ERR)
+ else()
+ get_filename_component(CMAKE_CUDA_COMPILER_TOOLKIT_ROOT "${_CUDA_NVCC_EXECUTABLE}" DIRECTORY)
+ endif()
+
set(CMAKE_CUDA_DEVICE_LINKER "${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}/nvlink${CMAKE_EXECUTABLE_SUFFIX}")
set(CMAKE_CUDA_FATBINARY "${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}/fatbinary${CMAKE_EXECUTABLE_SUFFIX}")
get_filename_component(CMAKE_CUDA_COMPILER_TOOLKIT_ROOT "${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}" DIRECTORY)
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.
diff --git a/Modules/FindCUDAToolkit.cmake b/Modules/FindCUDAToolkit.cmake
index 61e264b..0d80c80 100644
--- a/Modules/FindCUDAToolkit.cmake
+++ b/Modules/FindCUDAToolkit.cmake
@@ -519,7 +519,19 @@ else()
endif()
if(CUDAToolkit_NVCC_EXECUTABLE)
- get_filename_component(CUDAToolkit_BIN_DIR "${CUDAToolkit_NVCC_EXECUTABLE}" 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 ${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)
+ else()
+ get_filename_component(CUDAToolkit_BIN_DIR "${CUDAToolkit_NVCC_EXECUTABLE}" DIRECTORY)
+ endif()
set(CUDAToolkit_BIN_DIR "${CUDAToolkit_BIN_DIR}" CACHE PATH "" FORCE)
mark_as_advanced(CUDAToolkit_BIN_DIR)