xref: /llvm-project/offload/plugins-nextgen/cuda/CMakeLists.txt (revision 300e5b91144249a5b142b02d6331fcb33e13cf1d)
1# Create the library and add the default arguments.
2add_target_library(omptarget.rtl.cuda CUDA)
3
4target_sources(omptarget.rtl.cuda PRIVATE src/rtl.cpp)
5
6find_package(CUDAToolkit QUIET)
7if(CUDAToolkit_FOUND AND NOT "cuda" IN_LIST LIBOMPTARGET_DLOPEN_PLUGINS)
8  message(STATUS "Building CUDA plugin linked against libcuda")
9  target_link_libraries(omptarget.rtl.cuda PRIVATE CUDA::cuda_driver)
10else()
11  message(STATUS "Building CUDA plugin for dlopened libcuda")
12  target_include_directories(omptarget.rtl.cuda PRIVATE dynamic_cuda)
13  target_sources(omptarget.rtl.cuda PRIVATE dynamic_cuda/cuda.cpp)
14endif()
15
16# Configure testing for the CUDA plugin. We will build tests if we could a
17# functional NVIDIA GPU on the system, or if manually specifies by the user.
18option(LIBOMPTARGET_FORCE_NVIDIA_TESTS "Build NVIDIA libomptarget tests" OFF)
19if (LIBOMPTARGET_FOUND_NVIDIA_GPU OR LIBOMPTARGET_FORCE_NVIDIA_TESTS)
20  message(STATUS "Enable tests using CUDA plugin")
21  set(LIBOMPTARGET_SYSTEM_TARGETS
22      "${LIBOMPTARGET_SYSTEM_TARGETS} nvptx64-nvidia-cuda nvptx64-nvidia-cuda-LTO" PARENT_SCOPE)
23  list(APPEND LIBOMPTARGET_TESTED_PLUGINS "omptarget.rtl.cuda")
24  set(LIBOMPTARGET_TESTED_PLUGINS "${LIBOMPTARGET_TESTED_PLUGINS}" PARENT_SCOPE)
25else()
26  message(STATUS "Not generating NVIDIA tests, no supported devices detected."
27                   " Use 'LIBOMPTARGET_FORCE_NVIDIA_TESTS' to override.")
28endif()
29