-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
executable file
·961 lines (876 loc) · 37 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
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
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
#!/bin/bash
# BSD 2-Clause License
#
# Copyright (c) 2021-2023, Christoph Neuhauser
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
set -euo pipefail
scriptpath="$( cd "$(dirname "$0")" ; pwd -P )"
projectpath="$scriptpath"
pushd $scriptpath > /dev/null
if [[ "$(uname -s)" =~ ^MSYS_NT.* ]] || [[ "$(uname -s)" =~ ^MINGW.* ]]; then
use_msys=true
else
use_msys=false
fi
if [[ "$(uname -s)" =~ ^Darwin.* ]]; then
use_macos=true
else
use_macos=false
fi
os_arch="$(uname -m)"
run_program=true
debug=false
glibcxx_debug=false
build_dir_debug=".build_debug"
build_dir_release=".build_release"
use_vcpkg=false
link_dynamic=false
custom_glslang=false
# Process command line arguments.
for ((i=1;i<=$#;i++));
do
if [ ${!i} = "--do-not-run" ]; then
run_program=false
elif [ ${!i} = "--debug" ] || [ ${!i} = "debug" ]; then
debug=true
elif [ ${!i} = "--glibcxx-debug" ]; then
glibcxx_debug=true
elif [ ${!i} = "--vcpkg" ]; then
use_vcpkg=true
elif [ ${!i} = "--link-static" ]; then
link_dynamic=false
elif [ ${!i} = "--link-dynamic" ]; then
link_dynamic=true
elif [ ${!i} = "--custom-glslang" ]; then
custom_glslang=true
fi
done
if [ $debug = true ]; then
cmake_config="Debug"
build_dir=$build_dir_debug
else
cmake_config="Release"
build_dir=$build_dir_release
fi
destination_dir="Shipping"
if $use_macos; then
binaries_dest_dir="$destination_dir/CloudRendering.app/Contents/MacOS"
if ! command -v brew &> /dev/null; then
if [ ! -d "/opt/homebrew/bin" ]; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
if [ -d "/opt/homebrew/bin" ]; then
#echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/$USER/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
fi
fi
params_link=()
params_vcpkg=()
if [ $use_vcpkg = true ] && [ $use_macos = false ] && [ $link_dynamic = true ]; then
params_link+=(-DVCPKG_TARGET_TRIPLET=x64-linux-dynamic)
fi
if [ $use_vcpkg = true ] && [ $use_macos = false ]; then
params_vcpkg+=(-DUSE_STATIC_STD_LIBRARIES=On)
fi
if [ $use_vcpkg = true ]; then
params_vcpkg+=(-DCMAKE_TOOLCHAIN_FILE="$projectpath/third_party/vcpkg/scripts/buildsystems/vcpkg.cmake")
fi
is_installed_apt() {
local pkg_name="$1"
if [ "$(dpkg -l | awk '/'"$pkg_name"'/ {print }'|wc -l)" -ge 1 ]; then
return 0
else
return 1
fi
}
is_installed_pacman() {
local pkg_name="$1"
if pacman -Qs $pkg_name > /dev/null; then
return 0
else
return 1
fi
}
is_installed_yay() {
local pkg_name="$1"
if yay -Ss $pkg_name > /dev/null | grep -q 'instal'; then
return 1
else
return 0
fi
}
is_installed_yum() {
local pkg_name="$1"
if yum list installed "$pkg_name" > /dev/null 2>&1; then
return 0
else
return 1
fi
}
is_installed_rpm() {
local pkg_name="$1"
if rpm -q "$pkg_name" > /dev/null 2>&1; then
return 0
else
return 1
fi
}
is_installed_brew() {
local pkg_name="$1"
if brew list $pkg_name > /dev/null; then
return 0
else
return 1
fi
}
if $use_msys && command -v pacman &> /dev/null && [ ! -d $build_dir_debug ] && [ ! -d $build_dir_release ]; then
if ! command -v cmake &> /dev/null || ! command -v git &> /dev/null || ! command -v rsync &> /dev/null \
|| ! command -v curl &> /dev/null || ! command -v wget &> /dev/null \
|| ! command -v pkg-config &> /dev/null || ! command -v g++ &> /dev/null; then
echo "------------------------"
echo "installing build essentials"
echo "------------------------"
pacman --noconfirm -S --needed make git rsync curl wget mingw64/mingw-w64-x86_64-cmake \
mingw64/mingw-w64-x86_64-gcc mingw64/mingw-w64-x86_64-gdb
fi
# Dependencies of sgl and the application.
if ! is_installed_pacman "mingw-w64-x86_64-boost" || ! is_installed_pacman "mingw-w64-x86_64-glm" \
|| ! is_installed_pacman "mingw-w64-x86_64-libarchive" || ! is_installed_pacman "mingw-w64-x86_64-tinyxml2" \
|| ! is_installed_pacman "mingw-w64-x86_64-libpng" || ! is_installed_pacman "mingw-w64-x86_64-SDL2" \
|| ! is_installed_pacman "mingw-w64-x86_64-SDL2_image" || ! is_installed_pacman "mingw-w64-x86_64-glew" \
|| ! is_installed_pacman "mingw-w64-x86_64-vulkan-headers" \
|| ! is_installed_pacman "mingw-w64-x86_64-vulkan-loader" \
|| ! is_installed_pacman "mingw-w64-x86_64-vulkan-validation-layers" \
|| ! is_installed_pacman "mingw-w64-x86_64-shaderc" \
|| ! is_installed_pacman "mingw-w64-x86_64-opencl-headers" \
|| ! is_installed_pacman "mingw-w64-x86_64-opencl-icd" || ! is_installed_pacman "mingw-w64-x86_64-jsoncpp" \
|| ! is_installed_pacman "mingw-w64-x86_64-openexr"; then
echo "------------------------"
echo "installing dependencies "
echo "------------------------"
pacman --noconfirm -S --needed mingw64/mingw-w64-x86_64-boost mingw64/mingw-w64-x86_64-glm \
mingw64/mingw-w64-x86_64-libarchive mingw64/mingw-w64-x86_64-tinyxml2 mingw64/mingw-w64-x86_64-libpng \
mingw64/mingw-w64-x86_64-SDL2 mingw64/mingw-w64-x86_64-SDL2_image mingw64/mingw-w64-x86_64-glew \
mingw64/mingw-w64-x86_64-vulkan-headers mingw64/mingw-w64-x86_64-vulkan-loader \
mingw64/mingw-w64-x86_64-vulkan-validation-layers mingw64/mingw-w64-x86_64-shaderc \
mingw64/mingw-w64-x86_64-opencl-headers mingw64/mingw-w64-x86_64-opencl-icd mingw64/mingw-w64-x86_64-jsoncpp \
mingw64/mingw-w64-x86_64-openexr
fi
elif $use_macos && command -v brew &> /dev/null && [ ! -d $build_dir_debug ] && [ ! -d $build_dir_release ]; then
if ! is_installed_brew "git"; then
brew install git
fi
if ! is_installed_brew "cmake"; then
brew install cmake
fi
if ! is_installed_brew "curl"; then
brew install curl
fi
if ! is_installed_brew "pkg-config"; then
brew install pkg-config
fi
if ! is_installed_brew "llvm"; then
brew install llvm
fi
if ! is_installed_brew "libomp"; then
brew install libomp
fi
# Homebrew MoltenVK does not contain script for setting environment variables, unfortunately.
#if ! is_installed_brew "molten-vk"; then
# brew install molten-vk
#fi
# Dependencies of sgl and the application.
if [ $use_vcpkg = false ]; then
if ! is_installed_brew "boost"; then
brew install boost
fi
if ! is_installed_brew "glm"; then
brew install glm
fi
if ! is_installed_brew "libarchive"; then
brew install libarchive
fi
if ! is_installed_brew "tinyxml2"; then
brew install tinyxml2
fi
if ! is_installed_brew "zlib"; then
brew install zlib
fi
if ! is_installed_brew "libpng"; then
brew install libpng
fi
if ! is_installed_brew "sdl2"; then
brew install sdl2
fi
if ! is_installed_brew "sdl2_image"; then
brew install sdl2_image
fi
if ! is_installed_brew "glew"; then
brew install glew
fi
if ! is_installed_brew "opencl-headers"; then
brew install opencl-headers
fi
if ! is_installed_brew "jsoncpp"; then
brew install jsoncpp
fi
if ! is_installed_brew "openexr"; then
brew install openexr
fi
fi
elif command -v apt &> /dev/null; then
if ! command -v cmake &> /dev/null || ! command -v git &> /dev/null || ! command -v curl &> /dev/null \
|| ! command -v pkg-config &> /dev/null || ! command -v g++ &> /dev/null \
|| ! command -v patchelf &> /dev/null; then
echo "------------------------"
echo "installing build essentials"
echo "------------------------"
sudo apt install -y cmake git curl pkg-config build-essential patchelf
fi
# Dependencies of sgl and the application.
if $use_vcpkg; then
if ! is_installed_apt "libgl-dev" || ! is_installed_apt "libxmu-dev" || ! is_installed_apt "libxi-dev" \
|| ! is_installed_apt "libx11-dev" || ! is_installed_apt "libxft-dev" \
|| ! is_installed_apt "libxext-dev" || ! is_installed_apt "libwayland-dev" \
|| ! is_installed_apt "libxkbcommon-dev" || ! is_installed_apt "libegl1-mesa-dev"; then
echo "------------------------"
echo "installing dependencies "
echo "------------------------"
sudo apt install -y libgl-dev libxmu-dev libxi-dev libx11-dev libxft-dev libxext-dev libwayland-dev \
libxkbcommon-dev libegl1-mesa-dev
fi
else
if ! is_installed_apt "libboost-filesystem-dev" || ! is_installed_apt "libglm-dev" \
|| ! is_installed_apt "libarchive-dev" || ! is_installed_apt "libtinyxml2-dev" \
|| ! is_installed_apt "libpng-dev" || ! is_installed_apt "libsdl2-dev" \
|| ! is_installed_apt "libsdl2-image-dev" || ! is_installed_apt "libglew-dev" \
|| ! is_installed_apt "opencl-c-headers" || ! is_installed_apt "ocl-icd-opencl-dev" \
|| ! is_installed_apt "libjsoncpp-dev" || ! is_installed_apt "libopenexr-dev"; then
echo "------------------------"
echo "installing dependencies "
echo "------------------------"
sudo apt install -y libboost-filesystem-dev libglm-dev libarchive-dev libtinyxml2-dev libpng-dev libsdl2-dev \
libsdl2-image-dev libglew-dev opencl-c-headers ocl-icd-opencl-dev libjsoncpp-dev libopenexr-dev
fi
fi
elif command -v pacman &> /dev/null; then
if ! command -v cmake &> /dev/null || ! command -v git &> /dev/null || ! command -v curl &> /dev/null \
|| ! command -v pkg-config &> /dev/null || ! command -v g++ &> /dev/null \
|| ! command -v patchelf &> /dev/null; then
echo "------------------------"
echo "installing build essentials"
echo "------------------------"
sudo pacman -S cmake git curl pkgconf base-devel patchelf
fi
# Dependencies of sgl and the application.
if $use_vcpkg; then
if ! is_installed_pacman "libgl" || ! is_installed_pacman "vulkan-devel" || ! is_installed_pacman "shaderc" \
|| ! is_installed_pacman "openssl"; then
echo "------------------------"
echo "installing dependencies "
echo "------------------------"
sudo pacman -S libgl vulkan-devel shaderc openssl
fi
else
if ! is_installed_pacman "boost" || ! is_installed_pacman "glm" || ! is_installed_pacman "libarchive" \
|| ! is_installed_pacman "tinyxml2" || ! is_installed_pacman "libpng" || ! is_installed_pacman "sdl2" \
|| ! is_installed_pacman "sdl2_image" || ! is_installed_pacman "glew" \
|| ! is_installed_pacman "vulkan-devel" || ! is_installed_pacman "shaderc" \
|| ! is_installed_pacman "opencl-headers" || ! is_installed_pacman "ocl-icd" \
|| ! is_installed_pacman "jsoncpp" || ! is_installed_pacman "openexr"; then
echo "------------------------"
echo "installing dependencies "
echo "------------------------"
sudo pacman -S boost glm libarchive tinyxml2 libpng sdl2 sdl2_image glew vulkan-devel shaderc opencl-headers \
ocl-icd jsoncpp openexr
fi
fi
elif command -v yum &> /dev/null; then
if ! command -v cmake &> /dev/null || ! command -v git &> /dev/null || ! command -v curl &> /dev/null \
|| ! command -v pkg-config &> /dev/null || ! command -v g++ &> /dev/null \
|| ! command -v patchelf &> /dev/null; then
echo "------------------------"
echo "installing build essentials"
echo "------------------------"
sudo yum install -y cmake git curl pkgconf gcc gcc-c++ patchelf
fi
# Dependencies of sgl and the application.
if $use_vcpkg; then
if ! is_installed_rpm "perl" || ! is_installed_rpm "libstdc++-devel" || ! is_installed_rpm "libstdc++-static" \
|| ! is_installed_rpm "glew-devel" || ! is_installed_rpm "libXext-devel" \
|| ! is_installed_rpm "vulkan-devel" || ! is_installed_rpm "libshaderc-devel"; then
echo "------------------------"
echo "installing dependencies "
echo "------------------------"
sudo yum install -y perl libstdc++-devel libstdc++-static glew-devel libXext-devel vulkan-devel \
libshaderc-devel
fi
else
if ! is_installed_rpm "boost-devel" || ! is_installed_rpm "glm-devel" || ! is_installed_rpm "libarchive-devel" \
|| ! is_installed_rpm "tinyxml2-devel" || ! is_installed_rpm "libpng-devel" \
|| ! is_installed_rpm "SDL2-devel" || ! is_installed_rpm "SDL2_image-devel" \
|| ! is_installed_rpm "glew-devel" || ! is_installed_rpm "vulkan-headers" \
|| ! is_installed_rpm "libshaderc-devel" || ! is_installed_rpm "opencl-headers" \
|| ! is_installed_rpm "ocl-icd" || ! is_installed_rpm "jsoncpp-devel" \
|| ! is_installed_rpm "openexr-devel"; then
echo "------------------------"
echo "installing dependencies "
echo "------------------------"
sudo yum install -y boost-devel glm-devel libarchive-devel tinyxml2-devel libpng-devel SDL2-devel \
SDL2_image-devel glew-devel vulkan-headers libshaderc-devel opencl-headers ocl-icd jsoncpp-devel \
openexr-devel
fi
fi
else
echo "Warning: Unsupported system package manager detected." >&2
fi
if ! command -v cmake &> /dev/null; then
echo "CMake was not found, but is required to build the program."
exit 1
fi
if ! command -v git &> /dev/null; then
echo "git was not found, but is required to build the program."
exit 1
fi
if ! command -v curl &> /dev/null; then
echo "curl was not found, but is required to build the program."
exit 1
fi
if [ $use_macos = false ] && ! command -v pkg-config &> /dev/null; then
echo "pkg-config was not found, but is required to build the program."
exit 1
fi
[ -d "./third_party/" ] || mkdir "./third_party/"
pushd third_party > /dev/null
params_sgl=()
params=()
params_run=()
params_gen=()
if [ $use_msys = true ]; then
params_gen+=(-G "MSYS Makefiles")
params_sgl+=(-G "MSYS Makefiles")
params+=(-G "MSYS Makefiles")
fi
if [ $use_vcpkg = false ] && [ $use_macos = true ]; then
params_gen+=(-DCMAKE_FIND_USE_CMAKE_SYSTEM_PATH=False)
params_gen+=(-DCMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH=False)
params_gen+=(-DCMAKE_FIND_FRAMEWORK=LAST)
params_gen+=(-DCMAKE_FIND_APPBUNDLE=NEVER)
params_gen+=(-DCMAKE_PREFIX_PATH="$(brew --prefix)")
params_sgl+=(-DCMAKE_INSTALL_PREFIX="../install")
params_sgl+=(-DZLIB_ROOT="$(brew --prefix)/opt/zlib")
params+=(-DZLIB_ROOT="$(brew --prefix)/opt/zlib")
fi
if $glibcxx_debug; then
params_sgl+=(-DUSE_GLIBCXX_DEBUG=On)
params+=(-DUSE_GLIBCXX_DEBUG=On)
fi
use_vulkan=false
vulkan_sdk_env_set=true
use_vulkan=true
search_for_vulkan_sdk=false
if [ $use_msys = false ] && [ -z "${VULKAN_SDK+1}" ]; then
search_for_vulkan_sdk=true
fi
if [ $search_for_vulkan_sdk = true ]; then
echo "------------------------"
echo "searching for Vulkan SDK"
echo "------------------------"
found_vulkan=false
if [ $use_macos = false ]; then
if [ -d "VulkanSDK" ]; then
VK_LAYER_PATH=""
source "VulkanSDK/$(ls VulkanSDK)/setup-env.sh"
pkgconfig_dir="$(realpath "VulkanSDK/$(ls VulkanSDK)/$os_arch/lib/pkgconfig")"
if [ -d "$pkgconfig_dir" ]; then
export PKG_CONFIG_PATH="$pkgconfig_dir"
fi
found_vulkan=true
fi
if ! $found_vulkan && (lsb_release -a 2> /dev/null | grep -q 'Ubuntu' || lsb_release -a 2> /dev/null | grep -q 'Mint'); then
if lsb_release -a 2> /dev/null | grep -q 'Ubuntu'; then
distro_code_name=$(lsb_release -cs)
else
distro_code_name=$(cat /etc/upstream-release/lsb-release | grep "DISTRIB_CODENAME=" | sed 's/^.*=//')
fi
if ! compgen -G "/etc/apt/sources.list.d/lunarg-vulkan-*" > /dev/null \
&& ! curl -s -I "https://packages.lunarg.com/vulkan/dists/${distro_code_name}/" | grep "2 404" > /dev/null; then
echo "Setting up Vulkan SDK for $(lsb_release -ds)..."
wget -qO - https://packages.lunarg.com/lunarg-signing-key-pub.asc | sudo apt-key add -
sudo curl --silent --show-error --fail \
https://packages.lunarg.com/vulkan/lunarg-vulkan-${distro_code_name}.list \
--output /etc/apt/sources.list.d/lunarg-vulkan-${distro_code_name}.list
sudo apt update
sudo apt install -y vulkan-sdk shaderc glslang-dev
fi
fi
if [ -d "/usr/include/vulkan" ] && [ -d "/usr/include/shaderc" ]; then
if ! grep -q VULKAN_SDK ~/.bashrc; then
echo 'export VULKAN_SDK="/usr"' >> ~/.bashrc
fi
export VULKAN_SDK="/usr"
found_vulkan=true
fi
if ! $found_vulkan; then
curl --silent --show-error --fail -O https://sdk.lunarg.com/sdk/download/latest/linux/vulkan-sdk.tar.gz
mkdir -p VulkanSDK
tar -xf vulkan-sdk.tar.gz -C VulkanSDK
VK_LAYER_PATH=""
source "VulkanSDK/$(ls VulkanSDK)/setup-env.sh"
# Fix pkgconfig file.
shaderc_pkgconfig_file="VulkanSDK/$(ls VulkanSDK)/$os_arch/lib/pkgconfig/shaderc.pc"
if [ -f "$shaderc_pkgconfig_file" ]; then
prefix_path=$(realpath "VulkanSDK/$(ls VulkanSDK)/$os_arch")
sed -i '3s;.*;prefix=\"'$prefix_path'\";' "$shaderc_pkgconfig_file"
sed -i '5s;.*;libdir=${prefix}/lib;' "$shaderc_pkgconfig_file"
export PKG_CONFIG_PATH="$(realpath "VulkanSDK/$(ls VulkanSDK)/$os_arch/lib/pkgconfig")"
fi
found_vulkan=true
fi
else
if [ -d "$HOME/VulkanSDK" ] && [ ! -z "$(ls -A "$HOME/VulkanSDK")" ]; then
source "$HOME/VulkanSDK/$(ls $HOME/VulkanSDK)/setup-env.sh"
found_vulkan=true
else
vulkansdk_filename=$(curl -sIkL https://sdk.lunarg.com/sdk/download/latest/mac/vulkan-sdk.dmg | sed -r '/filename=/!d;s/.*filename=(.*)$/\1/')
VULKAN_SDK_VERSION=$(echo $vulkansdk_filename | sed -r 's/^.*vulkansdk-macos-(.*)\.dmg.*$/\1/')
curl -O https://sdk.lunarg.com/sdk/download/latest/mac/vulkan-sdk.dmg
sudo hdiutil attach vulkan-sdk.dmg
# The directory was changed from '/Volumes/VulkanSDK' to, e.g., 'vulkansdk-macos-1.3.261.0'.
vulkan_dir=$(find /Volumes -maxdepth 1 -name '[Vv]ulkan*' -not -path "/Volumes/VMware*" || true)
sudo "${vulkan_dir}/InstallVulkan.app/Contents/MacOS/InstallVulkan" \
--root ~/VulkanSDK/$VULKAN_SDK_VERSION --accept-licenses --default-answer --confirm-command install
pushd ~/VulkanSDK/$VULKAN_SDK_VERSION
sudo python3 ./install_vulkan.py || true
popd
sudo hdiutil unmount "${vulkan_dir}"
source "$HOME/VulkanSDK/$(ls $HOME/VulkanSDK)/setup-env.sh"
found_vulkan=true
fi
fi
if ! $found_vulkan; then
if [ $use_macos = false ]; then
os_name="linux"
else
os_name="mac"
fi
echo "The environment variable VULKAN_SDK is not set but is required in the installation process."
echo "Please refer to https://vulkan.lunarg.com/sdk/home#${os_name} for instructions on how to install the Vulkan SDK."
exit 1
fi
fi
if $custom_glslang; then
if [ ! -d "./glslang" ]; then
echo "------------------------"
echo " downloading glslang "
echo "------------------------"
# Make sure we have no leftovers from a failed build attempt.
if [ -d "./glslang-src" ]; then
rm -rf "./glslang-src"
fi
git clone https://github.com/KhronosGroup/glslang.git glslang-src
pushd glslang-src >/dev/null
./update_glslang_sources.py
mkdir build
pushd build >/dev/null
cmake ${params_gen[@]+"${params_gen[@]}"} -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="${projectpath}/third_party/glslang" ..
make -j $(nproc)
make install
popd >/dev/null
popd >/dev/null
fi
params_sgl+=(-Dglslang_DIR="${projectpath}/third_party/glslang" -DUSE_SHADERC=Off)
fi
if [ $use_msys = false ] && [ -z "${VULKAN_SDK+1}" ]; then
vulkan_sdk_env_set=true
fi
if [ $use_vcpkg = true ] && [ ! -d "./vcpkg" ]; then
echo "------------------------"
echo " fetching vcpkg "
echo "------------------------"
if $use_vulkan && [ $vulkan_sdk_env_set = false ]; then
echo "The environment variable VULKAN_SDK is not set but is required in the installation process."
exit 1
fi
git clone --depth 1 https://github.com/Microsoft/vcpkg.git
vcpkg/bootstrap-vcpkg.sh -disableMetrics
vcpkg/vcpkg install
fi
if [ $use_vcpkg = true ] && [ $use_macos = false ] && [ $link_dynamic = false ]; then
params_sgl+=(-DBUILD_STATIC_LIBRARY=On)
fi
if [ ! -d "./sgl" ]; then
echo "------------------------"
echo " fetching sgl "
echo "------------------------"
git clone --depth 1 https://github.com/chrismile/sgl.git
fi
if [ -f "./sgl/$build_dir/CMakeCache.txt" ]; then
if grep -q vcpkg_installed "./sgl/$build_dir/CMakeCache.txt"; then
cache_uses_vcpkg=true
else
cache_uses_vcpkg=false
fi
if ([ $use_vcpkg = true ] && [ $cache_uses_vcpkg = false ]) || ([ $use_vcpkg = false ] && [ $cache_uses_vcpkg = true ]); then
echo "Removing old sgl build cache..."
if [ -d "./sgl/$build_dir_debug" ]; then
rm -rf "./sgl/$build_dir_debug"
fi
if [ -d "./sgl/$build_dir_release" ]; then
rm -rf "./sgl/$build_dir_release"
fi
if [ -d "./sgl/install" ]; then
rm -rf "./sgl/install"
fi
fi
fi
if [ ! -d "./sgl/install" ]; then
echo "------------------------"
echo " building sgl "
echo "------------------------"
pushd "./sgl" >/dev/null
mkdir -p $build_dir_debug
mkdir -p $build_dir_release
pushd "$build_dir_debug" >/dev/null
cmake .. \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_INSTALL_PREFIX="../install" \
${params_gen[@]+"${params_gen[@]}"} ${params_link[@]+"${params_link[@]}"} \
${params_vcpkg[@]+"${params_vcpkg[@]}"} ${params_sgl[@]+"${params_sgl[@]}"}
if [ $use_vcpkg = false ] && [ $use_macos = false ]; then
make -j $(nproc)
make install
fi
popd >/dev/null
pushd $build_dir_release >/dev/null
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="../install" \
${params_gen[@]+"${params_gen[@]}"} ${params_link[@]+"${params_link[@]}"} \
${params_vcpkg[@]+"${params_vcpkg[@]}"} ${params_sgl[@]+"${params_sgl[@]}"}
if [ $use_vcpkg = false ] && [ $use_macos = false ]; then
make -j $(nproc)
make install
fi
popd >/dev/null
if [ $use_macos = true ]; then
cmake --build $build_dir_debug --parallel $(sysctl -n hw.ncpu)
cmake --build $build_dir_debug --target install
cmake --build $build_dir_release --parallel $(sysctl -n hw.ncpu)
cmake --build $build_dir_release --target install
elif [ $use_vcpkg = true ]; then
cmake --build $build_dir_debug --parallel $(nproc)
cmake --build $build_dir_debug --target install
if [ $link_dynamic = true ]; then
cp $build_dir_debug/libsgld.so install/lib/libsgld.so
fi
cmake --build $build_dir_release --parallel $(nproc)
cmake --build $build_dir_release --target install
if [ $link_dynamic = true ]; then
cp $build_dir_release/libsgl.so install/lib/libsgl.so
fi
fi
popd >/dev/null
fi
popd >/dev/null # back to project root
if [ $debug = true ]; then
echo "------------------------"
echo " building in debug "
echo "------------------------"
else
echo "------------------------"
echo " building in release "
echo "------------------------"
fi
if [ -f "./$build_dir/CMakeCache.txt" ]; then
if grep -q vcpkg_installed "./$build_dir/CMakeCache.txt"; then
cache_uses_vcpkg=true
else
cache_uses_vcpkg=false
fi
if ([ $use_vcpkg = true ] && [ $cache_uses_vcpkg = false ]) || ([ $use_vcpkg = false ] && [ $cache_uses_vcpkg = true ]); then
echo "Removing old application build cache..."
if [ -d "./$build_dir_debug" ]; then
rm -rf "./$build_dir_debug"
fi
if [ -d "./$build_dir_release" ]; then
rm -rf "./$build_dir_release"
fi
if [ -d "./$destination_dir" ]; then
rm -rf "./$destination_dir"
fi
fi
fi
mkdir -p $build_dir
echo "------------------------"
echo " generating "
echo "------------------------"
pushd $build_dir >/dev/null
cmake .. \
-DCMAKE_BUILD_TYPE=$cmake_config \
-Dsgl_DIR="$projectpath/third_party/sgl/install/lib/cmake/sgl/" \
${params_gen[@]+"${params_gen[@]}"} ${params_link[@]+"${params_link[@]}"} \
${params_vcpkg[@]+"${params_vcpkg[@]}"} ${params[@]+"${params[@]}"}
popd >/dev/null
echo "------------------------"
echo " compiling "
echo "------------------------"
if [ $use_macos = true ]; then
cmake --build $build_dir --parallel $(sysctl -n hw.ncpu)
elif [ $use_vcpkg = true ]; then
cmake --build $build_dir --parallel $(nproc)
else
pushd "$build_dir" >/dev/null
make -j $(nproc)
popd >/dev/null
fi
echo "------------------------"
echo " copying new files "
echo "------------------------"
# https://stackoverflow.com/questions/2829613/how-do-you-tell-if-a-string-contains-another-string-in-posix-sh
contains() {
string="$1"
substring="$2"
if test "${string#*$substring}" != "$string"
then
return 0
else
return 1
fi
}
startswith() {
string="$1"
prefix="$2"
if test "${string#$prefix}" != "$string"
then
return 0
else
return 1
fi
}
if $use_msys; then
mkdir -p $destination_dir/bin
# Copy sgl to the destination directory.
if [ $debug = true ] ; then
cp "./third_party/sgl/install/bin/libsgld.dll" "$destination_dir/bin"
else
cp "./third_party/sgl/install/bin/libsgl.dll" "$destination_dir/bin"
fi
# Copy the application to the destination directory.
cp "$build_dir/CloudRendering.exe" "$destination_dir/bin"
# Copy all dependencies of the application to the destination directory.
ldd_output="$(ldd $destination_dir/bin/CloudRendering.exe)"
for library in $ldd_output
do
if [[ $library == "$MSYSTEM_PREFIX"* ]] ;
then
cp "$library" "$destination_dir/bin"
fi
if [[ $library == libpython* ]] ;
then
tmp=${library#*lib}
Python3_VERSION=${tmp%.dll}
fi
done
elif [ $use_macos = true ] && [ $use_vcpkg = true ]; then
[ -d $destination_dir ] || mkdir $destination_dir
rsync -a "$build_dir/CloudRendering.app/Contents/MacOS/CloudRendering" $destination_dir
elif [ $use_macos = true ] && [ $use_vcpkg = false ]; then
brew_prefix="$(brew --prefix)"
mkdir -p $destination_dir
if [ -d "$destination_dir/CloudRendering.app" ]; then
rm -rf "$destination_dir/CloudRendering.app"
fi
# Copy the application to the destination directory.
cp -a "$build_dir/CloudRendering.app" "$destination_dir"
# Copy sgl to the destination directory.
if [ $debug = true ] ; then
cp "./third_party/sgl/install/lib/libsgld.dylib" "$binaries_dest_dir"
else
cp "./third_party/sgl/install/lib/libsgl.dylib" "$binaries_dest_dir"
fi
# Copy all dependencies of the application and sgl to the destination directory.
rsync -a "$VULKAN_SDK/lib/libMoltenVK.dylib" "$binaries_dest_dir"
copy_dependencies_recursive() {
local binary_path="$1"
local binary_source_folder=$(dirname "$binary_path")
local binary_name=$(basename "$binary_path")
local binary_target_path="$binaries_dest_dir/$binary_name"
if contains "$(file "$binary_target_path")" "dynamically linked shared library"; then
install_name_tool -id "@executable_path/$binary_name" "$binary_target_path" &> /dev/null
fi
local otool_output="$(otool -L "$binary_path")"
local otool_output=${otool_output#*$'\n'}
while read -r line
do
local stringarray=($line)
local library=${stringarray[0]}
local library_name=$(basename "$library")
local library_target_path="$binaries_dest_dir/$library_name"
if ! startswith "$library" "@rpath/" \
&& ! startswith "$library" "@loader_path/" \
&& ! startswith "$library" "/System/Library/Frameworks/" \
&& ! startswith "$library" "/usr/lib/"
then
install_name_tool -change "$library" "@executable_path/$library_name" "$binary_target_path" &> /dev/null
if [ ! -f "$library_target_path" ]; then
cp "$library" "$binaries_dest_dir"
copy_dependencies_recursive "$library"
fi
elif startswith "$library" "@rpath/"; then
install_name_tool -change "$library" "@executable_path/$library_name" "$binary_target_path" &> /dev/null
local rpath_grep_string="$(otool -l "$binary_target_path" | grep RPATH -A2)"
local counter=0
while read -r grep_rpath_line
do
if [ $(( counter % 4 )) -eq 2 ]; then
local stringarray_grep_rpath_line=($grep_rpath_line)
local rpath=${stringarray_grep_rpath_line[1]}
if startswith "$rpath" "@loader_path"; then
rpath="${rpath/@loader_path/$binary_source_folder}"
fi
local library_rpath="${rpath}${library#"@rpath"}"
if [ -f "$library_rpath" ]; then
if [ ! -f "$library_target_path" ]; then
cp "$library_rpath" "$binaries_dest_dir"
copy_dependencies_recursive "$library_rpath"
fi
break
fi
fi
counter=$((counter + 1))
done < <(echo "$rpath_grep_string")
fi
done < <(echo "$otool_output")
}
copy_dependencies_recursive "$build_dir/CloudRendering.app/Contents/MacOS/CloudRendering"
if [ $debug = true ]; then
copy_dependencies_recursive "./third_party/sgl/install/lib/libsgld.dylib"
else
copy_dependencies_recursive "./third_party/sgl/install/lib/libsgl.dylib"
fi
# Fix code signing for arm64.
for filename in $binaries_dest_dir/*
do
if contains "$(file "$filename")" "arm64"; then
codesign --force -s - "$filename" &> /dev/null
fi
done
${copy_dependencies_macos_post}
else
mkdir -p $destination_dir/bin
# Copy the application to the destination directory.
rsync -a "$build_dir/CloudRendering" "$destination_dir/bin"
# Copy all dependencies of the application to the destination directory.
ldd_output="$(ldd $build_dir/CloudRendering)"
library_blacklist=(
"libOpenGL" "libGLdispatch" "libGL.so" "libGLX.so"
"libwayland" "libffi." "libX" "libxcb" "libxkbcommon"
"ld-linux" "libdl." "libutil." "libm." "libc." "libpthread." "libbsd." "librt."
)
if [ $use_vcpkg = true ]; then
# We build with libstdc++.so and libgcc_s.so statically. If we were to ship them, libraries opened with dlopen will
# use our, potentially older, versions. Then, we will get errors like "version `GLIBCXX_3.4.29' not found" when
# the Vulkan loader attempts to load a Vulkan driver that was built with a never version of libstdc++.so.
# I tried to solve this by using "patchelf --replace-needed" to directly link to the patch version of libstdc++.so,
# but that made no difference whatsoever for dlopen.
library_blacklist+=("libstdc++.so")
library_blacklist+=("libgcc_s.so")
fi
for library in $ldd_output
do
if [[ $library != "/"* ]]; then
continue
fi
is_blacklisted=false
for blacklisted_library in ${library_blacklist[@]+"${library_blacklist[@]}"}; do
if [[ "$library" == *"$blacklisted_library"* ]]; then
is_blacklisted=true
break
fi
done
if [ $is_blacklisted = true ]; then
continue
fi
# TODO: Add blacklist entries for pulseaudio and dependencies when not using vcpkg.
#cp "$library" "$destination_dir/bin"
#patchelf --set-rpath '$ORIGIN' "$destination_dir/bin/$(basename "$library")"
if [ $use_vcpkg = true ]; then
cp "$library" "$destination_dir/bin"
patchelf --set-rpath '$ORIGIN' "$destination_dir/bin/$(basename "$library")"
fi
done
patchelf --set-rpath '$ORIGIN' "$destination_dir/bin/CloudRendering"
fi
# Copy the docs to the destination directory.
cp "README.md" "$destination_dir"
if [ ! -d "$destination_dir/LICENSE" ]; then
mkdir -p "$destination_dir/LICENSE"
cp -r "docs/license-libraries/." "$destination_dir/LICENSE/"
cp -r "LICENSE" "$destination_dir/LICENSE/LICENSE-cloudrendering.txt"
fi
if [ ! -d "$destination_dir/docs" ]; then
cp -r "docs" "$destination_dir"
fi
# Create a run script.
if $use_msys; then
printf "@echo off\npushd %%~dp0\npushd bin\nstart \"\" CloudRendering.exe\n" > "$destination_dir/run.bat"
elif $use_macos; then
printf "#!/bin/sh\npushd \"\$(dirname \"\$0\")\" >/dev/null\n./CloudRendering.app/Contents/MacOS/CloudRendering\npopd\n" > "$destination_dir/run.sh"
chmod +x "$destination_dir/run.sh"
else
printf "#!/bin/bash\npushd \"\$(dirname \"\$0\")/bin\" >/dev/null\n./CloudRendering\npopd\n" > "$destination_dir/run.sh"
chmod +x "$destination_dir/run.sh"
fi
# Run the program as the last step.
echo ""
echo "All done!"
pushd $build_dir >/dev/null
if $use_msys; then
if [[ -z "${PATH+x}" ]]; then
export PATH="${projectpath}/third_party/sgl/install/bin"
elif [[ ! "${PATH}" == *"${projectpath}/third_party/sgl/install/bin"* ]]; then
export PATH="${projectpath}/third_party/sgl/install/bin:$PATH"
fi
elif $use_macos; then
if [ -z "${DYLD_LIBRARY_PATH+x}" ]; then
export DYLD_LIBRARY_PATH="${projectpath}/third_party/sgl/install/lib"
elif contains "${DYLD_LIBRARY_PATH}" "${projectpath}/third_party/sgl/install/lib"; then
export DYLD_LIBRARY_PATH="DYLD_LIBRARY_PATH:${projectpath}/third_party/sgl/install/lib"
fi
else
if [[ -z "${LD_LIBRARY_PATH+x}" ]]; then
export LD_LIBRARY_PATH="${projectpath}/third_party/sgl/install/lib"
elif [[ ! "${LD_LIBRARY_PATH}" == *"${projectpath}/third_party/sgl/install/lib"* ]]; then
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${projectpath}/third_party/sgl/install/lib"
fi
fi
if [ $run_program = true ] && [ $use_macos = false ]; then
./CloudRendering ${params_run[@]+"${params_run[@]}"}
elif [ $run_program = true ] && [ $use_macos = true ]; then
#open ./CloudRendering.app
#open ./CloudRendering.app --args --perf
./CloudRendering.app/Contents/MacOS/CloudRendering ${params_run[@]+"${params_run[@]}"}
fi