Skip to content

Commit a548f5f

Browse files
committed
build.sh: On Linux force use of latest Clang
CMake will default to GCC if it's available. Force use of the latest Clang instead. This can be overridden with CC, CXX, and CXXFLAGS Fixed: google#8515
1 parent 2f4e48b commit a548f5f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

build.sh

+12
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,17 @@ BUILD_CUSTOM_TARGETS=
224224
UNAME=$(uname)
225225
LC_UNAME=$(echo "${UNAME}" | tr '[:upper:]' '[:lower:]')
226226

227+
if [[ "$LC_UNAME" == "linux" ]]; then
228+
# On Linux both GCC and Clang are commonly available, but CMake
229+
# will default to GCC.
230+
# Force use of Clang, and pick the highest-numbered version.
231+
CLANG_VER=$(ls -1 /usr/include/clang | fgrep -v . | sort -n | tail -1)
232+
export CC=${CC-/usr/bin/clang-$CLANG_VER}
233+
export CXX=${CXX-/usr/bin/clang++-$CLANG_VER}
234+
export CXXFLAGS=${CXXFLAGS--stdlib=libc++}
235+
export COMPILER_OPTION="-DCMAKE_C_COMPILER=$CC -DCMAKE_CXX_COMPILER=$CXX -DCMAKE_CXX_FLAGS=$CXXFLAGS"
236+
fi
237+
227238
# Functions
228239

229240
function build_clean {
@@ -268,6 +279,7 @@ function build_desktop_target {
268279
-DIMPORT_EXECUTABLES_DIR=out \
269280
-DCMAKE_BUILD_TYPE="$1" \
270281
-DCMAKE_INSTALL_PREFIX="../${lc_target}/filament" \
282+
${COMPILER_OPTION} \
271283
${EGL_ON_LINUX_OPTION} \
272284
${FGVIEWER_OPTION} \
273285
${WEBGPU_OPTION} \

0 commit comments

Comments
 (0)