1 cmake_minimum_required(VERSION 3.22.1) 2 project(ptx_backend) 3 4 set(CMAKE_CXX_STANDARD 14) 5 6 find_package(CUDAToolkit) 7 if(CUDAToolkit_FOUND) 8 message("PTX") 9 if ("${PTX_BACKEND}EMPTY" STREQUAL "EMPTY") 10 set (PTX_BACKEND "${CMAKE_SOURCE_DIR}") 11 message("PTX_BACKEND=${PTX_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 ${PTX_BACKEND}/include 23 ) 24 25 link_directories( 26 ${CMAKE_BINARY_DIR} 27 ${CUDAToolkit_LIBRARY_DIR} 28 ) 29 30 add_library(ptx_backend SHARED 31 ${SHARED_BACKEND}/cpp/shared.cpp 32 ${PTX_BACKEND}/cpp/ptx_backend.cpp 33 ) 34 35 target_link_libraries(ptx_backend 36 -lcudart 37 -lcuda 38 ) 39 40 add_executable(ptx_info 41 ${PTX_BACKEND}/cpp/info.cpp 42 ) 43 44 target_link_libraries(ptx_info 45 ptx_backend 46 -lcudart 47 -lcuda 48 ) 49 add_custom_target(ptx_natives DEPENDS ptx_info ptx_backend) 50 51 add_custom_target(copy_ptx_libs DEPENDS ptx_info ptx_backend 52 COMMAND cp ${CMAKE_BINARY_DIR}/ptx/libptx_backend.* ${HAT_TARGET} 53 COMMAND cp ${CMAKE_BINARY_DIR}/ptx/ptx_info ${HAT_TARGET} 54 ) 55 add_dependencies(copy_libs copy_ptx_libs) 56 endif() 57 58