-
Notifications
You must be signed in to change notification settings - Fork 138
/
BuildWasm.sh
executable file
·179 lines (162 loc) · 5.49 KB
/
BuildWasm.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
#!/bin/bash
SOURCE_DIR=$PWD
OUTPUT_DIR="build_wasm"
CLEAR_CACHE=0
ENABLE_EXAMPLES="ON"
ENABLE_TESTS="ON"
ENABLE_PTHREADS="OFF"
BUILD_TYPE="Release"
PROJECT_ONLY=0
VERBOSE=0
GENERATOR="CodeBlocks - Unix Makefiles"
# Check whether we are on a Linux distribution or MSYS on Windows
print_help()
{
echo "USAGE:"
echo " BuildWasm.sh OPTIONS* [OUTPUT_DIR]"
echo "OPTIONS:"
echo " -c, --clear-cache ......... Clear CMake cache and rebuild"
echo " -h, --help ................ Print this help documentation and exit"
echo " -d, --debug ............... Configure Debug build (default is Release)"
echo " -p, --project-only [=G] ... Build project with CMake generator (default is CodeBlocks)"
echo " -v, --verbose ............. Print additional information"
echo " --no-examples ............. Exclude example projects"
echo " --no-tests ................ Exclude test projects"
echo " --pthreads ................ Enable pthreads (limits browser availability)"
echo "NOTES:"
echo " Default output directory is '$OUTPUT_DIR'"
}
# Parse arguments
for ARG in "$@"; do
if [ "$ARG" = "-h" ] || [ "$ARG" = "--help" ]; then
print_help
exit 0
elif [ "$ARG" = "-c" ] || [ "$ARG" = "--clear-cache" ]; then
CLEAR_CACHE=1
elif [ "$ARG" = "-d" ] || [ "$ARG" = "--debug" ]; then
BUILD_TYPE="Debug"
elif [ "$ARG" = "-p" ] || [ "$ARG" = "--project-only" ]; then
PROJECT_ONLY=1
elif [[ "$ARG" == -p=* ]]; then
PROJECT_ONLY=1
GENERATOR="${ARG:3}"
elif [[ "$ARG" == --project-only=* ]]; then
PROJECT_ONLY=1
GENERATOR="${ARG:15}"
elif [ "$ARG" = "-v" ] || [ "$ARG" = "--verbose" ]; then
VERBOSE=1
elif [ "$ARG" = "--null" ]; then
ENABLE_NULL="ON"
elif [ "$ARG" = "--vulkan" ]; then
ENABLE_VULKAN="ON"
elif [ "$ARG" = "--no-examples" ]; then
ENABLE_EXAMPLES="OFF"
elif [ "$ARG" = "--no-tests" ]; then
ENABLE_TESTS="OFF"
elif [ "$ARG" = "--pthreads" ]; then
ENABLE_PTHREADS="ON"
else
OUTPUT_DIR="$ARG"
fi
done
# Ensure we are inside the repository folder
if [ ! -f "CMakeLists.txt" ]; then
echo "Error: File not found: CMakeLists.txt"
exit 1
fi
# Make output build folder
if [ $CLEAR_CACHE = 1 ] && [ -d "$OUTPUT_DIR" ]; then
rm -rf "$OUTPUT_DIR"
fi
if [ ! -d "$OUTPUT_DIR" ]; then
mkdir "$OUTPUT_DIR"
fi
# Wrapper for 'realpath' when it's not available (like on macOS)
get_realpath()
{
if command -v realpath &> /dev/null; then
echo $(realpath "$1")
else
echo "$1"
fi
}
# Checkout external depenencies
GAUSSIAN_LIB_DIR="GaussianLib/include"
if [ -f "$SOURCE_DIR/external/$GAUSSIAN_LIB_DIR/Gauss/Gauss.h" ]; then
GAUSSIAN_LIB_DIR=$(get_realpath "$SOURCE_DIR/external/$GAUSSIAN_LIB_DIR")
else
if [ ! -d "$OUTPUT_DIR/$GAUSSIAN_LIB_DIR" ]; then
(cd "$OUTPUT_DIR" && git clone https://github.com/LukasBanana/GaussianLib.git)
fi
GAUSSIAN_LIB_DIR=$(get_realpath "$OUTPUT_DIR/$GAUSSIAN_LIB_DIR")
fi
# Print additional information if in verbose mode
if [ $VERBOSE -ne 0 ]; then
echo "GAUSSIAN_LIB_DIR=$GAUSSIAN_LIB_DIR"
if [ $PROJECT_ONLY -eq 0 ]; then
echo "BUILD_TYPE=$BUILD_TYPE"
else
echo "GENERATOR=$GENERATOR"
fi
fi
# Find Emscripten SDK
if [ -z "$EMSDK" ]; then
echo "Error: Missing EMSDK environment variable. Run 'source <PATH-TO-EMSDK>/emsdk_env.sh' to fix it."
exit 1
fi
EMSCRIPTEN_CMAKE_TOOLCHAIN="$EMSDK/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake"
if [ ! -f "$EMSCRIPTEN_CMAKE_TOOLCHAIN" ]; then
echo "Error: Could not find file $EMSCRIPTEN_CMAKE_TOOLCHAIN"
exit 1
fi
# Build into output directory (this syntax requried CMake 3.13+)
OPTIONS=(
-DCMAKE_TOOLCHAIN_FILE="$EMSCRIPTEN_CMAKE_TOOLCHAIN"
-DLLGL_BUILD_RENDERER_WEBGL=ON
-DLLGL_GL_ENABLE_OPENGL2X=OFF
-DLLGL_BUILD_RENDERER_NULL=OFF
-DLLGL_BUILD_RENDERER_VULKAN=OFF
-DLLGL_BUILD_RENDERER_DIRECT3D11=OFF
-DLLGL_BUILD_RENDERER_DIRECT3D12=OFF
-DLLGL_BUILD_EXAMPLES=$ENABLE_EXAMPLES
-DLLGL_BUILD_TESTS=$ENABLE_TESTS
-DLLGL_BUILD_STATIC_LIB=ON
-DLLGL_ENABLE_EMSCRIPTEN_PTHREADS=$ENABLE_PTHREADS
-DGaussLib_INCLUDE_DIR:STRING="$GAUSSIAN_LIB_DIR"
-S "$SOURCE_DIR"
-B "$OUTPUT_DIR"
)
if [ $PROJECT_ONLY -eq 0 ]; then
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE ${OPTIONS[@]}
cmake --build "$OUTPUT_DIR" -- -j 20
else
cmake ${OPTIONS[@]} -G "$GENERATOR"
fi
# Copys the input file to the output and removes '\r' EOL characters from text files.
# Web page will run on Linux server and Git must not convert EOL for this output file.
# Otherwise, data offsets in the *.data.js script won't match with the *.data file after Git uploaded it.
copy_file_preserve_linux_eol()
{
INPUT=$1
OUTPUT=$2
FILE_EXT=${INPUT##*.}
if [[ "${FILE_EXT,,}" =~ ^(txt|vert|frag|obj)$ ]]; then
if [ $VERBOSE -ne 0 ]; then
echo "Copy asset (convert EOL): $(basename $INPUT)"
fi
tr -d "\r" < "$INPUT" > "$OUTPUT"
else
if [ $VERBOSE -ne 0 ]; then
echo "Copy asset: $(basename $INPUT)"
fi
cp "$INPUT" "$OUTPUT"
fi
}
# Generate HTML pages
if [ $PROJECT_ONLY -eq 0 ] && [ $ENABLE_EXAMPLES == "ON" ]; then
scripts/GenerateHTML5Examples.sh \
"${SOURCE_DIR}" \
"${OUTPUT_DIR}" \
$([ $BUILD_TYPE = "Debug" ] && echo "--debug") \
$([ $VERBOSE -ne 0 ] && echo "--verbose")
fi