-
Notifications
You must be signed in to change notification settings - Fork 68
/
build_win_lite.sh
executable file
·153 lines (133 loc) · 4 KB
/
build_win_lite.sh
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/bash
set -x
set -eux
#git submodule update --init --recursive
MSVC_VERSION=""
HOST=$(uname | tr 'A-Z' 'a-z')
BUILD_TYPE="Release"
BUILD_DIR=build_win_lite
OUTPUT_DIR=output
COMPILE_ARCH=""
preset=""
PYTHON_VERSION=3.7
export SCRIPT_EXEC_MODE=win
export WIN_XCOMPILE_ROOT=$(pwd)/3rd_party/win_rootfs
export PLATFORM_NAME=x64
export USE_BMF_FFMPEG=0
[ $# -gt 0 ] && {
for arg in "$@"; do
case $arg in
clean)
rm -rf ${BUILD_DIR}
exit
;;
--msvc=2013|--msvc=2015|--msvc=2017|--msvc=2019|--msvc=2022)
MSVC_VERSION=${arg#--msvc=}
;;
--preset=x86-Debug|--preset=x86-Release|--preset=x64-Debug|--preset=x64-Release)
preset=${arg#--preset=}
;;
bmf_ffmpeg)
USE_BMF_FFMPEG="ON"
;;
*)
printf "arg:%s is not supported.\n" "${arg}"
exit 1
;;
esac
done
}
if [ -z "$MSVC_VERSION" ]; then
printf "Please specify the MSVC version using --msvc=[2013,2015,2017,2019,2022].\n"
exit 1
fi
if [ -z "$preset" ]; then
printf "Please specify the MSVC arch preset using --preset=[x86-Debug,x86-Release,x64-Debug,x64-Release].\n"
exit 1
fi
if [ "$preset" = "x64-Debug" ] || [ "$preset" = "x86-Debug" ]; then
BUILD_TYPE="Debug"
fi
if [ "$preset" = "x86-Debug" ] || [ "$preset" = "x86-Release" ]; then
export WIN_XCOMPILE_ARCH=x86
fi
if [ "$preset" = "x64-Debug" ] || [ "$preset" = "x64-Release" ]; then
export WIN_XCOMPILE_ARCH=x64
fi
case $MSVC_VERSION in
2013)
CMAKE_GENERATOR="Visual Studio 12 2013"
;;
2015)
CMAKE_GENERATOR="Visual Studio 14 2015"
;;
2017)
CMAKE_GENERATOR="Visual Studio 15 2017"
;;
2019)
CMAKE_GENERATOR="Visual Studio 16 2019"
;;
2022)
CMAKE_GENERATOR="Visual Studio 17 2022"
;;
*)
printf "Unsupported MSVC version: %s\n" $MSVC_VERSION
exit 1
;;
esac
git submodule update --init --recursive
if [ ! -d "3rd_party/win_rootfs" ]
then
(cd 3rd_party/ && wget https://github.com/BabitMF/bmf/releases/download/files/win_rootfs.tar.gz --no-check-certificate && tar zvxf win_rootfs.tar.gz)
fi
source ./version.sh
[ -d ${OUTPUT_DIR} ] && rm -rf ${OUTPUT_DIR}/* || mkdir -p ${OUTPUT_DIR}
[ -d ${BUILD_DIR} ] && rm -rf ${BUILD_DIR}/* || mkdir -p ${BUILD_DIR}
cd ${BUILD_DIR}
#x86-Debug x64-Debug x86-Release x64-Release
if [[ ${HOST} =~ msys_nt || ${HOST} =~ mingw ]]; then
echo "Building ${preset} ${BUILD_TYPE}"
[ -d ${preset} ] && rm -rf ${preset}/* || mkdir -p ${preset}
(
cd ${preset}
cmake -DCMAKE_VERBOSE_MAKEFILE=ON -G "${CMAKE_GENERATOR}" --preset ${preset} \
-DCMAKE_VERBOSE_MAKEFILE=ON \
-DBUILD_SHARED_LIBS=TRUE \
-DCMAKE_TOOLCHAIN_FILE=../../cmake/win-toolchain.cmake \
-DBMF_ENABLE_PYTHON=ON \
-DBMF_ENABLE_MOBILE=OFF \
-DBMF_ENABLE_FFMPEG=${USE_BMF_FFMPEG} \
-DBMF_ENABLE_CUDA=OFF \
-DRUN_HAVE_STD_REGEX=0 \
-DRUN_HAVE_POSIX_REGEX=0 \
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
-DBMF_BUILD_VERSION=${BMF_BUILD_VERSION} \
-DBMF_PYENV=${PYTHON_VERSION} \
-DBMF_BUILD_COMMIT=${BMF_BUILD_COMMIT} ../..
)
cat >../output/current_revision <<EOF
revision:$(git rev-parse HEAD)
version:none
pub data:$(date -u +"%Y-%m-%d %H:%M:%S")
arch:x86_64
region:none
source code repo name:$(git remote get-url origin)
compiled by msvc, build command: $0 $@
EOF
else
cmake -A ${PLATFORM_NAME} \
-DCMAKE_VERBOSE_MAKEFILE=ON \
-DBUILD_SHARED_LIBS=TRUE \
-DCMAKE_TOOLCHAIN_FILE=../cmake/win-toolchain.cmake \
-DBMF_ENABLE_PYTHON=ON \
-DBMF_ENABLE_MOBILE=OFF \
-DBMF_ENABLE_FFMPEG=${USE_BMF_FFMPEG} \
-DBMF_ENABLE_CUDA=OFF \
-DRUN_HAVE_STD_REGEX=0 \
-DRUN_HAVE_POSIX_REGEX=0 \
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
-DBMF_BUILD_VERSION=${BMF_BUILD_VERSION} \
-DBMF_BUILD_COMMIT=${BMF_BUILD_COMMIT} ..
make -j$(nproc)
cp -r ${BUILD_DIR}/output ${OUTPUT_DIR}
fi