Skip to content

Commit

Permalink
add fallback for external ORT without find module
Browse files Browse the repository at this point in the history
  • Loading branch information
20DM committed Sep 13, 2024
1 parent f1429f2 commit 90159c9
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions cmake_files/LookUpONNXRT.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@

find_package(onnxruntime QUIET)

if(${onnxruntime_FOUND} AND NOT onnxruntime_INCLUDE_DIR)
find_path(onnxruntime_INCLUDE_DIR NAMES onnxruntime_cxx_api.h
HINTS
ENV onnxruntime_ROOT
ENV onnxruntime_ROOT_DIR
${CMAKE_INSTALL_PREFIX}/include
${KDE4_INCLUDE_DIR}
PATH_SUFFIXES onnxruntime
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(onnxruntime DEFAULT_MSG onnxruntime_INCLUDE_DIR TRUE)
set(onnxruntime_LIBRARIES onnxruntime)
get_filename_component(onnxruntime_INSTALL_PREFIX "${onnxruntime_INCLUDE_DIR}/../../" ABSOLUTE)
find_library(onnxruntime_LIBRARY onnxruntime PATHS "${onnxruntime_INSTALL_PREFIX}/lib")
add_library(${onnxruntime_LIBRARIES} SHARED IMPORTED)
set_target_properties(${onnxruntime_LIBRARIES} PROPERTIES IMPORTED_LOCATION "${onnxruntime_LIBRARY}")
set_target_properties(${onnxruntime_LIBRARIES} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${onnxruntime_INCLUDE_DIR}")
endif()

if(NOT ${onnxruntime_FOUND})
message(STATUS "ONNXrt not found. Attempt to install...")
EXECUTE_PROCESS( COMMAND uname -m COMMAND tr -d '\n' OUTPUT_VARIABLE ARCH )
Expand Down Expand Up @@ -30,9 +50,6 @@ if(NOT ${onnxruntime_FOUND})
set(onnxruntime_LIBRARIES onnxruntime)
add_library(${onnxruntime_LIBRARIES} SHARED IMPORTED GLOBAL)
set_target_properties(${onnxruntime_LIBRARIES} PROPERTIES IMPORTED_LOCATION ${onnxruntime_LIBRARY_DIR}/libonnxruntime.so)
message(STATUS "ORT-INCDIR=${onnxruntime_INCLUDE_DIR}")
message(STATUS "ORT-LIBDIR=${onnxruntime_LIBRARY_DIR}")
message(STATUS "ORT-LIB=${onnxruntime_LIBRARIES}")
set(onnxruntime_FOUND TRUE)
endif()

0 comments on commit 90159c9

Please sign in to comment.