OpenCVDetectWebNN.cmake 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. if(NOT EMSCRIPTEN)
  2. if(WITH_WEBNN)
  3. ocv_check_environment_variables(WEBNN_HEADER_DIRS)
  4. ocv_check_environment_variables(WEBNN_INCLUDE_DIRS)
  5. ocv_check_environment_variables(WEBNN_LIBRARIES)
  6. if(NOT DEFINED WEBNN_HEADER_DIRS)
  7. set(WEBNN_HEADER_DIRS "$ENV{WEBNN_NATIVE_DIR}/gen/src/include")
  8. endif()
  9. if(NOT DEFINED WEBNN_INCLUDE_DIRS)
  10. set(WEBNN_INCLUDE_DIRS "$ENV{WEBNN_NATIVE_DIR}/../../src/include")
  11. endif()
  12. if(NOT DEFINED WEBNN_LIBRARIES)
  13. set(WEBNN_LIBRARIES "$ENV{WEBNN_NATIVE_DIR}/libwebnn_native.so;$ENV{WEBNN_NATIVE_DIR}/libwebnn_proc.so")
  14. endif()
  15. endif()
  16. try_compile(VALID_WEBNN
  17. "${OpenCV_BINARY_DIR}"
  18. SOURCES "${OpenCV_SOURCE_DIR}/cmake/checks/webnn.cpp"
  19. "$ENV{WEBNN_NATIVE_DIR}/gen/src/webnn/webnn_cpp.cpp"
  20. CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${WEBNN_INCLUDE_DIRS}\;${WEBNN_HEADER_DIRS}"
  21. "-DLINK_LIBRARIES:STRING=${WEBNN_LIBRARIES}"
  22. OUTPUT_VARIABLE TRY_OUT
  23. )
  24. else()
  25. try_compile(VALID_WEBNN
  26. "${OpenCV_BINARY_DIR}"
  27. SOURCES "${OpenCV_SOURCE_DIR}/cmake/checks/webnn.cpp"
  28. OUTPUT_VARIABLE TRY_OUT
  29. )
  30. endif()
  31. if(NOT VALID_WEBNN)
  32. if(NOT EMSCRIPTEN)
  33. message(WARNING "Can't use WebNN-native")
  34. return()
  35. else()
  36. message(WARNING "Can't use WebNN")
  37. return()
  38. endif()
  39. else()
  40. set(HAVE_WEBNN ON)
  41. message(STATUS "Set HAVE_WEBNN = ${HAVE_WEBNN}")
  42. endif()
  43. if(NOT EMSCRIPTEN)
  44. message(AUTHOR_WARNING "Use WebNN-native")
  45. else()
  46. message(AUTHOR_WARNING "Use WebNN")
  47. endif()