-
Notifications
You must be signed in to change notification settings - Fork 27
/
cmake_dev.sh
executable file
·217 lines (199 loc) · 8.93 KB
/
cmake_dev.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
#!/bin/bash
#!/usr/bin/env bash
SYS_NAME="$(uname -s)";
SYS_NAME="$(basename $SYS_NAME)";
CC=gcc;
CXX=g++;
CCACHE="$(which ccache)";
DISTCC="";
if [ ! -z "$DISTCC_HOSTS" ]; then
DISTCC="$(which distcc 2>/dev/null)";
fi
NINJA_BIN="$(which ninja 2>&1)";
if [ $? -ne 0 ]; then
NINJA_BIN="$(which ninja-build 2>&1)";
if [ $? -ne 0 ]; then
NINJA_BIN="";
fi
fi
CMAKE_OPTIONS="";
CMAKE_CLANG_TIDY="";
CMAKE_CLANG_ANALYZER=0;
CMAKE_CLANG_ANALYZER_PATH="";
BUILD_DIR=$(echo "build_jobs_$SYS_NAME" | tr '[:upper:]' '[:lower:]');
CMAKE_BUILD_TYPE=Debug;
PROJECT_NAME=atsf4g-co;
which git > /dev/null 2>&1;
if [[ $? -eq 0 ]]; then
PROJECT_GIT_URL=$(git config remote.origin.url 2>/dev/null);
if [[ "x$PROJECT_GIT_URL" != "x" ]]; then
PROJECT_NAME="${PROJECT_GIT_URL##*/}";
PROJECT_NAME="${PROJECT_NAME//\.git/}";
fi
fi
if [[ ! -z "$MSYSTEM" ]]; then
CHECK_MSYS=$(echo "${MSYSTEM:0:5}" | tr '[:upper:]' '[:lower:]');
else
CHECK_MSYS="";
fi
while getopts "ab:c:d:e:hltus-" OPTION; do
case $OPTION in
a)
echo "Ready to check ccc-analyzer and c++-analyzer, please do not use -c to change the compiler when using clang-analyzer.";
export CCC_CC="$CC" ;
export CCC_CXX="$CXX" ;
CC=$(which ccc-analyzer);
CXX=$(which c++-analyzer);
if [[ 0 -ne $? ]]; then
# check mingw path
if [[ "mingw" == "$CHECK_MSYS" ]]; then
if [[ ! -z "$MINGW_MOUNT_POINT" ]] && [[ -e "$MINGW_MOUNT_POINT/libexec/ccc-analyzer.bat" ]] && [[ -e "$MINGW_MOUNT_POINT/libexec/ccc-analyzer.bat" ]]; then
echo "clang-analyzer found in $MINGW_MOUNT_POINT";
export PATH=$PATH:$MINGW_MOUNT_POINT/libexec ;
CC="$MINGW_MOUNT_POINT/libexec/ccc-analyzer.bat";
CXX="$MINGW_MOUNT_POINT/libexec/ccc-analyzer.bat";
CMAKE_CLANG_ANALYZER_PATH="$MINGW_MOUNT_POINT/libexec";
elif [[ ! -z "$MINGW_PREFIX" ]] && [[ -e "$MINGW_PREFIX/libexec/ccc-analyzer.bat" ]] && [[ -e "$MINGW_PREFIX/libexec/c++-analyzer.bat" ]]; then
echo "clang-analyzer found in $MINGW_PREFIX";
export PATH=$PATH:$MINGW_PREFIX/libexec ;
CC="$MINGW_PREFIX/libexec/ccc-analyzer.bat";
CXX="$MINGW_PREFIX/libexec/ccc-analyzer.bat";
CMAKE_CLANG_ANALYZER_PATH="$MINGW_PREFIX/libexec";
fi
else
TEST_CLANG_BIN="$(which clang 2>/dev/null)";
if [[ ! -z "$TEST_CLANG_BIN" ]]; then
TEST_CLANG_BIN="$(readlink -f "$TEST_CLANG_BIN")";
TEST_CLANG_BIN_DIR="$(dirname "$TEST_CLANG_BIN")";
if [[ -e "$TEST_CLANG_BIN_DIR/../libexec/ccc-analyzer" ]]; then
CC=$(readlink -f "$TEST_CLANG_BIN_DIR/../libexec/ccc-analyzer");
fi
if [[ -e "$TEST_CLANG_BIN_DIR/../libexec/c++-analyzer" ]]; then
CXX=$(readlink -f "$TEST_CLANG_BIN_DIR/../libexec/c++-analyzer");
fi
fi
fi
fi
if [[ -z "$CC" ]] || [[ -z "$CXX" ]]; then
echo "ccc-analyzer=$CC";
echo "c++-analyzer=$CXX";
echo "clang-analyzer not found, failed.";
exit 1;
fi
echo "ccc-analyzer=$CC";
echo "c++-analyzer=$CXX";
echo "clang-analyzer setup completed.";
CMAKE_CLANG_ANALYZER=1;
BUILD_DIR="${BUILD_DIR}_analyzer";
;;
b)
CMAKE_BUILD_TYPE="$OPTARG";
;;
c)
if [[ $CMAKE_CLANG_ANALYZER -ne 0 ]]; then
CCC_CC="$OPTARG";
CCC_CXX="${CCC_CC/%clang/clang++}";
CCC_CXX="${CCC_CXX/%gcc/g++}";
export CCC_CC;
export CCC_CXX;
else
CC="$OPTARG";
CXX="$(echo "$CC" | sed 's/\(.*\)clang/\1clang++/')";
CXX="$(echo "$CXX" | sed 's/\(.*\)gcc/\1g++/')";
fi
;;
d)
DISTCC="$OPTARG";
;;
e)
CCACHE="$OPTARG";
;;
h)
echo "usage: $0 [options] [-- [cmake options...] ]";
echo "options:";
echo "-a using clang-analyzer.";
echo "-c <compiler> compiler toolchains(gcc, clang or others).";
echo "-d <distcc path> try to use specify distcc to speed up building.";
echo "-e <ccache path> try to use specify ccache to speed up building.";
echo "-h help message.";
echo "-t enable clang-tidy.";
echo "-u enable unit test.";
echo "-s enable sample.";
echo "-l enable tools.";
exit 0;
;;
t)
CMAKE_CLANG_TIDY="-D -checks=* --";
;;
u)
CMAKE_OPTIONS="$CMAKE_OPTIONS -DPROJECT_ENABLE_UNITTEST=YES";
;;
s)
CMAKE_OPTIONS="$CMAKE_OPTIONS -DPROJECT_ENABLE_SAMPLE=YES";
;;
l)
CMAKE_OPTIONS="$CMAKE_OPTIONS -DPROJECT_ENABLE_TOOLS=YES";
;;
-)
break;
;;
?)
echo "unkonw argument detected";
exit 1;
;;
esac
done
shift $(($OPTIND - 1));
SCRIPT_DIR="$(cd $(dirname $0) && pwd)";
mkdir -p "$SCRIPT_DIR/$BUILD_DIR";
cd "$SCRIPT_DIR/$BUILD_DIR";
if [[ ! -z "$DISTCC" ]] && [[ "$DISTCC" != "disable" ]] && [[ "$DISTCC" != "disabled" ]] && [[ "$DISTCC" != "no" ]] && [[ "$DISTCC" != "false" ]] && [[ -e "$DISTCC" ]]; then
CMAKE_OPTIONS="$CMAKE_OPTIONS -DCMAKE_C_COMPILER_LAUNCHER=$DISTCC -DCMAKE_CXX_COMPILER_LAUNCHER=$DISTCC -DCMAKE_C_COMPILER=$CC -DCMAKE_CXX_COMPILER=$CXX";
elif [[ ! -z "$CCACHE" ]] && [[ "$CCACHE" != "disable" ]] && [[ "$CCACHE" != "disabled" ]] && [[ "$CCACHE" != "no" ]] && [[ "$CCACHE" != "false" ]] && [[ -e "$CCACHE" ]]; then
#CMAKE_OPTIONS="$CMAKE_OPTIONS -DCMAKE_C_COMPILER=$CCACHE -DCMAKE_CXX_COMPILER=$CCACHE -DCMAKE_C_COMPILER_ARG1=$CC -DCMAKE_CXX_COMPILER_ARG1=$CXX";
CMAKE_OPTIONS="$CMAKE_OPTIONS -DCMAKE_C_COMPILER_LAUNCHER=$CCACHE -DCMAKE_CXX_COMPILER_LAUNCHER=$CCACHE -DCMAKE_C_COMPILER=$CC -DCMAKE_CXX_COMPILER=$CXX";
else
CMAKE_OPTIONS="$CMAKE_OPTIONS -DCMAKE_C_COMPILER=$CC -DCMAKE_CXX_COMPILER=$CXX";
fi
CMAKE_BIN=(cmake);
if [[ $CMAKE_CLANG_ANALYZER -ne 0 ]]; then
CMAKE_BIN=(scan-build cmake);
fi
if [[ "x$NINJA_BIN" != "x" ]]; then
${CMAKE_BIN[@]} .. -G Ninja -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE $CMAKE_OPTIONS "$@";
elif [[ "$CHECK_MSYS" == "mingw" ]]; then
${CMAKE_BIN[@]} .. -G "MSYS Makefiles" -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE $CMAKE_OPTIONS "$@";
else
${CMAKE_BIN[@]} .. -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE $CMAKE_OPTIONS "$@";
fi
if [[ 1 -eq $CMAKE_CLANG_ANALYZER ]]; then
echo "=========================================================================================================";
CMAKE_CLANG_ANALYZER_OPTIONS="--exclude ../third_party --exclude ../src/server_frame/protocol";
if [[ -e "$SCRIPT_DIR/.scan-build.enable" ]]; then
for OPT in $(cat "$SCRIPT_DIR/.scan-build.enable"); do
CMAKE_CLANG_ANALYZER_OPTIONS="$CMAKE_CLANG_ANALYZER_OPTIONS -enable-checker $OPT";
done
fi
if [[ -e "$SCRIPT_DIR/.scan-build.disable" ]]; then
for OPT in $(cat "$SCRIPT_DIR/.scan-build.disable"); do
CMAKE_CLANG_ANALYZER_OPTIONS="$CMAKE_CLANG_ANALYZER_OPTIONS -disable-checker $OPT";
done
fi
for BUILD_JOBS_DIRS in ../build_* ; do
CMAKE_CLANG_ANALYZER_OPTIONS="$CMAKE_CLANG_ANALYZER_OPTIONS --exclude $BUILD_JOBS_DIRS";
done
for TEST_DIRS in $(find ../atframework -name test) ; do
CMAKE_CLANG_ANALYZER_OPTIONS="$CMAKE_CLANG_ANALYZER_OPTIONS --exclude $BUILD_JOBS_DIRS";
done
echo "#!/bin/bash
cd '$SCRIPT_DIR/$BUILD_DIR';
" > run-scan-build.sh;
if [[ -z "$CMAKE_CLANG_ANALYZER_PATH" ]]; then
echo "env CCC_CC=\"$CCC_CC\" CCC_CXX=\"$CCC_CXX\" scan-build -o report --html-title='$PROJECT_NAME static analysis' $CMAKE_CLANG_ANALYZER_OPTIONS cmake --build . -j $@" >> run-scan-build.sh;
else
echo "env PATH=\"\$PATH:$CMAKE_CLANG_ANALYZER_PATH\" CCC_CC=\"$CCC_CC\" CCC_CXX=\"$CCC_CXX\" scan-build -o report --html-title='libmt_core static analysis' $CMAKE_CLANG_ANALYZER_OPTIONS cmake --build . -j $@" >> run-scan-build.sh;
fi
chmod +x run-scan-build.sh;
echo "Now, you can run $PWD/run-scan-build.sh to build a static analysis report";
echo "You can get help and binary of clang-analyzer and scan-build at http://clang-analyzer.llvm.org/scan-build.html" ;
fi