if(DEFINED ANDROID_ABI)
    set(ONNX_RUNTIME_ROOTDIR "${CMAKE_CURRENT_LIST_DIR}/../onnxruntime_prebuilt/android")
elseif(MSVC_VERSION)
    if(INFERENCE_HELPER_ENABLE_ONNX_RUNTIME_CUDA)
        set(ONNX_RUNTIME_ROOTDIR "${CMAKE_CURRENT_LIST_DIR}/../onnxruntime_prebuilt/win-x64-gpu")
    else()
        set(ONNX_RUNTIME_ROOTDIR "${CMAKE_CURRENT_LIST_DIR}/../onnxruntime_prebuilt/win-x64")
    endif()
else()
    if(${BUILD_SYSTEM} STREQUAL "armv7")
        message(FATAL_ERROR "[onnx_runtime] unsupported platform")
    elseif(${BUILD_SYSTEM} STREQUAL "aarch64")
        set(ONNX_RUNTIME_ROOTDIR "${CMAKE_CURRENT_LIST_DIR}/../onnxruntime_prebuilt/linux-aarch64")
    else()
        if(INFERENCE_HELPER_ENABLE_ONNX_RUNTIME_CUDA)
            set(ONNX_RUNTIME_ROOTDIR "${CMAKE_CURRENT_LIST_DIR}/../onnxruntime_prebuilt/linux-x64-gpu")
        else()
            set(ONNX_RUNTIME_ROOTDIR "${CMAKE_CURRENT_LIST_DIR}/../onnxruntime_prebuilt/linux-x64")
        endif()
    endif()
endif()

if(DEFINED ANDROID_ABI)
    add_library(ONNX_RUNTIME SHARED IMPORTED GLOBAL)
    set_target_properties(
        ONNX_RUNTIME
        PROPERTIES IMPORTED_LOCATION
        ${ONNX_RUNTIME_ROOTDIR}/jni/${ANDROID_ABI}/libonnxruntime.so
    )
    set(ONNX_RUNTIME_LIB ONNX_RUNTIME)
    set(ONNX_RUNTIME_INC "${ONNX_RUNTIME_ROOTDIR}/headers")
else()
    if(MSVC_VERSION)
        set(ONNX_RUNTIME_LIB ${ONNX_RUNTIME_ROOTDIR}/lib/onnxruntime.lib)
        if(INFERENCE_HELPER_ENABLE_ONNX_RUNTIME_CUDA)
            set(ONNX_RUNTIME_LIB ${ONNX_RUNTIME_LIB} ${ONNX_RUNTIME_ROOTDIR}/lib/onnxruntime_providers_cuda.lib)
        endif()
        # Copy dll files into the binary directory
        file(GLOB DLL_FILES files "${ONNX_RUNTIME_ROOTDIR}/lib/*.dll")
        file(COPY ${DLL_FILES} DESTINATION ${CMAKE_BINARY_DIR})
        # Ensure to use pre-built onnxruntime.dll rather than that in system folder
        file(COPY ${DLL_FILES} DESTINATION ${CMAKE_BINARY_DIR}/Debug)
        file(COPY ${DLL_FILES} DESTINATION ${CMAKE_BINARY_DIR}/RelWithDebInfo)
        file(COPY ${DLL_FILES} DESTINATION ${CMAKE_BINARY_DIR}/Release)
    else()
        set(ONNX_RUNTIME_LIB ${ONNX_RUNTIME_ROOTDIR}/lib/libonnxruntime.so)
    endif()

    set(ONNX_RUNTIME_INC "${ONNX_RUNTIME_ROOTDIR}/include" "${ONNX_RUNTIME_ROOTDIR}/include/onnxruntime/core/session")
endif()
