Repository navigation
Expand file tree
/
Copy pathSetup.sh
More file actions
executable file
·746 lines (660 loc) · 30.7 KB
/
Copy pathSetup.sh
File metadata and controls
executable file
·746 lines (660 loc) · 30.7 KB
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
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
#!/bin/sh
CurrentDir=$(cd $(dirname $0); pwd)
CurrentSystem=$(uname)
CurrentKernel=$(uname -r)
CheckCmakeExe=$(command -v cmake)
CMakeExe=$(printf "cmake -DCMAKE_BUILD_TYPE=Release")
QuietMode=0
UsingWSL=0
UsingGles2=0
UseWasmOption=1
SkipCMakeConfig=0
SkipOsgBuild=0
VerseLibraryTargets="osgVerseDependency osgVerseAnimation osgVerseModeling
osgVerseReaderWriter osgVersePipeline osgVerseScript
osgVerseWrappers osgVerseUI osgVerseAI"
# Android related variables
GradleLocalPropFile=$CurrentDir/android/local.properties
GradleSettingsFile=$CurrentDir/android/settings.gradle
AndroidBuildType="Debug" # Debug or Release: Gradle task and build result paths used by mode 5
AndroidAbi="arm64-v8a" # passed to Gradle as -Pabi (ABI_FILTER in android/build.gradle)
Sdl2Version="release-2.24.0" # tag cloned into ../SDL2 when it does not exist yet
AndroidDebugPostfix="" # OSG appends 'd' to library names in Debug builds
if [ "$AndroidBuildType" = "Debug" ]; then
AndroidDebugPostfix="d"
fi
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
git clone https://gitee.com/mirrors/OpenSceneGraph.git --depth 1 --branch OpenSceneGraph-3.6.5 ../OpenSceneGraph
if [ ! -d "../OpenSceneGraph" ]; then
echo "OSG source folder not found. Please download and unzip it in ../OpenSceneGraph."
exit 1
fi
fi
# Check for Emscripten/NDK location
QuietModeString="$1"
case "$QuietModeString" in
"DEFAULT") BuildMode="0"
QuietMode=1 ;;
"CORE") BuildMode="1"
QuietMode=1 ;;
"GLES2") BuildMode="2"
UsingGles2=1
QuietMode=1 ;;
"GLES3") BuildMode="2"
UsingGles2=0
QuietMode=1 ;;
"WEBGL1") BuildMode="3"
QuietMode=1 ;;
"WEBGL2") BuildMode="4"
QuietMode=1 ;;
"ANDROID") BuildMode="5"
QuietMode=1 ;;
"WEBGPU") BuildMode="7"
QuietMode=1 ;;
esac
if [ -z "$BuildMode" ]; then
GLES_LibPath="$1/libGLESv2.so"
EGL_LibPath="$1/libEGL.so"
EmsdkToolchain="$1/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake"
AngleWasmRoot="$2"
else
GLES_LibPath="$2/libGLESv2.so"
EGL_LibPath="$2/libEGL.so"
EmsdkToolchain="$2/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake"
AngleWasmRoot="$3" # WEBGPU takes the gles-on-webgpu wasm SDK as the 3rd argument
fi
# Select how to compile
if [ "$QuietMode" = 0 ]; then
echo "
How do you like to compile OSG and osgVerse?
-----------------------------------
Please Select:
0. Desktop / OpenGL Compatible Mode
1. Desktop / OpenGL Core Mode
2. Desktop / OpenGL ES
3. WASM / WebGL 1.0
4. WASM / WebGL 2.0 (optional with osgEarth)
5. Android / OpenGLES 3
6. Harmony / OpenGLES 3
7. WASM / WebGPU (with gles-on-webgpu)
q. Quit
-----------------------------------"
read -p "Enter selection [0-7] > " BuildMode
fi
case "$BuildMode" in
1) echo "OpenGL Core Mode."
BuildResultChecker=build/sdk_core/bin/osgviewer
CMakeResultChecker=build/osg_core/CMakeCache.txt
;;
2) echo "OpenGL ES Mode."
BuildResultChecker=build/sdk_es/bin/osgviewer
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 3."
BuildResultChecker=build/osg_android/${AndroidBuildType}/${AndroidAbi}/lib/libosgViewer${AndroidDebugPostfix}.a
CMakeResultChecker=build/osg_android/CMakeCache.txt
;;
7) echo "WebAssembly WebGPU (Experimental)."
BuildResultChecker=build/sdk_wasm_webgpu/lib/libosgViewer.a
CMakeResultChecker=build/osg_webgpu/CMakeCache.txt
;;
q) exit 0
;;
*) echo "OpenGL Compatible Mode."
BuildResultChecker=build/sdk/bin/osgviewer
CMakeResultChecker=build/osg_def/CMakeCache.txt
;;
esac
if [ "$BuildMode" = '2' ]; then
# GLES toolchain
if [ ! -f "$GLES_LibPath" ] || [ ! -f "$EGL_LibPath" ]; then
echo "libEGL.so or libGLESv2.so not found. Please run as follows: ./Setup.sh <path_of_libEGL>"
exit 1
fi
elif [ "$BuildMode" = '3' ] || [ "$BuildMode" = '4' ] || [ "$BuildMode" = '7' ]; then
# WASM toolchain
if [ ! -f "$EmsdkToolchain" ]; then
echo "Emscripten.cmake not found. Please run as follows: ./Setup.sh <your_path>/emsdk/"
exit 1
fi
if [ "$BuildMode" = '7' ] && [ ! -f "$AngleWasmRoot/include/GLES3/gl3.h" ]; then
echo "gles-on-webgpu SDK not found. Please run as follows:"
echo " ./Setup.sh WEBGPU <your_path>/emsdk <your_path>/angle-wasm-sdk"
exit 1
fi
elif [ "$BuildMode" = '5' ]; then
# Android toolchain: Gradle 8.5 with AGP 7.4.2 only accepts JDK 11 or 17,
# so automatically pick a usable one instead of relying on the default java
AndroidJavaHome=""
JavaFoundVersions=""
JavaCandidateList="$JAVA_HOME/bin/java"
for JavaRootDir in /usr/lib/jvm /usr/java /opt/java /opt/jdk \
"$HOME/.sdkman/candidates/java" "$HOME/.jdks" \
/Library/Java/JavaVirtualMachines; do
if [ -d "$JavaRootDir" ]; then
for JavaSubDir in "$JavaRootDir"/*; do
for JavaHomeDir in "$JavaSubDir" "$JavaSubDir/Contents/Home"; do
if [ -x "$JavaHomeDir/bin/java" ]; then
JavaCandidateList="$JavaCandidateList $JavaHomeDir/bin/java"
fi
done
done
fi
done
JavaCandidateList="$JavaCandidateList $(command -v java)"
for JavaCandidate in $JavaCandidateList; do
if [ ! -x "$JavaCandidate" ]; then
continue
fi
JavaVersionInfo=$("$JavaCandidate" -version 2>&1 | head -n 1)
JavaMajorVersion=$(echo "$JavaVersionInfo" | sed -n 's/.*version "\([0-9][0-9]*\)[.\"].*/\1/p')
if [ "$JavaMajorVersion" = "1" ]; then
JavaMajorVersion=$(echo "$JavaVersionInfo" | sed -n 's/.*version "1\.\([0-9][0-9]*\).*/\1/p')
fi
JavaFoundVersions="$JavaFoundVersions $JavaMajorVersion"
if [ "$JavaMajorVersion" = "17" ]; then
AndroidJavaHome=$(cd "$(dirname "$JavaCandidate")/.." && pwd)
break
elif [ "$JavaMajorVersion" = "11" ] && [ "$AndroidJavaHome" = "" ]; then
# JDK 11 works as well, but keep looking for a preferred JDK 17
AndroidJavaHome=$(cd "$(dirname "$JavaCandidate")/.." && pwd)
fi
done
if [ "$AndroidJavaHome" = "" ]; then
echo "No usable JDK found for the Android build. Gradle 8.5 with AGP 7.4.2"
echo "requires JDK 11 or 17, but only found these versions: $JavaFoundVersions"
echo "Please install JDK 17 and try again."
exit 1
fi
JAVA_HOME=$AndroidJavaHome
export JAVA_HOME
PATH="$JAVA_HOME/bin:$PATH"
export PATH
echo "Android toolchain will use JDK: $JAVA_HOME"
# Fetch SDL2 in the same way as OpenSceneGraph above when it is not there yet.
# The sources come with both the native library and the Java classes used by
# the Android application, which therefore always share one version
if [ ! -d "../SDL2" ]; then
echo "SDL2 source folder not found. Cloning $Sdl2Version in ../SDL2..."
git clone --depth 1 --branch $Sdl2Version \
https://github.com/libsdl-org/SDL.git ../SDL2
if [ ! -d "../SDL2" ]; then
echo "SDL2 source folder not found. Please download and unzip it in ../SDL2."
exit 1
fi
fi
# Migrate the deprecated ndk.dir entry to ndk.path (read by gradle.ext.ndkPath)
if [ -f "$GradleLocalPropFile" ] && grep -q '^ndk\.dir=' "$GradleLocalPropFile"; then
sed -i 's/^ndk\.dir=/ndk.path=/' "$GradleLocalPropFile"
echo "Replaced deprecated ndk.dir with ndk.path in local.properties..."
fi
if [ ! -f "$GradleLocalPropFile" ]; then
if [ ! -n "$ANDROID_SDK" ]; then
echo "Environment variable ANDROID_SDK not set. Unable to create local.properties."
exit 1
fi
if [ ! -n "$ANDROID_NDK" ]; then
echo "Environment variable ANDROID_NDK not set. Unable to create local.properties."
exit 1
fi
cat > $GradleLocalPropFile <<EOF
sdk.dir=$ANDROID_SDK
ndk.path=$ANDROID_NDK
EOF
if [ "$QuietMode" = 0 ]; then
read -p "Would you like to set a specific SDK version (default: no)? (y/n) " AndroidCheckingFlag
if [ "$AndroidCheckingFlag" = 'y' ]; then
read -p "Please set build-tools version (e.g. 32.0.0) > " BuildToolsVersion
read -p "Please set target SDK version (e.g. 32) > " TargetSdkVersion
read -p "Please set minimum SDK version (e.g. 21) > " MinimumSdkVersion
cat > $GradleSettingsFile <<EOF
gradle.ext.buildToolsVersion = '$BuildToolsVersion'
gradle.ext.sdkVersion = $TargetSdkVersion
gradle.ext.minSdkVersion = $MinimumSdkVersion
gradle.ext.targetSdkVersion = $TargetSdkVersion
gradle.ext.libDistributionRoot = '../build'
include ':thirdparty'
include ':sdl2'
include ':osg'
include ':osgverse'
include ':app'
EOF
fi
else
# TODO: auto check and create $GradleSettingsFile?
echo "Ignore creation of $GradleSettingsFile..."
fi
fi
fi
# Check if CMake is already configured, or OSG is already built
if [ -f "$CurrentDir/$BuildResultChecker" ]; then
if [ "$QuietMode" = 0 ]; then
read -p "Would you like to use current OSG built (default: yes)? (y/n) > " RebuildFlag
if [ "$RebuildFlag" = 'n' ]; then
SkipOsgBuild=0
else
SkipOsgBuild=1
fi
else
SkipOsgBuild=1
fi
fi
if [ "$SkipOsgBuild" = 0 ]; then
if [ "$BuildMode" = '2' ]; then
read -p "Would you like to compile GLES2 version (default: GLES3)? (y/n) > " Gles2Flag
if [ "$Gles2Flag" = 'y' ]; then
UsingGles2=1
fi
fi
fi
echo "*** Building 3rdparty libraries..."
if [ ! -d "$CurrentDir/build" ]; then
mkdir $CurrentDir/build
fi
# Compile 3rdparty libraries
ThirdPartyBuildDir="$CurrentDir/build/3rdparty"
if [ "$BuildMode" = '3' ] || [ "$BuildMode" = '4' ] || [ "$BuildMode" = '6' ]; then
if [ "$QuietMode" = 0 ] && [ "$BuildMode" != '7' ]; then
read -p "Would you like to use WASM 64bit (experimental, default: no)? (y/n) > " Wasm64Flag
if [ "$Wasm64Flag" = 'y' ]; then
UseWasmOption=2
fi
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 . -j8 || exit 1
fi
elif [ "$BuildMode" = '5' ]; then
# Android toolchain
echo "The compilation will be processed by Gradle..."
else
# Default toolchain for desktop builds
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 . -j8 || 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 -DCMAKE_POLICY_VERSION_MINIMUM=3.5"
if [ "$BuildMode" = '3' ] || [ "$BuildMode" = '4' ] || [ "$BuildMode" = '7' ]; 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
else
if [ -e "$ThirdPartyBuildDir/tiff/libtiff.a" ]; then
# The bundled libtiff is static and includes its JPEG codec (tif_jpeg*.c), so its JPEG
# symbols must be resolved by also linking the bundled libjpeg. Without it, OSG's tiff
# plugin is built with 22 unresolved jpeg_* symbols and fails to load at runtime
ThirdDepOptions="
$ThirdDepOptions
-DTIFF_INCLUDE_DIR=$CurrentDir/helpers/toolchain_builder/tiff;$ThirdPartyBuildDir/tiff
-DTIFF_LIBRARY_RELEASE=$ThirdPartyBuildDir/tiff/libtiff.a;$ThirdPartyBuildDir/jpeg/libjpeg.a"
fi
fi
# Rewrite a source file in place while keeping its original timestamp, so that
# patching and unpatching never look like a source change to CMake/Ninja.
# Otherwise the modified timestamp would force a re-configure (and a recompile
# of every touched file) on the next run, even though the content is unchanged.
PatchFileSafely()
{
PatchRule="$1"
PatchPath="$2"
if [ -f "$PatchPath" ]; then
sed -i.bak "$PatchRule" "$PatchPath"
if [ -f "$PatchPath.bak" ]; then
touch -r "$PatchPath.bak" "$PatchPath"
fi
fi
}
# Fix some OpenSceneGraph compile errors
if [ "$SkipOsgBuild" = 0 ]; then
echo "*** Automatically patching source code..."
OpenSceneGraphRoot=$CurrentDir/../OpenSceneGraph
PatchFileSafely 's/std::mem_fun_ref/std::mem_fn/g' "$OpenSceneGraphRoot/src/osgUtil/tristripper/include/detail/graph_array.h"
PatchFileSafely 's/if defined(__ANDROID__)/if defined(__EMSCRIPTEN__) || defined(__ANDROID__)/g' "$OpenSceneGraphRoot/src/osgDB/FileUtils.cpp"
PatchFileSafely 's/ADD_PLUGIN_DIRECTORY(cfg)/#ADD_PLUGIN_DIRECTORY(#cfg)/g' "$OpenSceneGraphRoot/src/osgPlugins/CMakeLists.txt"
PatchFileSafely 's/ADD_PLUGIN_DIRECTORY(obj)/#ADD_PLUGIN_DIRECTORY(#obj)/g' "$OpenSceneGraphRoot/src/osgPlugins/CMakeLists.txt"
PatchFileSafely 's/ADD_PLUGIN_DIRECTORY(ffmpeg)/#ADD_PLUGIN_DIRECTORY(#ffmpeg)/g' "$OpenSceneGraphRoot/src/osgPlugins/CMakeLists.txt"
PatchFileSafely 's/TIFF_FOUND AND OSG_CPP_EXCEPTIONS_AVAILABLE/TIFF_FOUND/g' "$OpenSceneGraphRoot/src/osgPlugins/CMakeLists.txt"
PatchFileSafely 's/ANDROID_3RD_PARTY()/#ANDROID_3RD_PARTY(#)/g' "$OpenSceneGraphRoot/CMakeLists.txt"
# Fix OpenSceneGraph build warnings and errors
if [ "$BuildMode" = '3' ] || [ "$BuildMode" = '4' ] || [ "$BuildMode" = '7' ]; then
PatchFileSafely 's#dlopen(#NULL;\/\/dlopen\/\/(#g' "$OpenSceneGraphRoot/src/osgDB/DynamicLibrary.cpp"
else
PatchFileSafely 's#NULL;\/\/dlopen\/\/(#dlopen(#g' "$OpenSceneGraphRoot/src/osgDB/DynamicLibrary.cpp"
fi
PatchFileSafely 's/#ifndef GL_EXT_texture_compression_s3tc/#if !defined(GL_EXT_texture_compression_s3tc) || !defined(GL_EXT_texture_compression_s3tc_srgb)/g' "$OpenSceneGraphRoot/include/osg/Texture"
PatchFileSafely 's#glTexParameterf(target, GL_TEXTURE_LOD_BIAS, _lodbias)#;\/\/glTexParameterf(target, \/\/GL_TEXTURE_LOD_BIAS, _lodbias)#g' "$OpenSceneGraphRoot/src/osg/Texture.cpp"
PatchFileSafely 's#case(GL_HALF_FLOAT):#case GL_HALF_FLOAT: case 0x8D61:#g' "$OpenSceneGraphRoot/src/osg/Image.cpp"
# Fix a static destruction order problem: an osg::GLExtensions object can outlive the static
# per-context buffers it resets in its destructor. When the last reference is released by a
# static destructor of another translation unit (the VertexArrayStates kept in ContextData),
# the buffers may already be destroyed, and ~GLExtensions() then writes into freed memory.
# This corrupts the heap at process exit: the crash surfaces in _dl_fini afterwards, e.g. a
# SIGSEGV in the Moore Threads driver's teardown when the bloom / eye-adaptation stages are
# enabled. Leaking a few kilobytes once removes the dependency on the destruction order.
PatchFileSafely 's#static osg::buffered_object<ExtensionSet> s_glExtensionSetList;#static osg::buffered_object<ExtensionSet>\& s_glExtensionSetList = *new osg::buffered_object<ExtensionSet>;#g' "$OpenSceneGraphRoot/src/osg/GLExtensions.cpp"
PatchFileSafely 's#static osg::buffered_object<std::string> s_glRendererList;#static osg::buffered_object<std::string>\& s_glRendererList = *new osg::buffered_object<std::string>;#g' "$OpenSceneGraphRoot/src/osg/GLExtensions.cpp"
PatchFileSafely 's#static osg::buffered_value<int> s_glInitializedList;#static osg::buffered_value<int>\& s_glInitializedList = *new osg::buffered_value<int>;#g' "$OpenSceneGraphRoot/src/osg/GLExtensions.cpp"
PatchFileSafely 's#static BufferedExtensions s_extensions;#static BufferedExtensions\& s_extensions = *new BufferedExtensions;#g' "$OpenSceneGraphRoot/src/osg/GLExtensions.cpp"
if [ "$BuildMode" = '3' ] || [ "$BuildMode" = '4' ] || [ "$BuildMode" = '7' ]; then
PatchFileSafely 's#isTexture2DArraySupported = validContext#isTexture2DArraySupported = isTexture3DSupported;\/\/validContext#g' "$OpenSceneGraphRoot/src/osg/GLExtensions.cpp"
fi
fi
# OpenSceneGraph 3.6.x only checks OSG_GLES1/GLES2 in the Android branch of
# getGLExtensionFuncPtr(), so an OPENGL_PROFILE=GLES3 build leaves 'handle' undeclared.
# GLES3 symbols are exported by libGLESv2.so as well, so reuse the GLES2 branch.
# This must also be applied when the OSG build is skipped, because Gradle builds OSG from
# source through android/osg/CMakeLists.txt and may recompile it at any time.
if [ "$BuildMode" = '5' ]; then
OpenSceneGraphRoot=$CurrentDir/../OpenSceneGraph
PatchFileSafely 's/#elif defined(OSG_GLES2_AVAILABLE)$/#elif defined(OSG_GLES3_AVAILABLE) || defined(OSG_GLES2_AVAILABLE)/g' \
"$OpenSceneGraphRoot/src/osg/GLExtensions.cpp"
fi
# 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_INSTALL_RPATH=$CurrentDir/build/sdk_core/lib
-DGLCORE_INCLUDE_DIR=$CurrentDir/helpers/toolchain_builder/opengl
-DOPENGL_INCLUDE_DIR=$CurrentDir/helpers/toolchain_builder/opengl
-DCMAKE_INSTALL_PREFIX=$CurrentDir/build/sdk_core
-DOPENGL_PROFILE=GLCORE"
if [ "$SkipOsgBuild" = 0 ]; then
cd $CurrentDir/build/osg_core
if [ "$SkipCMakeConfig" = 0 ]; then
$CMakeExe $ThirdDepOptions $ExtraOptions $OpenSceneGraphRoot
fi
cmake --build . -j8 --target install --config Release || exit 1
fi
elif [ "$BuildMode" = '2' ]; then
# OpenGL ES
if [ ! -d "$CurrentDir/build/osg_es" ]; then
mkdir $CurrentDir/build/osg_es
fi
ExtraOptions="
-DCMAKE_INSTALL_RPATH=$CurrentDir/build/sdk_es/lib
-DOPENGL_INCLUDE_DIR=$CurrentDir/helpers/toolchain_builder/opengl
-DCMAKE_INSTALL_PREFIX=$CurrentDir/build/sdk_es
-DEGL_LIBRARY=$EGL_LibPath -DOPENGL_gl_LIBRARY=$GLES_LibPath
-DOSG_WINDOWING_SYSTEM=None"
if [ "$SkipOsgBuild" = 0 ]; then
cd $CurrentDir/build/osg_es
if [ "$SkipCMakeConfig" = 0 ]; then
if [ "$UsingGles2" = 0 ]; then
$CMakeExe $ThirdDepOptions $ExtraOptions -DOPENGL_PROFILE=GLES3 $OpenSceneGraphRoot
else
$CMakeExe $ThirdDepOptions $ExtraOptions -DOPENGL_PROFILE=GLES2 $OpenSceneGraphRoot
fi
fi
cmake --build . -j8 --target install --config Release || exit 1
fi
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 . -j8 --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 . -j8 --target install --config Release || exit 1
fi
elif [ "$BuildMode" = '5' ]; then
# Android toolchain
echo "The compilation will be processed by Gradle..."
elif [ "$BuildMode" = '7' ]; then
# WASM toolchain (WebGPU, with GLES 3 served by gles-on-webgpu)
if [ ! -d "$CurrentDir/build/osg_webgpu" ]; then
mkdir $CurrentDir/build/osg_webgpu
fi
# No GL emulation flags here: every gl*() call must resolve to gles-on-webgpu
ExtraOptions="
-DCMAKE_TOOLCHAIN_FILE="$EmsdkToolchain"
-DCMAKE_POLICY_VERSION_MINIMUM=3.5
-DCMAKE_INSTALL_PREFIX=$CurrentDir/build/sdk_wasm_webgpu
-DOSG_SOURCE_DIR=$OpenSceneGraphRoot
-DOSG_BUILD_DIR=$CurrentDir/build/osg_webgpu/osg
-DANGLE_INCLUDE_DIR=$AngleWasmRoot/include
-DOPENGL_INCLUDE_DIR=$AngleWasmRoot/include
-DEGL_INCLUDE_DIR=$AngleWasmRoot/include
-DOPENGL_gl_LIBRARY=$AngleWasmRoot/lib/libGLESv2_EGL.a
-DEGL_LIBRARY=$AngleWasmRoot/lib/libGLESv2_EGL.a"
if [ "$SkipOsgBuild" = 0 ]; then
cd $CurrentDir/build/osg_webgpu
if [ "$SkipCMakeConfig" = 0 ]; then
$CMakeExe $ExtraOptions $CurrentDir/helpers/osg_builder/webgpu
fi
cmake --build . -j8 --target install --config Release || exit 1
fi
if [ ! -f "$CurrentDir/build/sdk_wasm_webgpu/lib/libosgViewer.a" ]; then
echo "libosgViewer.a was not installed in build/sdk_wasm_webgpu/lib"
exit 1
fi
else
# OpenGL default
if [ ! -d "$CurrentDir/build/osg_def" ]; then
mkdir $CurrentDir/build/osg_def
fi
ExtraOptions="
-DCMAKE_INSTALL_RPATH=$CurrentDir/build/sdk/lib
-DCMAKE_INSTALL_PREFIX=$CurrentDir/build/sdk"
if [ "$SkipOsgBuild" = 0 ]; then
cd $CurrentDir/build/osg_def
if [ "$SkipCMakeConfig" = 0 ]; then
$CMakeExe $ThirdDepOptions $ExtraOptions $OpenSceneGraphRoot
fi
cmake --build . -j8 --target install --config Release || exit 1
fi
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 . -j8 --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 . -j8 --target install --config Release || exit 1
elif [ "$BuildMode" = '5' ]; then
# Android toolchain
cd $CurrentDir/android
./gradlew assemble${AndroidBuildType} -Pabi=$AndroidAbi || exit 1
# adb install -r android/app/build/outputs/apk/debug/app-debug.apk
# adb logcat -s osgVerse SDL
elif [ "$BuildMode" = '7' ]; then
# WASM toolchain (WebGPU, with GLES 3 served by gles-on-webgpu)
if [ ! -d "$CurrentDir/build/verse_wasm_webgpu" ]; then
mkdir $CurrentDir/build/verse_wasm_webgpu
fi
# Only the libraries are built: the wasm demos shipped with osgVerse target
# WebGL 2 (SDL window + -sFULL_ES3), which this build does not use. The
# WebGPU counterpart is wasm/wgpu_simple_demo, built below.
OsgRootLocation="$CurrentDir/build/sdk_wasm_webgpu"
cd $CurrentDir/build/verse_wasm_webgpu
$CMakeExe -DUSE_WASM_OPTIONS=$UseWasmOption -DVERSE_USE_WEBGPU=ON \
-DVERSE_BUILD_EXAMPLES=OFF -DVERSE_ENABLE_GLFW=OFF -DVERSE_BUILD_WITH_CUDA=OFF \
-DOSG_GLES_INCLUDE_DIR=$AngleWasmRoot/include \
-DOSG_GLES_LIBRARY=$AngleWasmRoot/lib/libGLESv2_EGL.a \
-DOSG_EGL_LIBRARY=$AngleWasmRoot/lib/libGLESv2_EGL.a \
-DCMAKE_C_FLAGS="-I$AngleWasmRoot/include" \
-DCMAKE_CXX_FLAGS="-I$AngleWasmRoot/include" \
-DOSG_ROOT="$OsgRootLocation" $ThirdDepOptions $ExtraOptions $CurrentDir
cmake --build . -j8 --config Release --target $VerseLibraryTargets || exit 1
if [ ! -f "$CurrentDir/build/verse_wasm_webgpu/lib/libosgVersePipeline.a" ]; then
echo "osgVerse libraries were not produced in build/verse_wasm_webgpu/lib"
exit 1
fi
# The WebGPU demo is configured as its own project because a WebGPU build
# links different libraries than the WebGL 2 build above.
echo "*** Building wasm/wgpu_simple_demo..."
if [ ! -d "$CurrentDir/build/wgpu_simple_wasm" ]; then
mkdir $CurrentDir/build/wgpu_simple_wasm
fi
cd $CurrentDir/build/wgpu_simple_wasm
$CMakeExe -DCMAKE_TOOLCHAIN_FILE="$EmsdkToolchain" \
-DANGLE_WASM_ROOT=$AngleWasmRoot \
-DOSG_SDK=$CurrentDir/build/sdk_wasm_webgpu \
-DVERSE_BUILD=$CurrentDir/build/verse_wasm_webgpu \
-DOSGVERSE_SRC=$CurrentDir \
-DTHIRDPARTY_WASM=$ThirdPartyBuildDir \
$CurrentDir/wasm/wgpu_simple_demo
cmake --build . -j8 || exit 1
echo "The page is ready. Serve it with a COOP/COEP server for SharedArrayBuffer:"
echo " cd $CurrentDir/build/wgpu_simple_wasm/out"
echo " python3 $CurrentDir/wasm/run_webserver.py"
echo " then open http://127.0.0.1:8000/osgVerse_WebGPUSimple.html"
else
# Default toolchain
if [ "$BuildMode" = '1' ]; then
ExtraOptions2="-DOPENGL_INCLUDE_DIR=$CurrentDir/helpers/toolchain_builder/opengl"
OsgRootLocation="$CurrentDir/build/sdk_core"
if [ ! -d "$CurrentDir/build/verse_core" ]; then
mkdir $CurrentDir/build/verse_core
fi
cd $CurrentDir/build/verse_core
elif [ "$BuildMode" = '2' ]; then
ExtraOptions2="-DOPENGL_INCLUDE_DIR=$CurrentDir/helpers/toolchain_builder/opengl
-DOSG_EGL_LIBRARY=$EGL_LibPath -DOSG_GLES_LIBRARY=$GLES_LibPath"
OsgRootLocation="$CurrentDir/build/sdk_es"
if [ ! -d "$CurrentDir/build/verse_es" ]; then
mkdir $CurrentDir/build/verse_es
fi
cd $CurrentDir/build/verse_es
else
ExtraOptions2=""
OsgRootLocation="$CurrentDir/build/sdk"
if [ ! -d "$CurrentDir/build/verse_def" ]; then
mkdir $CurrentDir/build/verse_def
fi
cd $CurrentDir/build/verse_def
fi
$CMakeExe -DOSG_ROOT="$OsgRootLocation" $ThirdDepOptions $ExtraOptions $ExtraOptions2 $CurrentDir
cmake --build . -j8 --target install --config Release || exit 1
fi
# Reset some OpenSceneGraph source code
if [ "$SkipOsgBuild" = 0 ]; then
echo "*** Automatically unpatching source code..."
PatchFileSafely 's/ADD_PLUGIN_DIRECTORY(#cfg)/#ADD_PLUGIN_DIRECTORY(cfg)/g' "$OpenSceneGraphRoot/src/osgPlugins/CMakeLists.txt"
PatchFileSafely 's/ADD_PLUGIN_DIRECTORY(#obj)/#ADD_PLUGIN_DIRECTORY(obj)/g' "$OpenSceneGraphRoot/src/osgPlugins/CMakeLists.txt"
PatchFileSafely 's/ADD_PLUGIN_DIRECTORY(#ffmpeg)/#ADD_PLUGIN_DIRECTORY(ffmpeg)/g' "$OpenSceneGraphRoot/src/osgPlugins/CMakeLists.txt"
PatchFileSafely 's/#ANDROID_3RD_PARTY(#)/ANDROID_3RD_PARTY()/g' "$OpenSceneGraphRoot/CMakeLists.txt"
PatchFileSafely 's#NULL;\/\/dlopen\/\/(#dlopen(#g' "$OpenSceneGraphRoot/src/osgDB/DynamicLibrary.cpp"
PatchFileSafely 's#;\/\/glTexParameterf(target, \/\/GL_TEXTURE_LOD_BIAS, _lodbias)#glTexParameterf(target, GL_TEXTURE_LOD_BIAS, _lodbias)#g' "$OpenSceneGraphRoot/src/osg/Texture.cpp"
PatchFileSafely 's#isTexture2DArraySupported = isTexture3DSupported;\/\/validContext#isTexture2DArraySupported = validContext#g' "$OpenSceneGraphRoot/src/osg/GLExtensions.cpp"
fi