-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild_cmake.sh
More file actions
executable file
·149 lines (93 loc) · 3.13 KB
/
Copy pathbuild_cmake.sh
File metadata and controls
executable file
·149 lines (93 loc) · 3.13 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
#! /bin/bash
ScriptPath=$0
Dir=$(cd "$(dirname "$ScriptPath")" && pwd)
Basename=$(basename "$ScriptPath")
CMakeDir=${SIS_CMAKE_BUILD_DIR:-$Dir/_build}
if [[ -n "$MSYSTEM" ]]; then
DefaultMakeCmd=mingw32-make.exe
else
DefaultMakeCmd=make
fi
MakeCmd=${SIS_CMAKE_MAKE_COMMAND:-${SIS_CMAKE_COMMAND:-$DefaultMakeCmd}}
ProjectNameFile="$Dir/.sis/project_name.txt"
ProjectName=$(tr -d '[:space:]' < "$ProjectNameFile")
IgnoreRemainingFlagsAndOptions=0
Targets=()
# ##########################################################
# colours
if [ -n "${TERM:-}" ] && [ -t 1 ] && command -v tput >/dev/null 2>&1; then
SisClr_Blue=${FG_BLUE:-$(tput setaf 4)}
SisClr_Red=${FG_RED:-$(tput setaf 1)}
SisClr_Bold=${FD_BOLD:-$(tput bold)}
SisClr_None=${FD_NONE:-$(tput sgr0)}
else
SisClr_Blue=
SisClr_Red=
SisClr_Bold=
SisClr_None=
fi
# ##########################################################
# functions
function join_by { local IFS="$1"; shift; echo "$*"; }
# ##########################################################
# command-line handling
while [[ $# -gt 0 ]]; do
if [ $IgnoreRemainingFlagsAndOptions -ne 0 ]; then
Targets+=($1)
shift
continue
else
if [ ! ${1:0:1} = '-' ]; then
Targets+=($1)
shift
continue
fi
fi
case $1 in
--)
IgnoreRemainingFlagsAndOptions=1
;;
--help)
[ -f "$Dir/.sis/script_info_lines.txt" ] && cat "$Dir/.sis/script_info_lines.txt"
cat << EOF
Executes CMake-generated artefacts to (re)build project
$ScriptPath [ ... flags/options ... ]
Flags/options:
behaviour:
standard flags:
--help
displays this help and terminates
EOF
exit 0
;;
*)
>&2 echo "$ScriptPath: ${SisClr_Red}${SisClr_Bold}unrecognised argument '$1'${SisClr_None}; use --help for usage"
exit 1
;;
esac
shift
done
# ##########################################################
# main()
if [ ! -d "$CMakeDir" ]; then
>&2 echo "$ScriptPath: ${SisClr_Red}${SisClr_Bold}CMake build directory '$CMakeDir' not found${SisClr_None} so nothing to do; use script 'prepare_cmake.sh' if you wish to prepare CMake artefacts"
exit 1
else
cd $CMakeDir
if [ ! -f "$CMakeDir/Makefile" ]; then
>&2 echo "$ScriptPath: ${SisClr_Red}${SisClr_Bold}CMake build directory '$CMakeDir' does not contain expected file 'Makefile'${SisClr_None}, so a clean cannot be performed. It is recommended that you remove all CMake artefacts using script 'remove_cmake_artefacts.sh' followed by regeneration via 'prepare_cmake.sh'"
cd ->/dev/null
exit 1
else
if [ -z "$Targets" ]; then
echo "Executing build of ${SisClr_Blue}${SisClr_Bold}${ProjectName}${SisClr_None} (via command \`${SisClr_Blue}${SisClr_Bold}$MakeCmd${SisClr_None}\`)"
else
echo "Executing build of ${SisClr_Blue}${SisClr_Bold}${ProjectName}${SisClr_None} (via command \`${SisClr_Blue}${SisClr_Bold}$MakeCmd${SisClr_None}\`) with specific target(s) $(join_by , "${Targets[@]}")"
fi
$MakeCmd ${Targets[*]}
status=$?
cd ->/dev/null
exit $status
fi
fi
# ############################## end of file ############################# #