onnxruntime.cmake
4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
function(download_onnxruntime)
include(FetchContent)
if(UNIX AND NOT APPLE)
# If you don't have access to the Internet,
# please pre-download onnxruntime
set(possible_file_locations
$ENV{HOME}/Downloads/onnxruntime-linux-x64-1.14.0.tgz
${PROJECT_SOURCE_DIR}/onnxruntime-linux-x64-1.14.0.tgz
${PROJECT_BINARY_DIR}/onnxruntime-linux-x64-1.14.0.tgz
/tmp/onnxruntime-linux-x64-1.14.0.tgz
/star-fj/fangjun/download/github/onnxruntime-linux-x64-1.14.0.tgz
)
set(onnxruntime_URL "https://github.com/microsoft/onnxruntime/releases/download/v1.14.0/onnxruntime-linux-x64-1.14.0.tgz")
set(onnxruntime_HASH "SHA256=92bf534e5fa5820c8dffe9de2850f84ed2a1c063e47c659ce09e8c7938aa2090")
# After downloading, it contains:
# ./lib/libonnxruntime.so.1.14.0
# ./lib/libonnxruntime.so, which is a symlink to lib/libonnxruntime.so.1.14.0
#
# ./include
# It contains all the needed header files
elseif(APPLE)
# If you don't have access to the Internet,
# please pre-download onnxruntime
set(possible_file_locations
$ENV{HOME}/Downloads/onnxruntime-osx-x86_64-1.14.0.tgz
${PROJECT_SOURCE_DIR}/onnxruntime-osx-x86_64-1.14.0.tgz
${PROJECT_BINARY_DIR}/onnxruntime-osx-x86_64-1.14.0.tgz
/tmp/onnxruntime-osx-x86_64-1.14.0.tgz
)
set(onnxruntime_URL "https://github.com/microsoft/onnxruntime/releases/download/v1.14.0/onnxruntime-osx-x86_64-1.14.0.tgz")
set(onnxruntime_HASH "SHA256=abd2056d56051e78263af37b8dffc3e6da110d2937af7a581a34d1a58dc58360")
# After downloading, it contains:
# ./lib/libonnxruntime.1.14.0.dylib
# ./lib/libonnxruntime.dylib, which is a symlink to lib/libonnxruntime.1.14.0.dylib
#
# ./include
# It contains all the needed header files
elseif(WIN32)
# If you don't have access to the Internet,
# please pre-download onnxruntime
set(possible_file_locations
$ENV{HOME}/Downloads/onnxruntime-win-x64-1.14.0.zip
${PROJECT_SOURCE_DIR}/onnxruntime-win-x64-1.14.0.zip
${PROJECT_BINARY_DIR}/onnxruntime-win-x64-1.14.0.zip
/tmp/onnxruntime-win-x64-1.14.0.zip
)
set(onnxruntime_URL "https://github.com/microsoft/onnxruntime/releases/download/v1.14.0/onnxruntime-win-x64-1.14.0.zip")
set(onnxruntime_HASH "SHA256=300eafef456748cde2743ee08845bd40ff1bab723697ff934eba6d4ce3519620")
# After downloading, it contains:
# ./lib/onnxruntime.{dll,lib,pdb}
# ./lib/onnxruntime_providers_shared.{dll,lib,pdb}
#
# ./include
# It contains all the needed header files
else()
message(FATAL_ERROR "Only support Linux and macOS at present. Will support other OSes later")
endif()
foreach(f IN LISTS possible_file_locations)
if(EXISTS ${f})
set(onnxruntime_URL "file://${f}")
break()
endif()
endforeach()
FetchContent_Declare(onnxruntime
URL ${onnxruntime_URL}
URL_HASH ${onnxruntime_HASH}
)
FetchContent_GetProperties(onnxruntime)
if(NOT onnxruntime_POPULATED)
message(STATUS "Downloading onnxruntime from ${onnxruntime_URL}")
FetchContent_Populate(onnxruntime)
endif()
message(STATUS "onnxruntime is downloaded to ${onnxruntime_SOURCE_DIR}")
find_library(location_onnxruntime onnxruntime
PATHS
"${onnxruntime_SOURCE_DIR}/lib"
)
message(STATUS "location_onnxruntime: ${location_onnxruntime}")
add_library(onnxruntime SHARED IMPORTED)
set_target_properties(onnxruntime PROPERTIES
IMPORTED_LOCATION ${location_onnxruntime}
INTERFACE_INCLUDE_DIRECTORIES "${onnxruntime_SOURCE_DIR}/include"
)
if(WIN32)
set_property(TARGET onnxruntime
PROPERTY
IMPORTED_IMPLIB "${onnxruntime_SOURCE_DIR}/lib/onnxruntime.lib"
)
file(COPY ${onnxruntime_SOURCE_DIR}/lib/onnxruntime.dll
DESTINATION
${CMAKE_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE}
)
endif()
if(UNIX AND NOT APPLE)
file(GLOB onnxruntime_lib_files "${onnxruntime_SOURCE_DIR}/lib/lib*")
elseif(APPLE)
file(GLOB onnxruntime_lib_files "${onnxruntime_SOURCE_DIR}/lib/lib*dylib")
elseif(WIN32)
file(GLOB onnxruntime_lib_files "${onnxruntime_SOURCE_DIR}/lib/*.dll")
endif()
message(STATUS "onnxruntime lib files: ${onnxruntime_lib_files}")
install(FILES ${onnxruntime_lib_files} DESTINATION lib)
endfunction()
download_onnxruntime()