Skip to content

Commit

Permalink
Fix link library
Browse files Browse the repository at this point in the history
- Address review comment opentrack#1306 (comment)
- 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 microsoft/onnxruntime#3124 for reference
  • Loading branch information
gdolle committed Aug 1, 2021
1 parent 1a22815 commit 489b49e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
23 changes: 16 additions & 7 deletions cmake/FindONNXRuntime.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
26 changes: 16 additions & 10 deletions tracker-neuralnet/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
include(opentrack-opencv)
find_package(OpenCV QUIET)
find_package(OpenCV QUIET COMPONENTS imgproc core imgcodecs calib3d)
find_package(OpenMP QUIET) # Used to control number of onnx threads.
find_package(ONNXRuntime QUIET)

if(OpenCV_FOUND AND ONNXRuntime_FOUND AND OpenMP_FOUND)
otr_module(tracker-neuralnet)
target_include_directories(${self} SYSTEM PUBLIC
${OpenCV_INCLUDE_DIRS} "${ONNXRuntime_INCLUDE_DIRS}")
target_link_libraries(${self} "${ONNXRuntime_LIBRARIES}"
opentrack-cv opencv_imgproc opencv_core
opencv_imgcodecs opencv_calib3d
OpenMP::OpenMP_C)

target_include_directories(${self}
SYSTEM PRIVATE
${OpenCV_INCLUDE_DIRS}
${ONNXRuntime_INCLUDE_DIRS}
)
target_link_libraries(${self}
opentrack-cv
${ONNXRuntime_LIBRARIES}
${OpenCV_LIBS}
OpenMP::OpenMP_C
)
install(
FILES "models/head-localizer.onnx" "models/head-pose.onnx"
FILES "models/head-localizer.onnx"
"models/head-pose.onnx"
DESTINATION "${opentrack-libexec}/models"
PERMISSIONS ${opentrack-perms-file})
PERMISSIONS ${opentrack-perms-file}
)
endif()

0 comments on commit 489b49e

Please sign in to comment.