Repository navigation
Expand file tree
/
Copy pathclean_cmake.sh
More file actions
executable file
·181 lines (123 loc) · 3.82 KB
/
Copy pathclean_cmake.sh
File metadata and controls
executable file
·181 lines (123 loc) · 3.82 KB
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
#! /bin/bash
# ##########################################################
# functions - 1
sis_cmake_is_truey() {
case "$(printf '%s' "${1:-}" | tr '[:upper:]' '[:lower:]')" in
1|ok|on|true|yes|y)
return 0
;;
*)
return 1
;;
esac
}
# ##########################################################
# constants and variables
Basename=$(basename "$0")
Dir=$(cd "$(dirname "$0")" && pwd)
CMakeDir=${SIS_CMAKE_BUILD_DIR:-$Dir/_build}
ProjectNameFile="$Dir/.sis/project_name.txt"
ProjectName=$(tr -d '[:space:]' < "$ProjectNameFile")
ScriptPath=$0
AlwaysUseColours=${SIS_CMAKE_ALWAYS_USE_COLOURS:-${SIS_ALWAYS_USE_COLOURS:-0}}
SisUseColours=0
# ##########################################################
# colours
#
# Enable when tput is available and either:
# - AlwaysUseColours is set (overrides NO_COLOR; may set TERM if
# empty/dumb), or
# - NO_COLOR is unset, stdout is a TTY, and TERM is not dumb (union of
# collect-c's "TERM set + TTY" and cstring's "TTY" — empty TERM on a
# TTY is OK).
SisClr_Blue=
SisClr_Bold=
SisClr_Green=
SisClr_None=
SisClr_Red=
SisClr_Yellow=
for arg in "$@"; do
case $arg in
--always-use-colors|--always-use-colours|-A)
AlwaysUseColours=1
;;
esac
done
if command -v tput >/dev/null 2>&1; then
if [ $AlwaysUseColours -ne 0 ]; then
if [ -z "${TERM:-}" ] || [ "$TERM" = "dumb" ]; then
TERM=xterm-256color
fi
SisUseColours=1
elif [ -z "${NO_COLOR:-}" ] && [ -t 1 ] && [ "${TERM:-}" != "dumb" ]; then
SisUseColours=1
fi
fi
if [ $SisUseColours -ne 0 ]; then
SisClr_Blue=${FG_BLUE:-$(tput setaf 4)}
SisClr_Bold=${FD_BOLD:-$(tput bold)}
SisClr_Green=${FG_GREEN:-$(tput setaf 2)}
SisClr_None=${FD_NONE:-$(tput sgr0)}
SisClr_Red=${FG_RED:-$(tput setaf 1)}
SisClr_Yellow=${FG_YELLOW:-$(tput setaf 3)}
fi
CMakeDirClr="${SisClr_Blue}${SisClr_Bold}${CMakeDir}${SisClr_None}"
ProjectNameClr="${SisClr_Blue}${SisClr_Bold}${ProjectName}${SisClr_None}"
ScriptPathClr="${SisClr_Blue}${SisClr_Bold}${ScriptPath}${SisClr_None}"
# ##########################################################
# functions - 2
sis_cmake_build() {
local config="${SIS_CMAKE_CONFIG:-Release}"
local args=(--build "$CMakeDir")
if [ -f "$CMakeDir/CMakeCache.txt" ] && grep -q '^CMAKE_CONFIGURATION_TYPES:' "$CMakeDir/CMakeCache.txt" 2>/dev/null; then
args+=(--config "$config")
fi
if [ "$#" -gt 0 ]; then
local t
for t in "$@"; do
args+=(--target "$t")
done
fi
cmake "${args[@]}"
}
# ##########################################################
# command-line handling
while [[ $# -gt 0 ]]; do
case $1 in
--always-use-colors|--always-use-colours|-A)
# AlwaysUseColours=1 - this is handled by the for loop above
;;
--help)
[ -f "$Dir/.sis/script_info_lines.txt" ] && cat "$Dir/.sis/script_info_lines.txt"
cat << EOF
Cleans CMake-generated build artefacts via cmake --build --target clean
${ScriptPath} [ ... flags/options ... ]
Flags/options:
behaviour:
-A
--always-use-colors
--always-use-colours
forces use of colours even when stdout is not a TTY
standard flags:
--help
displays this help and terminates
EOF
exit 0
;;
*)
>&2 echo "${ScriptPathClr}: unrecognised argument '${SisClr_Red}${SisClr_Bold}$1${SisClr_None}'; use --help for usage"
exit 1
;;
esac
shift
done
# ##########################################################
# main()
if [ ! -d "$CMakeDir" ] || [ ! -f "$CMakeDir/CMakeCache.txt" ]; then
>&2 echo "${ScriptPathClr}: CMake build directory '${CMakeDirClr}' not found or not configured; nothing to clean"
exit 1
fi
echo "Executing clean of ${ProjectNameClr} (via cmake --build --target clean)"
sis_cmake_build clean
exit $?
# ############################## end of file ############################# #