1 cmake_minimum_required(VERSION 3.22.1) 2 project(cuda_backend) 3 4 set(CMAKE_CXX_STANDARD 14) 5 6 find_package(CUDAToolkit) 7 if(CUDAToolkit_FOUND) 8 message("CUDA") 9 if ("${CUDA_BACKEND}EMPTY" STREQUAL "EMPTY") 10 set (CUDA_BACKEND "${CMAKE_SOURCE_DIR}") 11 message("CUDA_BACKEND=${CUDA_BACKEND}") 12 endif() 13 if ("${SHARED_BACKEND}EMPTY" STREQUAL "EMPTY") 14 set (SHARED_BACKEND "${CMAKE_SOURCE_DIR}/../shared") 15 message("SHARED_BACKEND=${SHARED_BACKEND}") 16 endif() 17 18 19 include_directories( 20 ${CUDAToolkit_INCLUDE_DIR} 21 ${SHARED_BACKEND}/include 22 ${CUDA_BACKEND}/include 23 ) 24 25 link_directories( 26 ${CMAKE_BINARY_DIR} 27 ${CUDAToolkit_LIBRARY_DIR} 28 ) 29 30 add_library(cuda_backend SHARED 31 ${SHARED_BACKEND}/cpp/shared.cpp 32 ${CUDA_BACKEND}/cpp/cuda_backend.cpp 33 ) 34 35 target_link_libraries(cuda_backend 36 -lcudart 37 -lcuda 38 ) 39 40 add_executable(cuda_info 41 ${CUDA_BACKEND}/cpp/info.cpp 42 ) 43 44 target_link_libraries(cuda_info 45 cuda_backend 46 -lcudart 47 -lcuda 48 ) 49 add_custom_target(cuda_natives DEPENDS cuda_info cuda_backend) 50 51 add_custom_target(copy_cuda_libs DEPENDS cuda_info cuda_backend 52 COMMAND cp ${CMAKE_BINARY_DIR}/cuda/libcuda_backend.* ${HAT_TARGET} 53 COMMAND cp ${CMAKE_BINARY_DIR}/cuda/cuda_info ${HAT_TARGET} 54 ) 55 add_dependencies(copy_libs copy_cuda_libs) 56 endif()