summaryrefslogtreecommitdiffstats
path: root/Modules/CMakeDetermineCUDACompiler.cmake
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2020-05-21 15:19:48 (GMT)
committerBrad King <brad.king@kitware.com>2020-05-22 10:50:19 (GMT)
commitd8eee80e3091ebdc1af2208ec6e94d885b279be9 (patch)
treeb3e9b51d85b895e0f89c75a6b71d95c6769f320e /Modules/CMakeDetermineCUDACompiler.cmake
parent345d707cf0d68c27edcaa9f76ac3257303750b70 (diff)
parente55b21e24ee81f5433b8ec778aa341c485d6e149 (diff)
downloadCMake-d8eee80e3091ebdc1af2208ec6e94d885b279be9.zip
CMake-d8eee80e3091ebdc1af2208ec6e94d885b279be9.tar.gz
CMake-d8eee80e3091ebdc1af2208ec6e94d885b279be9.tar.bz2
Merge branch 'backport-cuda-default-runtime' into cuda-default-runtime
Diffstat (limited to 'Modules/CMakeDetermineCUDACompiler.cmake')
-rw-r--r--Modules/CMakeDetermineCUDACompiler.cmake28
1 files changed, 28 insertions, 0 deletions
diff --git a/Modules/CMakeDetermineCUDACompiler.cmake b/Modules/CMakeDetermineCUDACompiler.cmake
index af36688..427e5b5 100644
--- a/Modules/CMakeDetermineCUDACompiler.cmake
+++ b/Modules/CMakeDetermineCUDACompiler.cmake
@@ -112,6 +112,20 @@ if(${CMAKE_GENERATOR} MATCHES "Visual Studio")
set(CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES "")
set(CMAKE_CUDA_HOST_IMPLICIT_LINK_DIRECTORIES "")
set(CMAKE_CUDA_HOST_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "")
+
+ # We do not currently detect CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES but we
+ # do need to detect CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT from the compiler by
+ # looking at which cudart library exists in the implicit link libraries passed
+ # to the host linker.
+ if(CMAKE_CUDA_COMPILER_PRODUCED_OUTPUT MATCHES "link\\.exe [^\n]*cudart_static\\.lib")
+ set(CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT "STATIC")
+ elseif(CMAKE_CUDA_COMPILER_PRODUCED_OUTPUT MATCHES "link\\.exe [^\n]*cudart\\.lib")
+ set(CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT "SHARED")
+ else()
+ set(CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT "NONE")
+ endif()
+ set(_SET_CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT
+ "set(CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT \"${CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT}\")")
elseif(CMAKE_CUDA_COMPILER_ID STREQUAL "Clang")
# Parse default CUDA architecture.
if(NOT CMAKE_CUDA_ARCHITECTURES)
@@ -232,6 +246,20 @@ elseif(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA")
log
"${CMAKE_CUDA_IMPLICIT_OBJECT_REGEX}")
+ # Detect CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT from the compiler by looking at which
+ # cudart library exists in the implicit link libraries passed to the host linker.
+ # This is required when a project sets the cuda runtime library as part of the
+ # initial flags.
+ if(";${CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES};" MATCHES [[;cudart_static(\.lib)?;]])
+ set(CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT "STATIC")
+ elseif(";${CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES};" MATCHES [[;cudart(\.lib)?;]])
+ set(CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT "SHARED")
+ else()
+ set(CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT "NONE")
+ endif()
+ set(_SET_CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT
+ "set(CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT \"${CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT}\")")
+
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
"Parsed CUDA nvcc implicit link information from above output:\n${_nvcc_log}\n${log}\n\n")
else()