forked from cansik/pyrealsense2-macosx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·199 lines (164 loc) · 4.07 KB
/
build.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/bin/bash
macos=""
tag=""
root=""
libusbPath=""
libusbTag=""
dist=""
disableDelocate=false
# get arguments
while getopts ":m:t:r:l:v:d:-:" opt; do
case ${opt} in
m)
macos=$OPTARG
;;
t)
tag=$OPTARG
;;
r)
root=$OPTARG
;;
l)
libusbPath=$OPTARG
;;
v)
libusbTag=$OPTARG
;;
d)
dist=$OPTARG
;;
-)
case "${OPTARG}" in
disable-delocate)
disableDelocate=true
;;
*)
echo "Invalid option: --${OPTARG}" >&2
exit 1
;;
esac
;;
\?)
echo "Invalid option: $OPTARG" 1>&2
exit 1
;;
:)
echo "Invalid option: $OPTARG requires an argument" 1>&2
exit 1
;;
esac
done
shift $((OPTIND - 1))
# set defaults
if [ -z "$macos" ]; then
macos="13"
fi
if [ -z "$tag" ]; then
tag="v2.54.1"
fi
if [ -z "$root" ]; then
root="librealsense"
fi
if [ -z "$libusbPath" ]; then
libusbPath="libusb"
fi
if [ -z "$libusbTag" ]; then
libusbTag="v1.0.26"
fi
if [ -z "$dist" ]; then
dist="dist"
fi
echo "build options:"
echo "tag: $tag"
echo "macos: $macos"
echo "root: $root"
echo "libusbPath: $libusbPath"
echo "libusbTag: $libusbTag"
echo "dist: $dist"
echo "disableDelocate: $disableDelocate"
echo ""
function replace_strings_in_file() {
SearchString=$1
ReplaceString=$2
FullPathToFile=$3
content=$(cat "$FullPathToFile" | sed "s|$SearchString|$ReplaceString|g")
echo "$content" >"$FullPathToFile"
}
# cleanup
rm -rf "$root"
rm -rf "$libusbPath"
echo "building libusb universal..."
git clone --depth 1 --branch "$libusbTag" "https://github.com/libusb/libusb" "$libusbPath"
libusb_include=$(realpath "$libusbPath/libusb")
pushd "$libusbPath/Xcode"
mkdir build
xcodebuild -scheme libusb -configuration Release -derivedDataPath "$PWD/build" MACOSX_DEPLOYMENT_TARGET="$macos"
pushd "build/Build/Products/Release"
libusb_binary=$(realpath "libusb-1.0.0.dylib")
popd
popd
echo ""
echo "Lib USB Paths"
echo $libusb_include
echo $libusb_binary
echo ""
# building librealsense
echo "creating librealsense python lib version $tag ..."
pythonWrapperDir="wrappers/python"
# clone
if [ "$tag" = "nightly" ]; then
echo "using nightly version..."
git clone --depth 1 "https://github.com/IntelRealSense/librealsense.git" $root
else
echo "using release version..."
git clone --depth 1 --branch $tag "https://github.com/IntelRealSense/librealsense.git" $root
fi
pushd $root
# build with python support
mkdir build
pushd build
cmake .. -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" \
-DCMAKE_THREAD_LIBS_INIT="-lpthread" \
-DCMAKE_BUILD_TYPE=RELEASE \
-DBUILD_PYTHON_BINDINGS=bool:true \
-DBUILD_SHARED_LIBS=ON \
-DBUILD_EXAMPLES=false \
-DBUILD_WITH_OPENMP=false \
-DBUILD_UNIT_TESTS=OFF \
-DBUILD_GRAPHICAL_EXAMPLES=OFF \
-DHWM_OVER_XU=false \
-DOPENSSL_ROOT_DIR=/opt/homebrew/opt/openssl \
-DCMAKE_OSX_DEPLOYMENT_TARGET="$macos" \
-DLIBUSB_INC="$libusb_include" \
-DLIBUSB_LIB="$libusb_binary" \
-G Xcode
xcodebuild -scheme realsense2 -configuration Release MACOSX_DEPLOYMENT_TARGET=$macos
xcodebuild -scheme pybackend2 -configuration Release MACOSX_DEPLOYMENT_TARGET=$macos
xcodebuild -scheme pyrealsense2 -configuration Release MACOSX_DEPLOYMENT_TARGET=$macos
popd
# copy libusb library
cp -a $libusb_binary $pythonWrapperDir/pyrealsense2
cp -a $libusb_binary build/Release
# copy realsense libraries
cp -a build/Release/*.dylib $pythonWrapperDir/pyrealsense2
# copy python libraries
cp -a build/wrappers/python/Release/*.so $pythonWrapperDir/pyrealsense2
# build bdist_wheel
pushd $pythonWrapperDir
python find_librs_version.py ../../ pyrealsense2
replace_strings_in_file "name=package_name" "name=\"pyrealsense2-mac\"" setup.py
replace_strings_in_file "https://github.com/IntelRealSense/librealsense" "https://github.com/yugasun/pyrealsense2-mac" setup.py
pip install wheel
python setup.py bdist_wheel --plat-name=macosx_"$macos"_0_universal2
# delocate wheel
if [ "$disableDelocate" = false ]; then
pip install delocate
delocate-wheel -v dist/*.whl
fi
popd
popd
# copy dist files
mkdir -p $dist
cp -a $root/wrappers/python/dist/* $dist
echo ""
echo "Finished! The build files are in $dist"