-
Notifications
You must be signed in to change notification settings - Fork 13
/
build-onnxruntime.bat
137 lines (121 loc) · 4 KB
/
build-onnxruntime.bat
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
:: build onnxruntime for windows by benjaminwan
:: x64 build_java, x86 Java is currently not supported on 32-bit x86 architecture
:: use in powershell
:: Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
:: & 'C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\Launch-VsDevShell.ps1' -SkipAutomaticLocation -HostArch amd64 -Arch amd64
@ECHO OFF
chcp 65001
cls
SETLOCAL EnableDelayedExpansion
IF "%1"=="" (
ECHO input VS_VER none, use v143
set VS_VER="v143"
) ^
ELSE (
ECHO input VS_VER:%1
set VS_VER="%1"
)
IF "%2"=="" (
ECHO input CRT none, use mt
set CRT="mt"
) ^
ELSE (
ECHO input CRT:%2
set CRT="%2"
)
call :cmakeParams "x64" %VS_VER% %CRT%
::call :cmakeParams "Win32" %VS_VER% %CRT%
GOTO:EOF
:getFileName
call set "libs=%%libs%% %~n1"
GOTO:EOF
:getFullPathAndName
call set "libs=%%libs%% %~1"
GOTO:EOF
:check_libexe_exists
::powershell -Command "if(Get-Command lib.exe -errorAction SilentlyContinue) {'true'} else {'false'}"
set pscmdline='powershell -Command "if(Get-Command lib.exe -errorAction SilentlyContinue) {'true'} else {'false'}"'
for /f %%a in (%pscmdline%) do (
set libexe_exists=%%a
)
GOTO:EOF
:getLibsList
set "InFile=onnxruntime.dir\Release\onnxruntime.tlog\link.read.1.tlog"
set "OutFile=libs_list.txt"
set "LikeLine=RELEASE\*.LIB"
powershell -Command "$data = foreach($line in gc %InFile%){ $line.split(" ")} $data | Out-File %OutFile%"
powershell -Command "$data = foreach($line in gc %OutFile%){ if($line -like '*%LikeLine%*') {$line}} $data | Out-File -Encoding ascii %OutFile%"
GOTO:EOF
:collectLibs
cmake --build . --config Release --target install
::del /s/q install\*test*.exe
copy install\include\onnxruntime\* install\include
rd /S /Q install\include\onnxruntime
ECHO set(OnnxRuntime_INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/include") > install/OnnxRuntimeConfig.cmake
ECHO include_directories(${OnnxRuntime_INCLUDE_DIRS}) >> install/OnnxRuntimeConfig.cmake
ECHO link_directories(${CMAKE_CURRENT_LIST_DIR}/lib) >> install/OnnxRuntimeConfig.cmake
ECHO set(OnnxRuntime_LIBS onnxruntime) >> install/OnnxRuntimeConfig.cmake
mkdir install-static\lib
xcopy install\include install-static\include /s /y /i
call :getLibsList
call :check_libexe_exists
IF "%libexe_exists%" == "true" (
ECHO "libexe_exists=%libexe_exists%"
set libs=
for /f "Delims=" %%a in (libs_list.txt) do (
call :getFullPathAndName %%a
)
) ELSE (
ECHO "libexe_exists=%libexe_exists%"
set libs=
for /f "Delims=" %%a in (libs_list.txt) do (
copy %%a install-static\lib
call :getFileName %%a
)
)
copy onnxruntime.dir\Release\onnxruntime.tlog\link.read.1.tlog install-static\link.log
ECHO set(OnnxRuntime_INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/include")>install-static\OnnxRuntimeConfig.cmake
ECHO include_directories(${OnnxRuntime_INCLUDE_DIRS})>>install-static\OnnxRuntimeConfig.cmake
ECHO link_directories(${CMAKE_CURRENT_LIST_DIR}/lib)>>install-static\OnnxRuntimeConfig.cmake
IF "%libexe_exists%" == "true" (
ECHO set(OnnxRuntime_LIBS onnxruntime.lib)>>install-static\OnnxRuntimeConfig.cmake
) ELSE (
ECHO set(OnnxRuntime_LIBS %libs%)>>install-static\OnnxRuntimeConfig.cmake
)
::IF "%libexe_exists%" == "true" (
:: lib.exe /OUT:install-static\lib\onnxruntime.lib %libs%
::)
GOTO:EOF
:cmakeParams
if "%~1" == "Win32" (
set MACHINE_FLAG="--x86"
)^
else (
set MACHINE_FLAG="--build_java"
)
IF "%~2" == "v142" (
set VS_FLAG=--cmake_generator "Visual Studio 16 2019"
) ^
ELSE (
set VS_FLAG=--cmake_generator "Visual Studio 17 2022"
)
IF "%~3" == "mt" (
set STATIC_CRT_FLAG="--enable_msvc_static_runtime"
) ^
ELSE (
set STATIC_CRT_FLAG=
)
python %~dp0\tools\ci_build\build.py --build_dir %~dp0\build-%~1-%~2-%~3 ^
--config Release ^
--parallel ^
--skip_tests ^
--build_shared_lib ^
%MACHINE_FLAG% ^
%VS_FLAG% ^
%STATIC_CRT_FLAG% ^
--cmake_extra_defines CMAKE_INSTALL_PREFIX=./install onnxruntime_BUILD_UNIT_TESTS=OFF
pushd "build-%~1-%~2-%~3"\Release
cmake --build . --config Release -j %NUMBER_OF_PROCESSORS%
call :collectLibs
popd
GOTO:EOF