Skip to content

Commit a2b0d76

Browse files
authored
Merge pull request #240 from willy-liu/cppcheck_dev
Fix missing compiler macros in cppcheck analysis
2 parents b36c6b1 + f8bbfee commit a2b0d76

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

scripts/pre-commit.hook

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,27 @@ cppcheck_suppressions() {
6868
printf "%s" "$out" | sed 's/[[:space:]]*$//'
6969
}
7070

71+
# Generation of standard compliance for GCC/Clang
72+
detect_cc_std() {
73+
local STDC_VERSION=""
74+
local EXTRA_DEFINES=""
75+
if command -v cc >/dev/null 2>&1; then
76+
if cc --version 2>/dev/null | grep -q "clang"; then
77+
STDC_VERSION=$(cc -dM -E -xc /dev/null | awk '/__STDC_VERSION__/ {print $3}')
78+
EXTRA_DEFINES="-D__clang__=1"
79+
elif cc --version 2>/dev/null | grep -q "Free Software Foundation"; then
80+
STDC_VERSION=$(cc -dM -E -xc /dev/null | awk '/__STDC_VERSION__/ {print $3}')
81+
EXTRA_DEFINES="-D__GNUC__=1"
82+
fi
83+
fi
84+
if [ -n "$STDC_VERSION" ]; then
85+
EXTRA_DEFINES+=" -D__STDC__=1 -D__STDC_VERSION__=${STDC_VERSION}"
86+
fi
87+
echo "$EXTRA_DEFINES"
88+
}
89+
7190
CPPCHECK_OPTS="-I. --enable=all --error-exitcode=1"
91+
CPPCHECK_OPTS+=" $(detect_cc_std)"
7292
CPPCHECK_OPTS+=" --force $(cppcheck_suppressions) $(cppcheck_build_unmatched)"
7393
CPPCHECK_OPTS+=" --cppcheck-build-dir=.out ."
7494

0 commit comments

Comments
 (0)