1 cmake_minimum_required(VERSION 3.22.1) 2 project(opencl_backend) 3 4 set(CMAKE_CXX_STANDARD 14) 5 6 find_package(OpenCL) 7 if(OPENCL_FOUND) 8 message("OPENCL") 9 if ("${OPENCL_BACKEND}EMPTY" STREQUAL "EMPTY") 10 set (OPENCL_BACKEND "${CMAKE_SOURCE_DIR}") 11 message("OPENCL_BACKEND=${OPENCL_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 if (APPLE) 19 set(OPENCL_INCLUDE_DIR "-framework OpenCL") 20 set(OPENCL_LIB "-framework OpenCL") 21 else() 22 set(OPENCL_LIB "OpenCL") 23 endif() 24 25 include_directories( 26 ${OPENCL_BACKEND}/include 27 ${SHARED_BACKEND}/include 28 ${OPENCL_INCLUDE_DIR} 29 ) 30 link_directories( 31 ${CMAKE_BINARY_DIR} 32 ) 33 34 add_library(opencl_backend SHARED 35 ${SHARED_BACKEND}/cpp/shared.cpp 36 ${OPENCL_BACKEND}/cpp/opencl_backend.cpp 37 ) 38 39 target_link_libraries(opencl_backend 40 ${OPENCL_LIB} 41 ) 42 43 add_executable(opencl_info 44 ${OPENCL_BACKEND}/cpp/info.cpp 45 ) 46 47 target_link_libraries(opencl_info 48 opencl_backend 49 ${OPENCL_LIB} 50 ) 51 add_custom_target(opencl_natives DEPENDS opencl_info opencl_backend) 52 add_custom_target(copy_opencl_libs DEPENDS opencl_info opencl_backend 53 COMMAND cp ${CMAKE_BINARY_DIR}/opencl/libopencl_backend.* ${HAT_TARGET} 54 COMMAND cp ${CMAKE_BINARY_DIR}/opencl/opencl_info ${HAT_TARGET} 55 ) 56 add_dependencies(copy_libs copy_opencl_libs) 57 58 endif()