-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathSetup.sh
executable file
·445 lines (383 loc) · 15.8 KB
/
Setup.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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
#!/bin/sh
CurrentDir=$(cd $(dirname $0); pwd)
CurrentSystem=$(uname)
CurrentKernel=$(uname -r)
CheckCmakeExe=$(command -v cmake)
CMakeExe=$(printf "cmake -DCMAKE_BUILD_TYPE=Release")
UsingWSL=0
UseWasmOption=1
SkipCMakeConfig=0
SkipOsgBuild=0
MingwSystem=$(echo $CurrentSystem | grep "MINGW")
WslKernel=$(echo $CurrentKernel | grep "Microsoft")
if [ "$WslKernel" != "" ]; then
echo "Using Windows subsystem for Linux..."
UsingWSL=1
elif [ "$MingwSystem" != "" ]; then
# Should install MinGW-CMake first: pacman -S mingw-w64-x86_64-cmake
echo "Using MinGW system..."
CMakeExe=$(printf 'cmake -DCYGWIN=ON -DCMAKE_BUILD_TYPE=Release')
fi
# Pre-build Checks
if [ "$CheckCmakeExe" = "" ]; then
echo "CMake not found. Please run 'apt install cmake'."
exit 1
fi
if [ ! -d "../OpenSceneGraph" ]; then
echo "OSG source folder not found. Please download and unzip it in ../OpenSceneGraph."
exit 1
fi
# Select how to compile
echo "
How do you like to compile OSG and osgVerse?
-----------------------------------
Please Select:
0. Desktop / OpenGL Compatible Mode
1. Desktop / OpenGL Core Mode
2. Desktop / Google Angle
3. WASM / WebGL 1.0
4. WASM / WebGL 2.0 (optional with osgEarth)
q. Quit
-----------------------------------"
read -p "Enter selection [0-4] > " BuildMode
case "$BuildMode" in
1) echo "OpenGL Core Mode."
BuildResultChecker=build/sdk_core/bin/osgviewer
CMakeResultChecker=build/osg_core/CMakeCache.txt
;;
2) echo "Google Angle. (NOT IMPLEMENTED)"
BuildResultChecker=build/sdk_es/lib/libosgviewer.a
CMakeResultChecker=build/osg_es/CMakeCache.txt
;;
3) echo "WebAssembly WebGL 1."
BuildResultChecker=build/sdk_wasm/lib/libosgviewer.a
CMakeResultChecker=build/osg_wasm/CMakeCache.txt
;;
4) echo "WebAssembly WebGL 2."
BuildResultChecker=build/sdk_wasm2/lib/libosgviewer.a
CMakeResultChecker=build/osg_wasm2/CMakeCache.txt
;;
5) echo "Android GLES 2."
BuildResultChecker=build/sdk_android/lib/libosgviewer.a
CMakeResultChecker=build/osg_android/CMakeCache.txt
;;
q) exit 0
;;
*) echo "OpenGL Compatible Mode."
BuildResultChecker=build/sdk/bin/osgviewer
CMakeResultChecker=build/osg_def/CMakeCache.txt
;;
esac
# Check for Emscripten/NDK location
EmsdkToolchain="$1/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake"
NdkToolchain="$1/build/cmake/android.toolchain.cmake"
AndroidDepOptions=""
if [ "$BuildMode" = '3' ] || [ "$BuildMode" = '4' ]; then
# WASM toolchain
if [ ! -f "$EmsdkToolchain" ]; then
echo "Emscripten.cmake not found. Please run as follows: ./Setup.sh <your_path>/emsdk-3.?.?/"
exit 1
fi
elif [ "$BuildMode" = '5' ]; then
# Android toolchain
if [ ! -f "$NdkToolchain" ]; then
echo "android.toolchain.cmake not found. Please run as follows: ./Setup.sh <your_path>/ndk-r??-linux/"
exit 1
fi
AndroidABI="armeabi-v7a"
AndroidSdkLevel=21
echo "
-----------------------------------
Please Select an Android ABI option:
0. armeabi-v7a (AArch32, Armv7)
1. armeabi-v7a with NEON
2. arm64-v8a (AArch64, Armv8.0)
3. x86 (MMX, SSE/2/3)
4. x86_64 (MMX, SSE/2/3, SSE4.1/4.2)
-----------------------------------"
read -p "Enter selection [0-4] > " OptionAndroidABI
case "$OptionAndroidABI" in
1) AndroidABI="armeabi-v7a with NEON" ;;
2) AndroidABI="arm64-v8a" ;;
3) AndroidABI="x86" ;;
4) AndroidABI="x86_64" ;;
*) AndroidABI="armeabi-v7a" ;;
esac
AndroidDepOptions="
-DCMAKE_TOOLCHAIN_FILE=$NdkToolchain
-DANDROID_ABI=$AndroidABI
-DANDROID_PLATFORM=$AndroidSdkLevel"
if [ "$UsingWSL" = 1 ]; then
# Please download NDK for LINUX at https://github.com/android/ndk/wiki/Unsupported-Downloads
echo "Please download NDK for Linux r20e at present. The latest r25 version seems having problems
with WSL, as clang will report 'Exec format error'. Need more tests later..."
# See https://github.com/android/ndk/issues/1755
# You should first install patchelf: $ sudo apt-get install patchelf
#/usr/bin/patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 "$1/toolchains/llvm/prebuilt/linux-x86_64/bin/clang-14"
fi
fi
# Check if CMake is already configured, or OSG is already built
if [ -f "$CurrentDir/$BuildResultChecker" ]; then
read -p "Would you like to use current OSG built? (y/n) > " RebuildFlag
if [ "$RebuildFlag" = 'n' ]; then
SkipOsgBuild=0
else
SkipOsgBuild=1
fi
#elif [ -f "$CurrentDir/$CMakeResultChecker" ]; then
# read -p "Would you like to use current CMake cache? (y/n) > " RecmakeFlag
# if [ "$RecmakeFlag" = 'n' ]; then
# SkipCMakeConfig=0
# else
# SkipCMakeConfig=1
# fi
fi
# Compile 3rdparty libraries
echo "*** Building 3rdparty libraries..."
if [ ! -d "$CurrentDir/build" ]; then
mkdir $CurrentDir/build
fi
ThirdPartyBuildDir="$CurrentDir/build/3rdparty_def"
if [ "$BuildMode" = '3' ] || [ "$BuildMode" = '4' ]; then
read -p "Would you like to use WASM 64bit (experimental)? (y/n) > " Wasm64Flag
if [ "$Wasm64Flag" = 'y' ]; then
UseWasmOption=2
fi
# WASM toolchain
ThirdPartyBuildDir="$CurrentDir/build/3rdparty_wasm"
if [ ! -d "$ThirdPartyBuildDir" ]; then
mkdir $ThirdPartyBuildDir
fi
if [ "$SkipOsgBuild" = 0 ]; then
cd $ThirdPartyBuildDir
if [ "$SkipCMakeConfig" = 0 ]; then
$CMakeExe -DCMAKE_TOOLCHAIN_FILE="$EmsdkToolchain" -DUSE_WASM_OPTIONS=$UseWasmOption $CurrentDir/helpers/toolchain_builder
fi
cmake --build . || exit 1
fi
elif [ "$BuildMode" = '5' ]; then
# Android toolchain
ThirdPartyBuildDir="$CurrentDir/build/3rdparty_android"
if [ ! -d "$ThirdPartyBuildDir" ]; then
mkdir $ThirdPartyBuildDir
fi
if [ "$SkipOsgBuild" = 0 ]; then
cd $ThirdPartyBuildDir
if [ "$SkipCMakeConfig" = 0 ]; then
$CMakeExe $AndroidDepOptions $CurrentDir/helpers/toolchain_builder
fi
cmake --build . || exit 1
fi
else
# Default toolchain
if [ ! -d "$ThirdPartyBuildDir" ]; then
mkdir $ThirdPartyBuildDir
fi
if [ "$SkipOsgBuild" = 0 ]; then
cd $ThirdPartyBuildDir
if [ "$SkipCMakeConfig" = 0 ]; then
$CMakeExe $CurrentDir/helpers/toolchain_builder
fi
cmake --build . || exit 1
fi
fi
# Generate 3rdparty options
ThirdDepOptions="
-DFREETYPE_INCLUDE_DIR_freetype2=$CurrentDir/helpers/toolchain_builder/freetype/include
-DFREETYPE_INCLUDE_DIR_ft2build=$CurrentDir/helpers/toolchain_builder/freetype/include
-DFREETYPE_LIBRARY_RELEASE=$ThirdPartyBuildDir/freetype/libfreetype.a
-DJPEG_INCLUDE_DIR=$CurrentDir/helpers/toolchain_builder/jpeg
-DJPEG_LIBRARY_RELEASE=$ThirdPartyBuildDir/jpeg/libjpeg.a
-DPNG_PNG_INCLUDE_DIR=$CurrentDir/helpers/toolchain_builder/png
-DPNG_LIBRARY_RELEASE=$ThirdPartyBuildDir/png/libpng.a
-DZLIB_INCLUDE_DIR=$CurrentDir/helpers/toolchain_builder/zlib
-DZLIB_LIBRARY_RELEASE=$ThirdPartyBuildDir/zlib/libzlib.a
-DVERSE_BUILD_3RDPARTIES=OFF"
if [ "$BuildMode" = '3' ] || [ "$BuildMode" = '4' ]; then
if [ -e "$CurrentDir/../Dependencies/wasm/lib/libtiff.a" ]; then
ThirdDepOptions="
$ThirdDepOptions
-DTIFF_INCLUDE_DIR=$CurrentDir/../Dependencies/wasm/include
-DTIFF_LIBRARY_RELEASE=$CurrentDir/../Dependencies/wasm/lib/libtiff.a"
fi
fi
# Fix some OpenSceneGraph compile errors
OpenSceneGraphRoot=$CurrentDir/../OpenSceneGraph
sed 's/if defined(__ANDROID__)/if defined(__EMSCRIPTEN__) || defined(__ANDROID__)/g' "$OpenSceneGraphRoot/src/osgDB/FileUtils.cpp" > FileUtils.cpp.tmp
mv FileUtils.cpp.tmp "$OpenSceneGraphRoot/src/osgDB/FileUtils.cpp"
sed 's/std::mem_fun_ref/std::mem_fn/g' "$OpenSceneGraphRoot/src/osgUtil/tristripper/include/detail/graph_array.h" > graph_array.h.tmp
mv graph_array.h.tmp "$OpenSceneGraphRoot/src/osgUtil/tristripper/include/detail/graph_array.h"
sed 's/ADD_PLUGIN_DIRECTORY(cfg)/#ADD_PLUGIN_DIRECTORY(#cfg)/g' "$OpenSceneGraphRoot/src/osgPlugins/CMakeLists.txt" > CMakeLists.txt.tmp
mv CMakeLists.txt.tmp "$OpenSceneGraphRoot/src/osgPlugins/CMakeLists.txt"
sed 's/ADD_PLUGIN_DIRECTORY(obj)/#ADD_PLUGIN_DIRECTORY(#obj)/g' "$OpenSceneGraphRoot/src/osgPlugins/CMakeLists.txt" > CMakeLists.txt.tmp
mv CMakeLists.txt.tmp "$OpenSceneGraphRoot/src/osgPlugins/CMakeLists.txt"
sed 's/TIFF_FOUND AND OSG_CPP_EXCEPTIONS_AVAILABLE/TIFF_FOUND/g' "$OpenSceneGraphRoot/src/osgPlugins/CMakeLists.txt" > CMakeLists.txt.tmp
mv CMakeLists.txt.tmp "$OpenSceneGraphRoot/src/osgPlugins/CMakeLists.txt"
sed 's/ANDROID_3RD_PARTY()/#ANDROID_3RD_PARTY(#)/g' "$OpenSceneGraphRoot/CMakeLists.txt" > CMakeLists.txt.tmp
mv CMakeLists.txt.tmp "$OpenSceneGraphRoot/CMakeLists.txt"
# Fix WebGL running errors
if [ "$BuildMode" = '3' ] || [ "$BuildMode" = '4' ]; then
sed 's#dlopen(#NULL;\/\/dlopen\/\/(#g' "$OpenSceneGraphRoot/src/osgDB/DynamicLibrary.cpp" > DynamicLibrary.cpp.tmp
else
sed 's#NULL;\/\/dlopen\/\/(#dlopen(#g' "$OpenSceneGraphRoot/src/osgDB/DynamicLibrary.cpp" > DynamicLibrary.cpp.tmp
fi
mv DynamicLibrary.cpp.tmp "$OpenSceneGraphRoot/src/osgDB/DynamicLibrary.cpp"
sed 's#glTexParameterf(target, GL_TEXTURE_LOD_BIAS, _lodbias)#;\/\/glTexParameterf(target, \/\/GL_TEXTURE_LOD_BIAS, _lodbias)#g' "$OpenSceneGraphRoot/src/osg/Texture.cpp" > Texture.cpp.tmp
mv Texture.cpp.tmp "$OpenSceneGraphRoot/src/osg/Texture.cpp"
sed 's#case(GL_HALF_FLOAT):#case GL_HALF_FLOAT: case 0x8D61:#g' "$OpenSceneGraphRoot/src/osg/Image.cpp" > Image.cpp.tmp
mv Image.cpp.tmp "$OpenSceneGraphRoot/src/osg/Image.cpp"
# Compile OpenSceneGraph
echo "*** Building OpenSceneGraph..."
if [ "$BuildMode" = '1' ]; then
# OpenGL Core
if [ ! -d "$CurrentDir/build/osg_core" ]; then
mkdir $CurrentDir/build/osg_core
fi
ExtraOptions="
-DCMAKE_INCLUDE_PATH=$CurrentDir/helpers/toolchain_builder/opengl
-DCMAKE_INSTALL_PREFIX=$CurrentDir/build/sdk_core
-DOPENGL_PROFILE=GL3CORE"
if [ "$SkipOsgBuild" = 0 ]; then
cd $CurrentDir/build/osg_core
if [ "$SkipCMakeConfig" = 0 ]; then
$CMakeExe $ThirdDepOptions $ExtraOptions $OpenSceneGraphRoot
fi
cmake --build . --target install --config Release || exit 1
fi
elif [ "$BuildMode" = '2' ]; then
# TODO: Google Angle
:
elif [ "$BuildMode" = '3' ]; then
# WASM toolchain (WebGL 1)
if [ ! -d "$CurrentDir/build/osg_wasm" ]; then
mkdir $CurrentDir/build/osg_wasm
fi
ExtraOptions="
-DCMAKE_TOOLCHAIN_FILE="$EmsdkToolchain"
-DCMAKE_INCLUDE_PATH=$CurrentDir/helpers/toolchain_builder/opengl
-DCMAKE_INSTALL_PREFIX=$CurrentDir/build/sdk_wasm
-DUSE_WASM_OPTIONS=$UseWasmOption
-DOSG_SOURCE_DIR=$OpenSceneGraphRoot
-DOSG_BUILD_DIR=$CurrentDir/build/osg_wasm/osg"
if [ "$SkipOsgBuild" = 0 ]; then
cd $CurrentDir/build/osg_wasm
if [ "$SkipCMakeConfig" = 0 ]; then
$CMakeExe $ThirdDepOptions $ExtraOptions $CurrentDir/helpers/osg_builder/wasm
fi
cmake --build . --target install --config Release || exit 1
fi
elif [ "$BuildMode" = '4' ]; then
# WASM toolchain (WebGL 2)
if [ ! -d "$CurrentDir/build/osg_wasm2" ]; then
mkdir $CurrentDir/build/osg_wasm2
fi
ExtraOptions="
-DCMAKE_TOOLCHAIN_FILE="$EmsdkToolchain"
-DCMAKE_INCLUDE_PATH=$CurrentDir/helpers/toolchain_builder/opengl
-DCMAKE_INSTALL_PREFIX=$CurrentDir/build/sdk_wasm2
-DUSE_WASM_OPTIONS=$UseWasmOption
-DOSG_SOURCE_DIR=$OpenSceneGraphRoot
-DOSG_BUILD_DIR=$CurrentDir/build/osg_wasm2/osg"
if [ "$SkipOsgBuild" = 0 ]; then
cd $CurrentDir/build/osg_wasm2
if [ "$SkipCMakeConfig" = 0 ]; then
$CMakeExe $ThirdDepOptions $ExtraOptions $CurrentDir/helpers/osg_builder/wasm2
fi
cmake --build . --target install --config Release || exit 1
fi
elif [ "$BuildMode" = '5' ]; then
# Android toolchain
if [ ! -d "$CurrentDir/build/osg_android" ]; then
mkdir $CurrentDir/build/osg_android
fi
ExtraOptions="
-DCMAKE_INCLUDE_PATH=$CurrentDir/helpers/toolchain_builder/opengl
-DCMAKE_INSTALL_PREFIX=$CurrentDir/build/sdk_android
-DOSG_SOURCE_DIR=$OpenSceneGraphRoot
-DOSG_BUILD_DIR=$CurrentDir/build/osg_android/osg"
if [ "$SkipOsgBuild" = 0 ]; then
cd $CurrentDir/build/osg_android
if [ "$SkipCMakeConfig" = 0 ]; then
$CMakeExe $AndroidDepOptions $ThirdDepOptions $ExtraOptions $CurrentDir/helpers/osg_builder/android
fi
cmake --build . --target install --config Release || exit 1
fi
else
# OpenGL default
if [ ! -d "$CurrentDir/build/osg_def" ]; then
mkdir $CurrentDir/build/osg_def
fi
if [ "$SkipOsgBuild" = 0 ]; then
cd $CurrentDir/build/osg_def
if [ "$SkipCMakeConfig" = 0 ]; then
$CMakeExe $ThirdDepOptions $ExtraOptions $OpenSceneGraphRoot
fi
fi
cmake --build . --target install --config Release || exit 1
fi
# Build osgEarth (Optional)
WithOsgEarth=0
if [ "$BuildMode" = '4' ]; then
if [ -d "$CurrentDir/../osgearth-wasm" ]; then
# WASM toolchain (WebGL 2)
if [ ! -d "$CurrentDir/build/osgearth_wasm2" ]; then
mkdir $CurrentDir/build/osgearth_wasm2
fi
echo "*** Building osgEarth 2.10..."
ExtraOptions2="
-DOSG_DIR=$CurrentDir/build/sdk_wasm2
-DTHIRDPARTY_ROOT=$CurrentDir/../Dependencies/wasm
-DUSE_WASM_OPTIONS=$UseWasmOption
-DOSGEARTH_SOURCE_DIR=$CurrentDir/../osgearth-wasm
-DOSGEARTH_BUILD_DIR=$CurrentDir/build/osgearth_wasm2/osgearth"
cd $CurrentDir/build/osgearth_wasm2
$CMakeExe $ExtraOptions $ExtraOptions2 $CurrentDir/helpers/osg_builder/wasm2_oe
make install || exit 1
WithOsgEarth=1
else
echo "osgEarth-WASM not found. Please download it and unzip in ../osgearth-wasm if you wish."
fi
fi
# Build osgVerse
echo "*** Building osgVerse..."
if [ "$BuildMode" = '3' ]; then
# WASM toolchain (WebGL 1)
if [ ! -d "$CurrentDir/build/verse_wasm" ]; then
mkdir $CurrentDir/build/verse_wasm
fi
OsgRootLocation="$CurrentDir/build/sdk_wasm"
cd $CurrentDir/build/verse_wasm
$CMakeExe -DUSE_WASM_OPTIONS=$UseWasmOption -DOSG_ROOT="$OsgRootLocation" $ThirdDepOptions $ExtraOptions $CurrentDir
cmake --build . --target install --config Release || exit 1
elif [ "$BuildMode" = '4' ]; then
# WASM toolchain (WebGL 2)
if [ ! -d "$CurrentDir/build/verse_wasm2" ]; then
mkdir $CurrentDir/build/verse_wasm2
fi
OsgRootLocation="$CurrentDir/build/sdk_wasm2"
cd $CurrentDir/build/verse_wasm2
$CMakeExe -DUSE_WASM_OPTIONS=$UseWasmOption -DUSE_WASM_OSGEARTH=$WithOsgEarth -DOSG_ROOT="$OsgRootLocation" $ThirdDepOptions $ExtraOptions $CurrentDir
cmake --build . --target install --config Release || exit 1
elif [ "$BuildMode" = '5' ]; then
# WASM toolchain
if [ ! -d "$CurrentDir/build/verse_android" ]; then
mkdir $CurrentDir/build/verse_android
fi
OsgRootLocation="$CurrentDir/build/sdk_android"
cd $CurrentDir/build/verse_android
$CMakeExe $AndroidDepOptions -DOSG_ROOT="$OsgRootLocation" $ThirdDepOptions $ExtraOptions $CurrentDir
cmake --build . --target install --config Release || exit 1
else
# Default toolchain
if [ ! -d "$CurrentDir/build/verse" ]; then
mkdir $CurrentDir/build/verse
fi
if [ "$BuildMode" = '1' ]; then
OsgRootLocation="$CurrentDir/build/sdk_core"
else
OsgRootLocation="$CurrentDir/build/sdk"
fi
cd $CurrentDir/build/verse
$CMakeExe -DOSG_ROOT="$OsgRootLocation" $ThirdDepOptions $ExtraOptions $CurrentDir
cmake --build . --target install --config Release || exit 1
fi