CMakeLists.txt 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. if(OPENCV_SKIP_SAMPLES_SYCL)
  2. return()
  3. endif()
  4. ocv_install_example_src(sycl *.cpp *.hpp CMakeLists.txt)
  5. set(OPENCV_SYCL_SAMPLES_REQUIRED_DEPS
  6. opencv_core
  7. opencv_imgproc
  8. opencv_imgcodecs
  9. opencv_videoio
  10. opencv_highgui)
  11. ocv_check_dependencies(${OPENCV_SYCL_SAMPLES_REQUIRED_DEPS})
  12. if(NOT BUILD_EXAMPLES OR NOT OCV_DEPENDENCIES_FOUND OR OPENCV_SKIP_SAMPLES_BUILD_SYCL)
  13. return()
  14. endif()
  15. if(CMAKE_VERSION VERSION_LESS "3.5")
  16. message(STATUS "SYCL samples require CMake 3.5+")
  17. return()
  18. endif()
  19. cmake_policy(VERSION 3.5)
  20. find_package(SYCL QUIET) # will oneAPI support this straightforward way?
  21. if(NOT SYCL_FOUND AND NOT OPENCV_SKIP_SAMPLES_SYCL_ONEDNN)
  22. # lets try scripts from oneAPI:oneDNN component
  23. if(NOT DEFINED DNNLROOT AND DEFINED ENV{DNNLROOT})
  24. set(DNNLROOT "$ENV{DNNLROOT}")
  25. endif()
  26. # Some verions of called script violate CMake policy and may emit unrecoverable CMake errors
  27. # Use OPENCV_SKIP_SAMPLES_SYCL=1 / OPENCV_SKIP_SAMPLES_SYCL_ONEDNN to bypass this
  28. find_package(dnnl CONFIG QUIET HINTS "${DNNLROOT}")
  29. endif()
  30. if(NOT SYCL_FOUND AND NOT OPENCV_SKIP_SAMPLES_SYCL_COMPUTECPP)
  31. # lets try this SYCL SDK too: https://github.com/codeplaysoftware/computecpp-sdk
  32. find_package(ComputeCpp QUIET)
  33. if(ComputeCpp_FOUND)
  34. set(SYCL_TARGET ComputeCpp::ComputeCpp)
  35. set(SYCL_FLAGS ${ComputeCpp_FLAGS})
  36. set(SYCL_INCLUDE_DIRS ${ComputeCpp_INCLUDE_DIRS})
  37. set(SYCL_LIBRARIES ${ComputeCpp_LIBRARIES})
  38. endif()
  39. endif()
  40. if(OPENCV_CMAKE_DEBUG_SYCL)
  41. ocv_cmake_dump_vars("SYCL") # OpenCV source tree is required
  42. endif()
  43. if(NOT SYCL_TARGET)
  44. message(STATUS "SYCL/OpenCL samples are skipped: SYCL SDK is required")
  45. message(STATUS " - check configuration of SYCL_DIR/SYCL_ROOT/CMAKE_MODULE_PATH")
  46. message(STATUS " - ensure that right compiler is selected from SYCL SDK (e.g, clang++): CMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}")
  47. return()
  48. endif()
  49. project(sycl_samples)
  50. if(SYCL_FLAGS) # "target_link_libraries(... ${SYCL_TARGET})" is not enough. Hacking...
  51. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SYCL_FLAGS}")
  52. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${SYCL_FLAGS}")
  53. endif()
  54. ocv_include_modules_recurse(${OPENCV_SYCL_SAMPLES_REQUIRED_DEPS})
  55. ocv_include_directories(${OpenCL_INCLUDE_DIR})
  56. file(GLOB all_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp)
  57. foreach(sample_filename ${all_samples})
  58. ocv_define_sample(tgt ${sample_filename} sycl)
  59. ocv_target_link_libraries(${tgt} PRIVATE
  60. ${OPENCV_LINKER_LIBS}
  61. ${OPENCV_SYCL_SAMPLES_REQUIRED_DEPS}
  62. ${SYCL_TARGET})
  63. if(COMMAND add_sycl_to_target) # ComputeCpp
  64. add_sycl_to_target(TARGET ${tgt} SOURCES ${sample_filename})
  65. endif()
  66. endforeach()