forked from attugit/cxxjson
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig
76 lines (69 loc) · 1.83 KB
/
config
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
#!/bin/bash
SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
PROJECT_DIR=$(readlink -f ${SCRIPT_DIR})
set_base_flags() {
CXXFLAGS="${CXXFLAGS} -Wall -Wconversion -Werror -Wextra -Wshadow -Wunused -pedantic -pedantic-errors -fno-rtti -fPIC -std=c++17 -Wno-gnu-string-literal-operator-template"
LINKFLAGS="${LINKFLAGS}"
DEFINES="${DEFINES}"
}
publish_unique_flags() {
CXXFLAGS=$(echo ${CXXFLAGS} | tr ' ' '\n' | sort | uniq | tr '\n' ' ')
LINKFLAGS=$(echo ${LINKFLAGS} | tr ' ' '\n' | sort | uniq | tr '\n' ' ')
DEFINES=$(echo ${DEFINES} | tr ' ' '\n' | sort | uniq | tr '\n' ' ')
export CXXFLAGS
export LINKFLAGS
export DEFINES
}
set_flags() {
case "$1" in
'debug')
CXXFLAGS="${CXXFLAGS} -g -O0"
DEFINES="${DEFINES} DEBUG"
;;
'release')
CXXFLAGS="${CXXFLAGS} -O3 -march=native"
DEFINES="${DEFINES} NDEBUG"
LINKFLAGS="${LINKFLAGS} -flto"
;;
'sanitize')
CXXFLAGS="${CXXFLAGS} -fsanitize=address -fsanitize=undefined"
LINKFLAGS="${LINKFLAGS} -fsanitize=address -fsanitize=undefined"
export ASAN_OPTIONS=symbolize=1:abort_on_error=1
export UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1:suppressions=${PROJECT_DIR}/test/ub.supp
;;
'coverage')
CXXFLAGS="${CXXFLAGS} -fprofile-arcs -ftest-coverage"
LINKFLAGS="${LINKFLAGS} -fprofile-arcs -ftest-coverage"
;;
'libc++')
CXXFLAGS="${CXXFLAGS} -stdlib=libc++"
LINKFLAGS="${LINKFLAGS} -stdlib=libc++"
;;
'g++')
export CXX="g++"
;;
'clang++')
export CXX="clang++"
;;
*)
echo 'wrong switch ' ${1}
esac
}
clear_flags() {
unset CXXFLAGS
unset LINKFLAGS
unset DEFINES
}
if [ "$#" == "0" ]; then
exit 1
fi
while (( "$#" )); do
if [ "$1" == "clear" ]; then
clear_flags
else
set_flags $1
fi
shift
done
set_base_flags
publish_unique_flags