forked from colmap/pycolmap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-wheels-linux.sh
executable file
·185 lines (152 loc) · 5.43 KB
/
build-wheels-linux.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
#!/bin/bash
# Installation based off of https://colmap.github.io/install.html (COLMAP)
# and https://github.com/mihaidusmanu/pycolmap#getting-started (pycolmap)
# and http://ceres-solver.org/installation.html (Ceres)
# However, the OS is centOS 7, instead of Ubuntu.
# Author: John Lambert (johnwlambert)
uname -a
echo "Current CentOS Version:"
cat /etc/centos-release
yum -y install wget
ls -ltrh /io/
# we cannot simply use `pip` or `python`, since points to old 2.7 version
PYBIN="/opt/python/$PYTHON_VERSION/bin"
PYVER_NUM=$($PYBIN/python -c "import sys;print(sys.version.split(\" \")[0])")
PYTHONVER="$(basename $(dirname $PYBIN))"
echo "Python bin path: $PYBIN"
echo "Python version number: $PYVER_NUM"
echo "Python version: $PYTHONVER"
export PATH=$PYBIN:$PATH
${PYBIN}/pip install auditwheel
PYTHON_EXECUTABLE=${PYBIN}/python
# We use distutils to get the include directory and the library path directly from the selected interpreter
# We provide these variables to CMake to hint what Python development files we wish to use in the build.
PYTHON_INCLUDE_DIR=$(${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())")
PYTHON_LIBRARY=$(${PYTHON_EXECUTABLE} -c "import distutils.sysconfig as sysconfig; print(sysconfig.get_config_var('LIBDIR'))")
CURRDIR=$(pwd)
echo "Num. processes to use for building: ${nproc}"
# ------ Install boost (build it staticly) ------
cd $CURRDIR
yum install -y wget libicu libicu-devel centos-release-scl-rh devtoolset-7-gcc-c++
# Download and install Boost-1.65.1
# colmap needs only program_options filesystem graph system unit_test_framework
mkdir -p boost && \
cd boost && \
wget -nv https://boostorg.jfrog.io/artifactory/main/release/1.65.1/source/boost_1_65_1.tar.gz && \
tar xzf boost_1_65_1.tar.gz && \
cd boost_1_65_1 && \
./bootstrap.sh --with-libraries=serialization,filesystem,thread,system,atomic,date_time,timer,chrono,program_options,regex,graph,test && \
./b2 -j$(nproc) cxxflags="-fPIC" runtime-link=static variant=release link=static install
# Boost should now be visible under /usr/local
ls -ltrh /usr/local
# ------ Install dependencies from the default Ubuntu repositories ------
cd $CURRDIR
yum install \
git \
cmake \
build-essential \
libboost-program-options-dev \
libboost-filesystem-dev \
libboost-graph-dev \
libboost-system-dev \
libboost-test-dev \
libeigen3-dev \
libsuitesparse-dev \
libfreeimage-dev \
libgoogle-glog-dev \
libgflags-dev \
libglew-dev \
libcgal-dev
# Note: `yum install gflags` will not work, since the version is too old (2.1)
# Note: `yum install glog` will also not work, since the version is too old
# Cloning and building https://github.com/google/glog.git will also not work, due to linker issues.
yum -y install gflags-devel glog-devel
cd $CURRDIR
# Using Eigen 3.3, not Eigen 3.4
wget https://gitlab.com/libeigen/eigen/-/archive/3.3.9/eigen-3.3.9.tar.gz
tar -xvzf eigen-3.3.9.tar.gz
export EIGEN_DIR="$CURRDIR/eigen-3.3.9"
# While Eigen is a header-only library, it still has to be built!
# Creates Eigen3Config.cmake from Eigen3Config.cmake.in
cd $EIGEN_DIR
mkdir build
cd build
cmake ..
ls -ltrh "$EIGEN_DIR/cmake/"
# ------ Install CERES solver ------
cd $CURRDIR
yum install libeigen3-dev # was not in COLMAP instructions
yum install libatlas-base-dev libsuitesparse-dev
yum install libgoogle-glog-dev libgflags-dev # was not in COLMAP instructions
git clone https://ceres-solver.googlesource.com/ceres-solver
cd ceres-solver
git checkout $(git describe --tags) # Checkout the latest release
mkdir build
cd build
cmake .. -DBUILD_TESTING=OFF \
-DBUILD_EXAMPLES=OFF \
-DEigen3_DIR="$EIGEN_DIR/cmake/"
make -j$(nproc)
make install
echo "PYTHON_EXECUTABLE:${PYTHON_EXECUTABLE}"
echo "PYTHON_INCLUDE_DIR:${PYTHON_INCLUDE_DIR}"
echo "PYTHON_LIBRARY:${PYTHON_LIBRARY}"
# ------ Fix broken dependencies ------
cd $CURRDIR
# try new boost install
yum install libboost-all-dev
yum install git
yum install cmake
yum install build-essential
yum install libboost-program-options-dev
yum install libboost-filesystem-dev
yum install libboost-graph-dev
yum install libboost-system-dev
yum install libboost-test-dev
yum install libeigen3-dev
yum install libsuitesparse-dev
# yum install libfreeimage-dev
yum install libgoogle-glog-dev
yum install libgflags-dev
yum install libglew-dev
yum install libcgal-dev
yum -y install freeimage
# ------ Build FreeImage from source and install ------
cd $CURRDIR
wget http://downloads.sourceforge.net/freeimage/FreeImage3180.zip
unzip FreeImage3180.zip
cd FreeImage
make
make install
# Install GLEW
yum -y install glew-devel
# ------ Build COLMAP ------
cd $CURRDIR
git clone https://github.com/colmap/colmap.git
cd colmap
git checkout dev
mkdir build/
cd build/
CXXFLAGS="-fPIC" CFLAGS="-fPIC" cmake .. -DCMAKE_BUILD_TYPE=Release \
-DBoost_USE_STATIC_LIBS=ON \
-DBOOST_ROOT=/usr/local \
-DGUI_ENABLED=OFF \
-DEIGEN3_INCLUDE_DIRS=$EIGEN_DIR
if [ $ec -ne 0 ]; then
echo "Error:"
cat ./CMakeCache.txt
exit $ec
fi
set -e -x
make -j$(nproc) install
# ------ Build pycolmap wheel ------
cd /io/
cat setup.py
PLAT=manylinux2014_x86_64
EIGEN3_INCLUDE_DIRS="$EIGEN_DIR" "${PYBIN}/python" setup.py bdist_wheel --plat-name=$PLAT
# Bundle external shared libraries into the wheels
mkdir -p /io/wheelhouse
for whl in ./dist/*.whl; do
auditwheel repair "$whl" -w /io/wheelhouse/ --no-update-tags
done
ls -ltrh /io/wheelhouse/