FindONNX.cmake 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. ocv_clear_vars(HAVE_ONNX)
  2. set(ONNXRT_ROOT_DIR "" CACHE PATH "ONNX Runtime install directory")
  3. # For now, check the old name ORT_INSTALL_DIR
  4. if(ORT_INSTALL_DIR AND NOT ONNXRT_ROOT_DIR)
  5. set(ONNXRT_ROOT_DIR ${ORT_INSTALL_DIR})
  6. endif()
  7. if(ONNXRT_ROOT_DIR)
  8. find_library(ORT_LIB onnxruntime
  9. ${ONNXRT_ROOT_DIR}/lib
  10. CMAKE_FIND_ROOT_PATH_BOTH)
  11. find_path(ORT_INCLUDE onnxruntime_cxx_api.h
  12. ${ONNXRT_ROOT_DIR}/include/onnxruntime/core/session
  13. CMAKE_FIND_ROOT_PATH_BOTH)
  14. endif()
  15. if(ORT_LIB AND ORT_INCLUDE)
  16. set(HAVE_ONNX TRUE)
  17. # For CMake output only
  18. set(ONNX_LIBRARIES "${ORT_LIB}" CACHE STRING "ONNX Runtime libraries")
  19. set(ONNX_INCLUDE_DIR "${ORT_INCLUDE}" CACHE STRING "ONNX Runtime include path")
  20. # Link target with associated interface headers
  21. set(ONNX_LIBRARY "onnxruntime" CACHE STRING "ONNX Link Target")
  22. ocv_add_library(${ONNX_LIBRARY} SHARED IMPORTED)
  23. set_target_properties(${ONNX_LIBRARY} PROPERTIES
  24. INTERFACE_INCLUDE_DIRECTORIES ${ORT_INCLUDE}
  25. IMPORTED_LOCATION ${ORT_LIB}
  26. IMPORTED_IMPLIB ${ORT_LIB})
  27. endif()
  28. if(NOT HAVE_ONNX)
  29. ocv_clear_vars(HAVE_ONNX ORT_LIB ORT_INCLUDE_DIR)
  30. endif()