microsoft/onnxruntime-extensions

Public

mirrored fromhttps://github.com/microsoft/onnxruntime-extensionsAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
nodeps

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

cmake/ext_ortlib.cmake

121lines · modecode

1# Copyright (c) Microsoft Corporation. All rights reserved.
2# Licensed under the MIT License.
3
4if(_ONNXRUNTIME_EMBEDDED)
5 set(ONNXRUNTIME_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/../include/onnxruntime/core/session)
6 set(ONNXRUNTIME_LIB_DIR "")
7elseif(ONNXRUNTIME_PKG_DIR)
8 set(ONNXRUNTIME_INCLUDE_DIR ${ONNXRUNTIME_PKG_DIR}/include)
9 set(ONNXRUNTIME_LIB_DIR ${ONNXRUNTIME_PKG_DIR}/lib)
10elseif(OCOS_ONNXRUNTIME_PKG_URI)
11 if (NOT OCOS_ONNXRUNTIME_VERSION)
12 message(FATAL_ERROR "OCOS_ONNXRUNTIME_PKG_URI is set but OCOS_ONNXRUNTIME_VERSION is not set")
13 endif()
14 set(ONNXRUNTIME_VER ${OCOS_ONNXRUNTIME_VERSION})
15 set(ONNXRUNTIME_URL ${OCOS_ONNXRUNTIME_PKG_URI})
16 message(STATUS "ONNX Runtime URL: ${OCOS_ONNXRUNTIME_PKG_URI}")
17 FetchContent_Declare(
18 onnxruntime
19 URL ${OCOS_ONNXRUNTIME_PKG_URI}
20 )
21
22 FetchContent_makeAvailable(onnxruntime)
23
24 if (ANDROID)
25 set(ONNXRUNTIME_INCLUDE_DIR ${onnxruntime_SOURCE_DIR}/headers)
26 set(ONNXRUNTIME_LIB_DIR ${onnxruntime_SOURCE_DIR}/jni/${ANDROID_ABI})
27 message(STATUS "Android onnxruntime inc=${ONNXRUNTIME_INCLUDE_DIR} lib=${ONNXRUNTIME_LIB_DIR}")
28 else()
29 set(ONNXRUNTIME_INCLUDE_DIR ${onnxruntime_SOURCE_DIR}/include)
30 set(ONNXRUNTIME_LIB_DIR ${onnxruntime_SOURCE_DIR}/lib)
31 endif()
32else()
33 message(STATUS "CMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}")
34 message(STATUS "CMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM}")
35
36 # 1.16.1 is the latest ORT release.
37 if (OCOS_ONNXRUNTIME_VERSION)
38 set(ONNXRUNTIME_VER ${OCOS_ONNXRUNTIME_VERSION})
39 else()
40 set(ONNXRUNTIME_VER "1.19.2") # need to check if android package of this version is available too.
41 endif()
42
43 if (ANDROID)
44 set(ort_fetch_URL "https://repo1.maven.org/maven2/com/microsoft/onnxruntime/onnxruntime-android/${ONNXRUNTIME_VER}/onnxruntime-android-${ONNXRUNTIME_VER}.aar")
45 elseif(IOS)
46 set(ort_fetch_URL "https://onnxruntimepackages.z14.web.core.windows.net/pod-archive-onnxruntime-c-${ONNXRUNTIME_VER}.zip")
47 else()
48 if(APPLE)
49 set(ONNXRUNTIME_URL "v${ONNXRUNTIME_VER}/onnxruntime-osx-universal2-${ONNXRUNTIME_VER}.tgz")
50 elseif(WIN32)
51 set(ONNXRUNTIME_BINARY_PLATFORM "x64")
52
53 # override if generator platform is set
54 if (CMAKE_GENERATOR_PLATFORM)
55 if (CMAKE_GENERATOR_PLATFORM STREQUAL "Win32")
56 set(ONNXRUNTIME_BINARY_PLATFORM "x86")
57 elseif (CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64" OR CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64EC")
58 set(ONNXRUNTIME_BINARY_PLATFORM "arm64")
59 elseif (CMAKE_GENERATOR_PLATFORM STREQUAL "ARM")
60 set(ONNXRUNTIME_BINARY_PLATFORM "arm")
61 endif()
62 elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "ARM64")
63 # or if building on arm64 machine
64 set(ONNXRUNTIME_BINARY_PLATFORM "arm64")
65 endif()
66
67 if (OCOS_USE_CUDA)
68 set(ONNXRUNTIME_URL "v${ONNXRUNTIME_VER}/onnxruntime-win-${ONNXRUNTIME_BINARY_PLATFORM}-gpu-${ONNXRUNTIME_VER}.zip")
69 else()
70 set(ONNXRUNTIME_URL "v${ONNXRUNTIME_VER}/onnxruntime-win-${ONNXRUNTIME_BINARY_PLATFORM}-${ONNXRUNTIME_VER}.zip")
71 endif()
72 else()
73 # Linux or other, using Linux package to retrieve the headers
74 if (OCOS_USE_CUDA)
75 set(ONNXRUNTIME_URL "v${ONNXRUNTIME_VER}/onnxruntime-linux-x64-gpu-${ONNXRUNTIME_VER}.tgz")
76 else()
77 set(ONNXRUNTIME_URL "v${ONNXRUNTIME_VER}/onnxruntime-linux-x64-${ONNXRUNTIME_VER}.tgz")
78 endif()
79
80 if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
81 set(ONNXRUNTIME_URL "v${ONNXRUNTIME_VER}/onnxruntime-linux-aarch64-${ONNXRUNTIME_VER}.tgz")
82 endif()
83 endif()
84
85 set(ort_fetch_URL "https://github.com/microsoft/onnxruntime/releases/download/${ONNXRUNTIME_URL}")
86 endif()
87
88 message(STATUS "ONNX Runtime URL: ${ort_fetch_URL}")
89 FetchContent_Declare(
90 onnxruntime
91 URL ${ort_fetch_URL}
92 )
93
94 FetchContent_makeAvailable(onnxruntime)
95
96 if (ANDROID)
97 set(ONNXRUNTIME_INCLUDE_DIR ${onnxruntime_SOURCE_DIR}/headers)
98 set(ONNXRUNTIME_LIB_DIR ${onnxruntime_SOURCE_DIR}/jni/${ANDROID_ABI})
99 message(STATUS "Android onnxruntime inc=${ONNXRUNTIME_INCLUDE_DIR} lib=${ONNXRUNTIME_LIB_DIR}")
100 elseif(IOS)
101 set(ONNXRUNTIME_INCLUDE_DIR ${onnxruntime_SOURCE_DIR}/Headers)
102 # TODO Update once CMake supports finding and linking to .xcframeworks, possibly in 3.28.
103 # https://gitlab.kitware.com/cmake/cmake/-/issues/21752
104 # https://gitlab.kitware.com/cmake/cmake/-/merge_requests/8619
105 # https://gitlab.kitware.com/cmake/cmake/-/merge_requests/8661
106 if(CMAKE_OSX_SYSROOT STREQUAL "iphoneos")
107 set(ONNXRUNTIME_LIB_DIR ${onnxruntime_SOURCE_DIR}/onnxruntime.xcframework/ios-arm64)
108 elseif(CMAKE_OSX_SYSROOT STREQUAL "iphonesimulator")
109 set(ONNXRUNTIME_LIB_DIR ${onnxruntime_SOURCE_DIR}/onnxruntime.xcframework/ios-arm64_x86_64-simulator)
110 else()
111 message(FATAL_ERROR "Unsupported CMAKE_OSX_SYSROOT value: ${CMAKE_OSX_SYSROOT}")
112 endif()
113 else()
114 set(ONNXRUNTIME_INCLUDE_DIR ${onnxruntime_SOURCE_DIR}/include)
115 set(ONNXRUNTIME_LIB_DIR ${onnxruntime_SOURCE_DIR}/lib)
116 endif()
117endif()
118
119if(NOT EXISTS ${ONNXRUNTIME_INCLUDE_DIR})
120 message(FATAL_ERROR "ONNX Runtime headers not found at ${ONNXRUNTIME_INCLUDE_DIR}")
121endif()
122