mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-05 21:31:08 -06:00
Previously we dropped non-target items from the device link line because nvcc rejects paths to shared library files, and only with target items do we know the kind of library. However, this also prevents projects from linking to system-provided libraries like `cublas_device` that contain device code. Fix this by passing more link items to device linking. Items that are not file paths, such as `-lfoo`, can simply be passed unconditionally. Items that are targets known to be shared libraries can still be skipped. Items that are paths to library files can be passed directly if they end in `.a`. Otherwise, pass them using `-Xnvlink` to bypass nvcc's front-end. The nvlink tool knows to ignore shared library files. Issue: #16317
16 lines
701 B
CMake
16 lines
701 B
CMake
cmake_minimum_required(VERSION 3.8)
|
|
project(CudaOnlyLinkSystemDeviceLibraries CUDA)
|
|
|
|
string(APPEND CMAKE_CUDA_FLAGS " -gencode arch=compute_35,code=compute_35 -gencode arch=compute_35,code=sm_35")
|
|
set(CMAKE_CUDA_STANDARD 11)
|
|
|
|
add_executable(CudaOnlyLinkSystemDeviceLibraries main.cu)
|
|
set_target_properties( CudaOnlyLinkSystemDeviceLibraries
|
|
PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
|
|
target_link_libraries( CudaOnlyLinkSystemDeviceLibraries PRIVATE cublas_device)
|
|
|
|
if(APPLE)
|
|
# Help the static cuda runtime find the driver (libcuda.dyllib) at runtime.
|
|
set_property(TARGET CudaOnlyLinkSystemDeviceLibraries PROPERTY BUILD_RPATH ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES})
|
|
endif()
|