summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-09-21 18:18:52 (GMT)
committerBrad King <brad.king@kitware.com>2023-09-21 19:34:27 (GMT)
commita6841a967bc933101a351597b5b09363287ddfa6 (patch)
tree6fb95f9b359b894ea04a9e2eb7d1d754018e82ac
parentdeff0e638d2a6308354c0bdbc2c262d525218e64 (diff)
downloadCMake-a6841a967bc933101a351597b5b09363287ddfa6.zip
CMake-a6841a967bc933101a351597b5b09363287ddfa6.tar.gz
CMake-a6841a967bc933101a351597b5b09363287ddfa6.tar.bz2
CUDA: Factor out helper to filter implicit link libraries
Prepare to use it for other languages.
-rw-r--r--Modules/CMakeDetermineCUDACompiler.cmake20
-rw-r--r--Modules/CMakeTestCUDACompiler.cmake4
-rw-r--r--Modules/Internal/CMakeCUDAFilterImplicitLibs.cmake20
3 files changed, 25 insertions, 19 deletions
diff --git a/Modules/CMakeDetermineCUDACompiler.cmake b/Modules/CMakeDetermineCUDACompiler.cmake
index a495a28..657550a 100644
--- a/Modules/CMakeDetermineCUDACompiler.cmake
+++ b/Modules/CMakeDetermineCUDACompiler.cmake
@@ -439,23 +439,9 @@ elseif(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA")
"set(CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT \"${CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT}\")")
endif()
-# CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES is detected above as the list of
-# libraries that the CUDA compiler implicitly passes to the host linker.
-# CMake invokes the host linker directly and so needs to pass these libraries.
-# We filter out those that should not be passed unconditionally both here
-# and from CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES in CMakeTestCUDACompiler.
-set(CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES_EXCLUDE
- # The CUDA runtime libraries are controlled by CMAKE_CUDA_RUNTIME_LIBRARY.
- cudart cudart.lib
- cudart_static cudart_static.lib
- cudadevrt cudadevrt.lib
-
- # Dependencies of the CUDA static runtime library on Linux hosts.
- rt
- pthread
- dl
- )
-list(REMOVE_ITEM CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES ${CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES_EXCLUDE})
+include(Internal/CMakeCUDAFilterImplicitLibs)
+# Filter out implicit link libraries that should not be passed unconditionally.
+cmake_cuda_filter_implicit_libs(CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES)
if(CMAKE_CUDA_COMPILER_SYSROOT)
string(CONCAT _SET_CMAKE_CUDA_COMPILER_SYSROOT
diff --git a/Modules/CMakeTestCUDACompiler.cmake b/Modules/CMakeTestCUDACompiler.cmake
index 3fbf230..79ee20f 100644
--- a/Modules/CMakeTestCUDACompiler.cmake
+++ b/Modules/CMakeTestCUDACompiler.cmake
@@ -114,9 +114,9 @@ if("x${CMAKE_CUDA_SIMULATE_ID}" STREQUAL "xMSVC")
set(CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES "${CMAKE_CUDA_HOST_IMPLICIT_LINK_DIRECTORIES}")
endif()
+include(Internal/CMakeCUDAFilterImplicitLibs)
# Filter out implicit link libraries that should not be passed unconditionally.
-# See CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES_EXCLUDE in CMakeDetermineCUDACompiler.
-list(REMOVE_ITEM CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES ${CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES_EXCLUDE})
+cmake_cuda_filter_implicit_libs(CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES)
if(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA")
include(Internal/CMakeNVCCFilterImplicitInfo)
diff --git a/Modules/Internal/CMakeCUDAFilterImplicitLibs.cmake b/Modules/Internal/CMakeCUDAFilterImplicitLibs.cmake
new file mode 100644
index 0000000..60287af
--- /dev/null
+++ b/Modules/Internal/CMakeCUDAFilterImplicitLibs.cmake
@@ -0,0 +1,20 @@
+# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
+# file Copyright.txt or https://cmake.org/licensing for details.
+
+# In CMakeDetermineCUDACompiler and CMakeTestCUDACompiler we detect
+# libraries that the CUDA compiler implicitly passes to the host linker.
+# CMake invokes the host linker directly and so needs to pass these libraries.
+# Filter out implicit link libraries that should not be passed unconditionally.
+macro(cmake_cuda_filter_implicit_libs _var_CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES)
+ list(REMOVE_ITEM "${_var_CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES}"
+ # The CUDA runtime libraries are controlled by CMAKE_CUDA_RUNTIME_LIBRARY.
+ cudart cudart.lib
+ cudart_static cudart_static.lib
+ cudadevrt cudadevrt.lib
+
+ # Dependencies of the CUDA static runtime library on Linux hosts.
+ rt
+ pthread
+ dl
+ )
+endmacro()