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 10 if ("${CUDA_BACKEND}EMPTY" STREQUAL "EMPTY") 11 set (CUDA_BACKEND "${CMAKE_SOURCE_DIR}") 12 message("CUDA_BACKEND=${CUDA_BACKEND}") 13 endif() 14 15 if ("${SHARED_BACKEND}EMPTY" STREQUAL "EMPTY") 16 set (SHARED_BACKEND "${CMAKE_SOURCE_DIR}/../shared") 17 message("SHARED_BACKEND=${SHARED_BACKEND}") 18 endif() 19 20 include_directories( 21 ${CUDAToolkit_INCLUDE_DIR} 22 ${SHARED_BACKEND}/include 23 ${CUDA_BACKEND}/include 24 ) 25 26 link_directories( 27 ${CMAKE_BINARY_DIR} 28 ${CUDAToolkit_LIBRARY_DIR} 29 ) 30 31 add_library(cuda_backend SHARED 32 ${SHARED_BACKEND}/cpp/shared.cpp 33 ${CUDA_BACKEND}/cpp/cuda_backend.cpp 34 ) 35 36 target_link_libraries(cuda_backend 37 -lcudart 38 -lcuda 39 ) 40 41 add_executable(cuda_info 42 ${CUDA_BACKEND}/cpp/info.cpp 43 ) 44 45 target_link_libraries(cuda_info 46 cuda_backend 47 -lcudart 48 -lcuda 49 ) 50 endif()