Skip to content

Commit bcc668b

Browse files
committed
OSX
1 parent 5f31455 commit bcc668b

File tree

3 files changed

+230
-1
lines changed

3 files changed

+230
-1
lines changed

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ jobs:
113113
- TEST_DEPENDS=numpy==1.17.3
114114
workspaces:
115115
use: brew_cache
116+
cache:
117+
directories: $HOME/.ccache
116118

117119
# headless builds for MacOS
118120
- os: osx
@@ -125,6 +127,8 @@ jobs:
125127
- TEST_DEPENDS=numpy==1.17.3
126128
workspaces:
127129
use: brew_cache
130+
cache:
131+
directories: $HOME/.ccache
128132

129133
# Contrib builds for MacOS
130134
- os: osx
@@ -137,6 +141,8 @@ jobs:
137141
- TEST_DEPENDS=numpy==1.17.3
138142
workspaces:
139143
use: brew_cache
144+
cache:
145+
directories: $HOME/.ccache
140146

141147
# headless contrib builds for MacOS
142148
- os: osx
@@ -149,6 +155,8 @@ jobs:
149155
- TEST_DEPENDS=numpy==1.17.3
150156
workspaces:
151157
use: brew_cache
158+
cache:
159+
directories: $HOME/.ccache
152160

153161
# default builds for Linux
154162
- os: linux

travis_config.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ echo "=== Loading config.sh === "
77

88
# To see build progress
99
function build_wheel {
10-
build_bdist_wheel $@
10+
if [ -n "$IS_OSX" ]; then
11+
source travis_osx_build.sh
12+
build_bdist_osx_wheel $@
13+
else
14+
build_bdist_wheel $@
15+
fi
1116
}
1217

1318
function bdist_wheel_cmd {

travis_osx_build.sh

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
function pre_build_osx {
2+
local repo_dir=$(abspath ${1:-$REPO_DIR})
3+
local build_dir="$repo_dir/opencv/build"
4+
5+
if [ ! -d "$build_dir" ]; then
6+
mkdir "$build_dir"
7+
fi
8+
9+
cd "$build_dir"
10+
11+
local CMAKE_OPTS=(
12+
-G "Unix Makefiles"
13+
-DPYTHON3_EXECUTABLE="$(python3 "$repo_dir/tools/python_path.py" bin)"
14+
-DPYTHON3_INCLUDE_DIR="$(python3 "$repo_dir/tools/python_path.py" include)"
15+
-DPYTHON3_LIBRARY="$(python3 "$repo_dir/tools/python_path.py" lib)"
16+
-DBUILD_opencv_python3=ON
17+
-DBUILD_opencv_python2=OFF
18+
-DOPENCV_SKIP_PYTHON_LOADER=ON
19+
-DOPENCV_PYTHON3_INSTALL_PATH=python
20+
-DINSTALL_CREATE_DISTRIB=ON
21+
-DBUILD_opencv_apps=OFF
22+
-DBUILD_SHARED_LIBS=OFF
23+
-DBUILD_TESTS=OFF
24+
-DBUILD_PERF_TESTS=OFF
25+
-DBUILD_DOCS=OFF
26+
)
27+
if [ $ENABLE_JAVA -eq 0 ]; then
28+
CMAKE_OPTS+=(-DBUILD_opencv_java=OFF)
29+
fi
30+
if [ $ENABLE_CONTRIB -ne 0 ]; then
31+
CMAKE_OPTS+=(-DOPENCV_EXTRA_MODULES_PATH="$repo_dir/opencv_contrib/modules")
32+
fi
33+
if [ $ENABLE_HEADLESS -eq 0 ]; then
34+
export PKG_CONFIG_PATH="/usr/local/opt/qt/lib/pkgconfig":$PKG_CONFIG_PATH
35+
export CMAKE_PREFIX_PATH="/usr/local/Cellar/qt/5.15.2"
36+
CMAKE_OPTS+=(-DWITH_QT=5)
37+
else
38+
CMAKE_OPTS+=(
39+
-DWITH_WIN32UI=OFF
40+
-DWITH_QT=OFF
41+
-DWITH_GTK=OFF
42+
# -DWITH_MSMF=OFF
43+
)
44+
fi
45+
46+
# Clear ccache stats
47+
ccache -z
48+
49+
# Measure build time
50+
cmake "${CMAKE_OPTS[@]}" ..
51+
# $ pkg-config --libs opencv4 | sed -e 's| |\n|g' | sed -e 's|^-l||g' | tac
52+
CV_MODULES=(
53+
opencv_core
54+
opencv_imgproc
55+
opencv_photo
56+
opencv_xphoto
57+
opencv_flann
58+
opencv_features2d
59+
opencv_imgcodecs
60+
opencv_calib3d
61+
opencv_objdetect
62+
opencv_xobjdetect
63+
opencv_video
64+
opencv_ximgproc
65+
opencv_ml
66+
opencv_shape
67+
opencv_xfeatures2d
68+
opencv_viz
69+
opencv_videoio
70+
opencv_videostab
71+
opencv_plot
72+
opencv_dnn
73+
opencv_text
74+
opencv_datasets
75+
opencv_tracking
76+
opencv_surface_matching
77+
opencv_optflow
78+
opencv_superres
79+
opencv_phase_unwrapping
80+
opencv_structured_light
81+
opencv_stereo
82+
opencv_saliency
83+
opencv_rgbd
84+
opencv_reg
85+
opencv_rapid
86+
opencv_quality
87+
opencv_mcc
88+
opencv_line_descriptor
89+
opencv_intensity_transform
90+
opencv_img_hash
91+
opencv_hfs
92+
opencv_hdf
93+
opencv_fuzzy
94+
opencv_freetype
95+
opencv_face
96+
opencv_highgui
97+
opencv_dpm
98+
opencv_dnn_superres
99+
opencv_dnn_objdetect
100+
opencv_cvv
101+
opencv_ccalib
102+
opencv_bioinspired
103+
opencv_bgsegm
104+
opencv_aruco
105+
opencv_alphamat
106+
opencv_stitching
107+
opencv_gapi
108+
)
109+
for m in "${CV_MODULES[@]}"; do
110+
if make help | grep "$m"; then
111+
time make -j "$m"
112+
fi
113+
done
114+
time make -j
115+
116+
# Print ccache stats
117+
ccache -s
118+
}
119+
120+
function build_osx {
121+
# Copy compiled python module and 3rd-party stuff to package
122+
cp -f lib/python3/cv2*.so "$REPO/$NAME/cv2"
123+
124+
# Copy dependencies
125+
dep_libs=()
126+
127+
# There are libs in /System, /usr/lib and /usr/local/opt. Copy only non-system ones
128+
dep_list()
129+
{
130+
for lib in $(otool -X -L "$1" | grep -o '/usr/local/[^ ]*'); do
131+
found=0
132+
for l in "${dep_libs[@]}"; do
133+
if [ "$l" = "$lib" ]; then
134+
found=1
135+
break
136+
fi
137+
done
138+
if [ $found -eq 0 ]; then
139+
dep_libs+=( "$lib" )
140+
dep_list "$lib"
141+
fi
142+
done
143+
}
144+
145+
dep_list "$REPO/$NAME/cv2/"cv2*.so
146+
147+
if [ ! -d "$REPO/$NAME/cv2/.dylibs" ]; then
148+
mkdir -p "$REPO/$NAME/cv2/.dylibs"
149+
fi
150+
for lib in "${dep_libs[@]}"; do
151+
cp -f "$lib" "$REPO/$NAME/cv2/.dylibs"
152+
done
153+
154+
if [ $ENABLE_HEADLESS -eq 0 ]; then
155+
dep_libs=()
156+
dep_list /usr/local/Cellar/qt/5.15.2/plugins/platforms/libqcocoa.dylib
157+
if [ ! -d "$REPO/$NAME/cv2/qt/plugins/platforms" ]; then
158+
mkdir -p "$REPO/$NAME/cv2/qt/plugins/platforms"
159+
fi
160+
cp /usr/local/Cellar/qt/5.15.2/plugins/platforms/libqcocoa.dylib "$REPO/$NAME/cv2/qt/plugins/platforms"
161+
162+
for lib in "${dep_libs[@]}"; do
163+
cp -f "$lib" "$REPO/$NAME/cv2/.dylibs"
164+
done
165+
fi
166+
167+
cp -f "$REPO/$NAME/opencv/data/haarcascades/"*.xml "$REPO/$NAME/cv2/data"
168+
# Copy licenses
169+
cp -f "$REPO/$NAME/LICENSE.txt" "$REPO/$NAME/LICENSE-3RD-PARTY.txt" "$REPO/$NAME/cv2"
170+
171+
cd "$REPO/$NAME"
172+
# FIXME: Is there a way to package wheel without setup.py?
173+
cp setup.py tools/setup.py.bak
174+
cat tools/setup.py > setup.py
175+
export ENABLE_CONTRIB
176+
export ENABLE_HEADLESS
177+
export ENABLE_JAVA
178+
pip3 wheel .
179+
180+
echo -e 'Built wheels:'
181+
ls -1 *.whl
182+
183+
# Install built wheel to virtual env
184+
if [ ! -d "$TMP/testenv" ]; then
185+
mkdir -p "$TMP/testenv"
186+
fi
187+
rm -rf "$TMP/testenv"/*
188+
virtualenv -p "$(python3 "$REPO/$NAME/tools/python_path.py" bin)" "$TMP/testenv"
189+
source "$TMP/testenv/bin/activate"
190+
pip install numpy==1.17.3
191+
pip install ./opencv_*python*.whl
192+
pip install packaging
193+
194+
# Validate package
195+
cd tests
196+
python3 -m unittest test
197+
cd -
198+
deactivate
199+
# Error: This tool only supports Linux
200+
# auditwheel ./opencv_*python*.whl
201+
}
202+
203+
function build_bdist_osx_wheel {
204+
local repo_dir=${1:-$REPO_DIR}
205+
[ -z "$repo_dir" ] && echo "repo_dir not defined" && exit 1
206+
local wheelhouse=$(abspath ${WHEEL_SDIR:-wheelhouse})
207+
start_spinner
208+
pre_build_osx "$repo_dir"
209+
stop_spinner
210+
if [ -n "$BUILD_DEPENDS" ]; then
211+
pip install $(pip_opts) $BUILD_DEPENDS
212+
fi
213+
build_osx "$repo_dir"
214+
(cd $repo_dir && $cmd $wheelhouse)
215+
repair_wheelhouse $wheelhouse
216+
}

0 commit comments

Comments
 (0)