diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c5ecf326a..9d44ba9a89 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,24 +70,6 @@ find_package(OpenCV REQUIRED COMPONENTS core imgproc imgcodecs) find_package(ZLIB REQUIRED) find_package(MaaDerpLearning REQUIRED) find_package(asio REQUIRED) - -find_path(ONNXRuntime_INCLUDE_DIR NAMES onnxruntime/core/session/onnxruntime_c_api.h) -find_library(ONNXRuntime_LIBRARY NAMES onnxruntime) -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args( - ONNXRuntime - REQUIRED_VARS ONNXRuntime_LIBRARY ONNXRuntime_INCLUDE_DIR -) -if(ONNXRuntime_FOUND) - set(ONNXRuntime_INCLUDE_DIRS ${ONNXRuntime_INCLUDE_DIR}) - if(NOT TARGET ONNXRuntime::ONNXRuntime) - add_library(ONNXRuntime::ONNXRuntime UNKNOWN IMPORTED) - set_target_properties(ONNXRuntime::ONNXRuntime PROPERTIES - IMPORTED_LOCATION "${ONNXRuntime_LIBRARY}" - INTERFACE_INCLUDE_DIRECTORIES "${ONNXRuntime_INCLUDE_DIR}" - ) - endif() -endif() find_package(ONNXRuntime) target_link_libraries(MaaCore ${OpenCV_LIBS} MaaDerpLearning asio::asio ZLIB::ZLIB ONNXRuntime::ONNXRuntime header_only_libraries) diff --git a/cmake/FindONNXRuntime.cmake b/cmake/FindONNXRuntime.cmake new file mode 100644 index 0000000000..c40452bddb --- /dev/null +++ b/cmake/FindONNXRuntime.cmake @@ -0,0 +1,20 @@ +find_path(ONNXRuntime_INCLUDE_DIR NAMES onnxruntime/core/session/onnxruntime_c_api.h) + +find_library(ONNXRuntime_LIBRARY NAMES onnxruntime) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( + ONNXRuntime + REQUIRED_VARS ONNXRuntime_LIBRARY ONNXRuntime_INCLUDE_DIR +) + +if(ONNXRuntime_FOUND) + set(ONNXRuntime_INCLUDE_DIRS ${ONNXRuntime_INCLUDE_DIR}) + if(NOT TARGET ONNXRuntime::ONNXRuntime) + add_library(ONNXRuntime::ONNXRuntime UNKNOWN IMPORTED) + set_target_properties(ONNXRuntime::ONNXRuntime PROPERTIES + IMPORTED_LOCATION "${ONNXRuntime_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${ONNXRuntime_INCLUDE_DIR}" + ) + endif() +endif() \ No newline at end of file