summaryrefslogtreecommitdiffhomepage
path: root/cmake/FindONNXRuntime.cmake
diff options
context:
space:
mode:
authorGuillaume Dollé <dolle.guillaume@gmail.com>2021-08-01 16:02:00 +0200
committerGuillaume Dollé <dolle.guillaume@gmail.com>2021-08-01 16:02:00 +0200
commit489b49e98f013ca495ee8314718df24b67b0e825 (patch)
treed184e1301d6f57ab2ae464e5e75fd7bc76855ee9 /cmake/FindONNXRuntime.cmake
parent1a22815d82ddfbd4f5c1f3240fb13155f517d79c (diff)
Fix link library
- Address review comment https://github.com/opentrack/opentrack/pull/1306#discussion_r680484878 - Update ONNXRuntime module to use a specific `onnxruntime` target. - Use OpenCV components instead. NOTE: ONNXRuntinme may provide their own ONNXRuntimeConfig.cmake and ONNXRuntimeVersion.cmake in the future. See https://github.com/microsoft/onnxruntime/issues/3124 for reference
Diffstat (limited to 'cmake/FindONNXRuntime.cmake')
-rw-r--r--cmake/FindONNXRuntime.cmake23
1 files changed, 16 insertions, 7 deletions
diff --git a/cmake/FindONNXRuntime.cmake b/cmake/FindONNXRuntime.cmake
index 733bdb36..f485ecdd 100644
--- a/cmake/FindONNXRuntime.cmake
+++ b/cmake/FindONNXRuntime.cmake
@@ -13,10 +13,9 @@
# Output variable
# ---------------
#
-# ONNXRuntime_FOUND Variable indicating that ONNXRuntime has been
-# found.
-# ONNXRuntime_LIBRARIES Library implementing ONNXRuntime
-# ONNXRuntime_INCLUDE_DIRS Headers for ONNXRuntime
+# ONNXRuntime_FOUND True if headers and requested libraries were found
+# ONNXRuntime_LIBRARIES Component libraries to be linked.
+# ONNXRuntime_INCLUDE_DIRS Include directories.
find_library(ORT_LIB onnxruntime
CMAKE_FIND_ROOT_PATH_BOTH)
@@ -25,7 +24,17 @@ find_path(ORT_INCLUDE onnxruntime/core/session/onnxruntime_cxx_api.h
if(ORT_LIB AND ORT_INCLUDE)
set(ONNXRuntime_FOUND TRUE)
- # For CMake output only
- set(ONNXRuntime_LIBRARIES "${ORT_LIB}" CACHE STRING "ONNX Runtime libraries")
- set(ONNXRuntime_INCLUDE_DIRS "${ORT_INCLUDE}" CACHE STRING "ONNX Runtime include path")
+ set(ONNXRuntime_INCLUDE_DIRS "${ORT_INCLUDE}")
+
+ if(NOT TARGET onnxruntime)
+ add_library(onnxruntime UNKNOWN IMPORTED)
+ set_target_properties(onnxruntime PROPERTIES
+ IMPORTED_LOCATION "${ORT_LIB}"
+ INTERFACE_INCLUDE_DIRECTORIES "${ORT_INCLUDE}"
+ INTERFACE_LINK_LIBRARIES "onnxruntime")
+ list(APPEND ONNXRuntime_LIBRARIES onnxruntime)
+ endif()
endif()
+
+unset(ORT_LIB CACHE)
+unset(ORT_INCLUDE CACHE)