forked from edennz/artoolkit6-calibration
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.sh
executable file
·326 lines (279 loc) · 11 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
#! /bin/bash
#
# Build artoolkitX Camera Calibration utility for desktop platforms.
#
# Copyright 2018, Philip Lamb.
# Copyright 2018, Realmax, Inc.
# Copyright 2016-2017, DAQRI LLC.
#
# Author(s): Philip Lamb, Thorsten Bux, John Wolf, Dan Bell.
#
# -e = exit on errors; -x = debug
set -e
# -x = debug
set -x
# Get our location.
OURDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
VERSION=`sed -En -e 's/.*VERSION_STRING[[:space:]]+"([0-9]+\.[0-9]+(\.[0-9]+)*)".*/\1/p' ${OURDIR}/version.h`
# If the tiny version number is 0, drop it.
VERSION=`echo -n "${VERSION}" | sed -E -e 's/([0-9]+\.[0-9]+)\.0/\1/'`
# Process for version number parts.
VERSION_MAJOR=$(echo ${VERSION} | sed -E -e 's/^([0-9]+).*/\1/')
VERSION_MINOR=$(echo ${VERSION} | sed -E -e 's/^[0-9]+\.([0-9]+).*/\1/')
# VERSION_TINY and its preceding dot can be absent, so allow for that in our regexp and set to 0 in that case.
VERSION_TINY=$(echo ${VERSION} | sed -E -e 's/^[0-9]+\.[0-9]+\.*([0-9]+)*.*/\1/')
VERSION_TINY=${VERSION_TINY:-0}
# VERSION_BUILD can be overridden in the environment, but defaults to 0.
VERSION_BUILD=${VERSION_BUILD:-0}
# Convert version to an integer (e.g. for use in incremental build numbering, as on Android).
VERSION_INT=$(printf "%d%02d%02d%02d" ${VERSION_MAJOR} ${VERSION_MINOR} ${VERSION_TINY} ${VERSION_BUILD})
echo "Build version ${VERSION_INT}"
function usage {
echo "Usage: $(basename $0) [--debug] (macos | ios | windows | linux | linux-raspbian) "
exit 1
}
if [ $# -eq 0 ]; then
usage
fi
# Parse parameters
while test $# -gt 0
do
case "$1" in
osx) BUILD_MACOS=1
;;
macos) BUILD_MACOS=1
;;
ios) BUILD_IOS=1
;;
linux) BUILD_LINUX=1
;;
linux-raspbian) BUILD_LINUX_RASPBIAN=1
;;
windows) BUILD_WINDOWS=1
;;
android) BUILD_ANDROID=1
;;
--debug) DEBUG=
;;
--*) echo "bad option $1"
usage
;;
*) echo "bad argument $1"
usage
;;
esac
shift
done
# Set OS-dependent variables.
OS=`uname -s`
ARCH=`uname -m`
TAR='/usr/bin/tar'
if [ "$OS" = "Linux" ]
then
CPUS=`/usr/bin/nproc`
TAR='/bin/tar'
# Identify Linux OS. Sets useful variables: ID, ID_LIKE, VERSION, NAME, PRETTY_NAME.
#source /etc/os-release
# Windows Subsystem for Linux identifies itself as 'Linux'. Additional test required.
if grep -qE "(Microsoft|WSL)" /proc/version &> /dev/null ; then
OS='Windows'
fi
elif [ "$OS" = "Darwin" ]
then
CPUS=`/usr/sbin/sysctl -n hw.ncpu`
elif [ "$OS" = "CYGWIN_NT-6.1" ]
then
# bash on Cygwin.
CPUS=`/usr/bin/nproc`
OS='Windows'
elif [ "$OS" = "MINGW64_NT-10.0" ]
then
# git-bash on Windows.
CPUS=`/usr/bin/nproc`
OS='Windows'
else
CPUS=1
fi
ARTOOLKITX_VERSION=$(cat ${OURDIR}/artoolkitx-version.txt | tr -d '[:space:]')
# Set default CMake generator for Windows.
echo "$CMAKE_GENERATOR"
if [ $OS = "Windows" ] && test -z "$CMAKE_GENERATOR"; then
CMAKE_GENERATOR="Visual Studio 16 2019"
CMAKE_ARCH="x64"
fi
# Function to allow check for required packages.
function check_package {
# Variant for distros that use debian packaging.
if (type dpkg-query >/dev/null 2>&1) ; then
if ! $(dpkg-query -W -f='${Status}' $1 | grep -q '^install ok installed$') ; then
echo "Warning: required package '$1' does not appear to be installed. To install it use 'sudo apt-get install $1'."
fi
# Variant for distros that use rpm packaging.
elif (type rpm >/dev/null 2>&1) ; then
if ! $(rpm -qa | grep -q $1) ; then
echo "Warning: required package '$1' does not appear to be installed. To install it use 'sudo dnf install $1'."
fi
fi
}
find_or_fetch_artoolkitx() {
if [ ! -f "${1}" ] ; then
echo "Downloading ${1}..."
curl --location "https://github.com/artoolkitx/artoolkitx/releases/download/${ARTOOLKITX_VERSION}/${1}" -O
fi
}
if [ "$OS" = "Darwin" ] ; then
# ======================================================================
# Build platforms hosted by macOS
# ======================================================================
# macOS
if [ $BUILD_MACOS ] ; then
cd "${OURDIR}"
# Fetch the ARX.framework from latest build into a location where Xcode will find it.
MOUNTPOINT=mnt$$
IMAGE="artoolkitX.for.macOS.v${ARTOOLKITX_VERSION}.dmg"
find_or_fetch_artoolkitx "${IMAGE}"
mkdir -p "${MOUNTPOINT}"
hdiutil attach "${IMAGE}" -noautoopen -quiet -mountpoint "${MOUNTPOINT}"
rm -rf depends/macOS/Frameworks/ARX.framework
ditto "${MOUNTPOINT}/artoolkitX/SDK/Frameworks/ARX.framework" depends/macOS/Frameworks/ARX.framework
hdiutil detach "${MOUNTPOINT}" -quiet -force
rmdir "${MOUNTPOINT}"
# Make the version number available to Xcode.
cp macOS/user-config-in.xcconfig macOS/user-config.xcconfig
sed -E -i "" -e "s/@VERSION@/${VERSION}/" macOS/user-config.xcconfig
# Insert the calibration server upload URL and authentication tokens into the build config.
if [[ ! -z "${ARTOOLKITX_CSUU}" && ! -z "${ARTOOLKITX_CSAT}" ]]; then
echo "GCC_PREPROCESSOR_DEFINITIONS=ARTOOLKITX_CSUU=\\\"${ARTOOLKITX_CSUU////\\/}\\\" ARTOOLKITX_CSAT=\\\"${ARTOOLKITX_CSAT}\\\"" >> macOS/user-config.xcconfig
fi
(cd macOS
xcodebuild -target "artoolkitX Camera Calibration Utility" -configuration Release
)
fi
# /BUILD_MACOS
# iOS
if [ $BUILD_IOS ] ; then
cd "${OURDIR}"
# Fetch libARX from latest build into a location where Xcode will find it.
MOUNTPOINT=mnt$$
IMAGE="artoolkitX.for.iOS.v${ARTOOLKITX_VERSION}.dmg"
find_or_fetch_artoolkitx "${IMAGE}"
mkdir -p "${MOUNTPOINT}"
hdiutil attach "${IMAGE}" -noautoopen -quiet -mountpoint "${MOUNTPOINT}"
rm -rf depends/iOS/include/ARX/
cp -af "${MOUNTPOINT}/artoolkitX/SDK/include/ARX" depends/iOS/include
rm -f depends/iOS/lib/libARX.a
cp -af "${MOUNTPOINT}/artoolkitX/SDK/lib/libARX.a" depends/iOS/lib
hdiutil detach "${MOUNTPOINT}" -quiet -force
rmdir "${MOUNTPOINT}"
# Make the version number available to Xcode.
cp iOS/user-config-in.xcconfig iOS/user-config.xcconfig
sed -E -i "" -e "s/@VERSION@/${VERSION}/" iOS/user-config.xcconfig
# Insert the calibration server upload URL and authentication tokens into the build config.
if [[ ! -z "${ARTOOLKITX_CSUU}" && ! -z "${ARTOOLKITX_CSAT}" ]]; then
echo "GCC_PREPROCESSOR_DEFINITIONS=ARTOOLKITX_CSUU=\\\"${ARTOOLKITX_CSUU////\\/}\\\" ARTOOLKITX_CSAT=\\\"${ARTOOLKITX_CSAT}\\\"" >> iOS/user-config.xcconfig
fi
(cd iOS
xcodebuild -target "artoolkitX Camera Calibration Utility" -configuration Release -destination generic/platform=iOS
)
fi
# /BUILD_IOS
fi
# /Darwin
if [ "$OS" = "Darwin" ] || [ "$OS" = "Linux" ] || [ "$OS" = "Windows" ] ; then
# ======================================================================
# Build platforms hosted by macOS/Linux/Windows
# ======================================================================
if [ $BUILD_ANDROID ] ; then
cd "${OURDIR}"
if [ ! -d "depends/android/include/opencv2" ] ; then
curl --location "https://github.com/artoolkitx/opencv/releases/download/4.6.0/opencv-4.6.0-dev-artoolkitx-android.tgz" -o opencv2.tgz
tar xzf opencv2.tgz --strip-components=1 --warning=no-unknown-keyword -C depends/android
rm opencv2.tgz
fi
# If artoolkitx folder is not a symlink, fetch artoolkitx from latest build into a location where the build can find it.
if [[ ! -L "${OURDIR}/depends/android/artoolkitx" ]] ; then
IMAGE="artoolkitx-${ARTOOLKITX_VERSION}-Android.zip"
find_or_fetch_artoolkitx "${IMAGE}"
rm -rf "${OURDIR}/depends/android/artoolkitx"
unzip -q "${OURDIR}/${IMAGE}" -d "${OURDIR}/depends/android"
mv "${OURDIR}/depends/android/artoolkitX" "${OURDIR}/depends/android/artoolkitx"
fi
# Make the version number available to Gradle.
sed -E -i.bak -e "s/versionCode [0-9]+/versionCode ${VERSION_INT}/" -e "s/versionName \"[0-9\.]+\"/versionName \"${VERSION}\"/" Android/app/build.gradle
rm -f Android/app/build.gradle.bak
# Insert the calibration server upload URL and authentication tokens on the Java side. On the C/C++ side, this is done by in CMakeLists.txt.
if [[ ! -z "${ARTOOLKITX_CSUU}" && ! -z "${ARTOOLKITX_CSAT}" ]]; then
sed -E -i.bak -e "s/ARTOOLKITX_CSUU *= *\".*\"/ARTOOLKITX_CSUU = \"${ARTOOLKITX_CSUU////\\/}\"/" Android/app/src/main/java/org/artoolkitx/utilities/cameracalibration/Config.java
sed -E -i.bak -e "s/ARTOOLKITX_CSAT *= *\".*\"/ARTOOLKITX_CSAT = \"${ARTOOLKITX_CSAT//&/\\&}\"/" Android/app/src/main/java/org/artoolkitx/utilities/cameracalibration/Config.java
rm -f Android/app/src/main/java/org/artoolkitx/utilities/cameracalibration/Config.java.bak
fi
(cd "${OURDIR}/Android"
echo "Building Android project"
./gradlew assembleRelease
)
fi
# /BUILD_ANDROID
fi
# /Darwin/Linux/Windows
if [ "$OS" = "Linux" ] ; then
# ======================================================================
# Build platforms hosted by Linux
# ======================================================================
# Linux
if [ $BUILD_LINUX ] ; then
#Before we can install the artoolkitx-dev package we need to install the -lib. As -dev depends on -lib
#SDK_FILENAME="artoolkitx-lib_${SDK_VERSION}_amd64.deb"
#curl -f -o "${SDK_FILENAME}" --location "${SDK_URL_DIR}$(rawurlencode "${SDK_FILENAME}")"
#sudo dpkg -i "${SDK_FILENAME}"
# Fetch the artoolkitx-dev package and install it.
#SDK_FILENAME="artoolkitx-dev_${SDK_VERSION}_amd64.deb"
#curl -f -o "${SDK_FILENAME}" --location "${SDK_URL_DIR}$(rawurlencode "${SDK_FILENAME}")"
#sudo dpkg -i "${SDK_FILENAME}"
(cd Linux
mkdir -p build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release "-DVERSION=${VERSION}"
make
make install
)
fi
# /BUILD_LINUX
# Linux
if [ $BUILD_LINUX_RASPBIAN ] ; then
(cd Linux
mkdir -p build-raspbian
cd build-raspbian
cmake .. -DCMAKE_BUILD_TYPE=Release -DARX_TARGET_PLATFORM_VARIANT="raspbian" -DVERSION="${VERSION}"
make
make install
)
fi
# /BUILD_LINUX_RASPBIAN
fi
# /Linux
if [ "$OS" = "Windows" ] ; then
# ======================================================================
# Build platforms hosted by Windows
# ======================================================================
# Windows
if [ $BUILD_WINDOWS ] ; then
cd "${OURDIR}"
MOUNTPOINT=mnt$$
IMAGE="artoolkitX-${ARTOOLKITX_VERSION}-Windows.zip"
find_or_fetch_artoolkitx "${IMAGE}"
unzip -q -o "${IMAGE}" -d "${MOUNTPOINT}"
# TODO COPY FROM "${MOUNTPOINT}/artoolkitX"
rm -rf "${MOUNTPOINT}"
if [ ! -d "build-windows" ] ; then
mkdir build-windows
fi
(cd Windows
mkdir -p build
cd build
cmake.exe .. -DCMAKE_CONFIGURATION_TYPES=${DEBUG+Debug}${DEBUG-Release} -G "$CMAKE_GENERATOR" ${CMAKE_ARCH+-A ${CMAKE_ARCH}} -D"VERSION=${VERSION}"
cmake.exe --build . --config ${DEBUG+Debug}${DEBUG-Release} --target install
)
fi
# /BUILD_WINDOWS
fi
# /Windows