MNN/package_scripts/win/build_lib.ps1

110 lines
3.0 KiB
PowerShell
Raw Normal View History

2020-11-06 11:05:52 +08:00
# MNN
# |-- Debug
# | |--- MD
# | |--- MT
# | |--- Static
# |
# |-- Release
# |--- MD
# |--- MT
# |--- Static
Param(
[Parameter(Mandatory=$true)][String]$path,
2021-04-28 18:02:10 +08:00
[String]$backends
2020-11-06 11:05:52 +08:00
)
2021-04-28 18:02:10 +08:00
# build process may failed because of lnk1181, but be success when run again
# Run expr, return if success, otherwise try again until try_times
function Retry([String]$expr, [Int]$try_times) {
$cnt = 0
do {
$cnt++
try {
Invoke-Expression $expr
return
} catch { }
} while($cnt -lt $try_times)
throw "Failed: $expr"
}
2020-11-06 11:05:52 +08:00
$erroractionpreference = "stop"
Remove-Item $path -Recurse -ErrorAction Ignore
mkdir -p $path
$PACKAGE_PATH = $(Resolve-Path $path).Path
#clear and create package directory
powershell ./schema/generate.ps1
pushd $PACKAGE_PATH
mkdir -p Debug\MD
mkdir -p Debug\MT
mkdir -p Debug\Static
mkdir -p Release\MD
mkdir -p Release\MT
mkdir -p Release\Static
popd
2021-01-06 16:29:37 +08:00
$CMAKE_ARGS = "-DMNN_SEP_BUILD=OFF -DMNN_BUILD_TRAIN=ON"
2021-04-28 18:02:10 +08:00
if ($backends -ne $null) {
Foreach ($backend in $backends.Split(",")) {
if ($backend -eq "opencl") {
$CMAKE_ARGS = "$CMAKE_ARGS -DMNN_OPENCL=ON"
} elseif ($backend -eq "vulkan") {
$CMAKE_ARGS = "$CMAKE_ARGS -DMNN_VULKAN=ON"
}
}
2020-11-06 11:05:52 +08:00
}
2021-04-28 18:02:10 +08:00
Remove-Item build -Recurse -ErrorAction Ignore
2020-11-06 11:05:52 +08:00
mkdir build
pushd build
2021-01-06 16:29:37 +08:00
##### Debug/MT ####
2020-11-06 11:05:52 +08:00
Remove-Item CMakeCache.txt -ErrorAction Ignore
Invoke-Expression "cmake -G Ninja $CMAKE_ARGS -DCMAKE_BUILD_TYPE=Debug -DMNN_WIN_RUNTIME_MT=ON .."
2021-04-28 18:02:10 +08:00
Retry "ninja" 2
2020-11-06 11:05:52 +08:00
cp MNN.lib $PACKAGE_PATH\Debug\MT
cp MNN.dll $PACKAGE_PATH\Debug\MT
cp MNN.pdb $PACKAGE_PATH\Debug\MT
rm MNN.*
2021-01-06 16:29:37 +08:00
##### Debug/MD ####
2020-11-06 11:05:52 +08:00
Remove-Item CMakeCache.txt -ErrorAction Ignore
Invoke-Expression "cmake -G Ninja $CMAKE_ARGS -DCMAKE_BUILD_TYPE=Debug -DMNN_WIN_RUNTIME_MT=OFF .."
2021-04-28 18:02:10 +08:00
Retry "ninja" 2
2020-11-06 11:05:52 +08:00
cp MNN.lib $PACKAGE_PATH\Debug\MD
cp MNN.dll $PACKAGE_PATH\Debug\MD
cp MNN.pdb $PACKAGE_PATH\Debug\MD
rm MNN.*
2021-01-06 16:29:37 +08:00
##### Debug/Static ####
2020-11-06 11:05:52 +08:00
Remove-Item CMakeCache.txt -ErrorAction Ignore
Invoke-Expression "cmake -G Ninja $CMAKE_ARGS -DCMAKE_BUILD_TYPE=Debug -DMNN_WIN_RUNTIME_MT=OFF -DMNN_BUILD_SHARED_LIBS=OFF .."
2021-04-28 18:02:10 +08:00
Retry "ninja" 2
2020-11-06 11:05:52 +08:00
cp MNN.lib $PACKAGE_PATH\Debug\Static
rm MNN.*
2021-01-06 16:29:37 +08:00
##### Release/MT ####
2020-11-06 11:05:52 +08:00
Remove-Item CMakeCache.txt -ErrorAction Ignore
Invoke-Expression "cmake -G Ninja $CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release -DMNN_WIN_RUNTIME_MT=ON .."
2021-04-28 18:02:10 +08:00
Retry "ninja" 2
2020-11-06 11:05:52 +08:00
cp MNN.lib $PACKAGE_PATH\Release\MT
cp MNN.dll $PACKAGE_PATH\Release\MT
cp MNN.pdb $PACKAGE_PATH\Release\MT
rm MNN.*
2021-01-06 16:29:37 +08:00
##### Release/MD ####
2020-11-06 11:05:52 +08:00
Remove-Item CMakeCache.txt -ErrorAction Ignore
Invoke-Expression "cmake -G Ninja $CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release -DMNN_WIN_RUNTIME_MT=OFF .."
2021-04-28 18:02:10 +08:00
Retry "ninja" 2
2020-11-06 11:05:52 +08:00
cp MNN.lib $PACKAGE_PATH\Release\MD
cp MNN.dll $PACKAGE_PATH\Release\MD
cp MNN.pdb $PACKAGE_PATH\Release\MD
rm MNN.*
2021-01-06 16:29:37 +08:00
##### Release/Static ####
2020-11-06 11:05:52 +08:00
Remove-Item CMakeCache.txt -ErrorAction Ignore
Invoke-Expression "cmake -G Ninja $CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release -DMNN_WIN_RUNTIME_MT=OFF -DMNN_BUILD_SHARED_LIBS=OFF .."
2021-04-28 18:02:10 +08:00
Retry "ninja" 2
2020-11-06 11:05:52 +08:00
cp MNN.lib $PACKAGE_PATH\Release\Static
popd