Skip to content

Commit

Permalink
COMP: Modernize CUDA integration using FindCUDAToolkit CMake module
Browse files Browse the repository at this point in the history
For reference, CUDA support for Visual Studio generators was introduced
in CMake 3.9.
See https://cmake.org/cmake/help/latest/release/3.9.html#languages
  • Loading branch information
jcfr committed Feb 12, 2024
1 parent 7b65a85 commit 6e3491f
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions libautoscoper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,22 @@ list(APPEND libautoscoper_SOURCES
)

if(Autoscoper_RENDERING_BACKEND STREQUAL "CUDA")
find_package(CUDA REQUIRED)
# CUDA 10.2 supports C++ up to version 14
# See https://docs.nvidia.com/cuda/archive/10.2/cuda-c-programming-guide/index.html#c-cplusplus-language-support
set(CMAKE_CUDA_STANDARD 14)
set(CMAKE_CUDA_STANDARD_REQUIRED TRUE)
enable_language(CUDA)
find_package(CUDAToolkit REQUIRED)
include(${CMAKE_CURRENT_SOURCE_DIR}/src/gpu/cuda/CMakeLists.txt)
# Ensure calls to "target_link_libraries()" used in "CUDA_ADD_LIBRARY()" also
# specify a scope keyword.
set(CUDA_LINK_LIBRARIES_KEYWORD "PUBLIC")
CUDA_ADD_LIBRARY(libautoscoper STATIC ${libautoscoper_SOURCES} ${libautoscoper_HEADERS} ${cuda_HEADERS} ${cuda_SOURCES} ${cuda_KERNEL_HEADERS} ${cuda_KERNEL})
add_library(libautoscoper STATIC ${libautoscoper_SOURCES} ${libautoscoper_HEADERS} ${cuda_HEADERS} ${cuda_SOURCES} ${cuda_KERNEL_HEADERS} ${cuda_KERNEL})
target_include_directories(libautoscoper PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/gpu/cuda/cutil)
# Explicitly linking against CUDA_LIBRARIES is already done in "CUDA_ADD_LIBRARY()".
target_link_libraries(libautoscoper PUBLIC
CUDA::cudart_static
)
# The use of multiple .h and .cu files implies separate compilation units
set_target_properties(libautoscoper PROPERTIES
CMAKE_CUDA_SEPARABLE_COMPILATION ON
)
elseif(Autoscoper_RENDERING_BACKEND STREQUAL "OpenCL")
if(Autoscoper_OPENCL_USE_ICD_LOADER)
find_package(OpenCLHeaders REQUIRED)
Expand Down

0 comments on commit 6e3491f

Please sign in to comment.