-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprepare_cmake.sh
More file actions
executable file
·227 lines (164 loc) · 4.99 KB
/
Copy pathprepare_cmake.sh
File metadata and controls
executable file
·227 lines (164 loc) · 4.99 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
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
218
219
220
221
222
223
224
225
226
227
#! /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")
Configuration=Release
CxxStandard=
MSVC_MT=0
MinGW="${MinGW:=0}"
RunMake=0
STLSoftDirGiven=
TestingDisabled=0
VerboseMakefile=0
# ##########################################################
# 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
# ##########################################################
# command-line handling
while [[ $# -gt 0 ]]; do
case $1 in
--cxx-standard)
shift
CxxStandard=$1
case $CxxStandard in
98|11|14|17|20|23)
;;
*)
>&2 echo "$ScriptPath: ${SisClr_Red}${SisClr_Bold}invalid C++ standard '$CxxStandard'${SisClr_None}; expected 98, 11, 14, 17, 20, or 23"
exit 1
;;
esac
;;
--cmake-verbose-makefile|-v)
VerboseMakefile=1
;;
--debug-configuration|-d)
Configuration=Debug
;;
--disable-testing|-T)
TestingDisabled=1
;;
--mingw)
MinGW=1
;;
--msvc-mt)
MSVC_MT=1
;;
--run-make|-m)
RunMake=1
;;
--stlsoft-root-dir|-s)
shift
STLSoftDirGiven=$1
;;
--help)
[ -f "$Dir/.sis/script_info_lines.txt" ] && cat "$Dir/.sis/script_info_lines.txt"
cat << EOF
Creates/reinitialises the CMake build script(s)
$ScriptPath [ ... flags/options ... ]
Flags/options:
behaviour:
--c-standard {99|11|17|23}
sets CMAKE_C_STANDARD (default is 11)
-v
--cmake-verbose-makefile
configures CMake to run verbosely (by setting CMAKE_VERBOSE_MAKEFILE
to be ON)
-d
--debug-configuration
use Debug configuration (by setting CMAKE_BUILD_TYPE=Debug). Default
is to use Release
-T
--disable-testing
disables building of tests (by setting BUILD_TESTING=OFF)
--mingw
uses explicitly the "MinGW Makefiles" generator, and defaults the
make-command to "mingw32-make.exe"
--msvc-mt
when using Visual C++ (MSVC), the static runtime library will be
selected; the default is the dynamic runtime library
-m
--run-make
executes make after a successful running of CMake
-s <dir>
--stlsoft-root-dir <dir>
specifies the STLSoft root-directory, which will be passed to CMake
as the variable STLSOFT, and which will override the environment
variable STLSOFT (if present)
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()
mkdir -p $CMakeDir || exit 1
cd $CMakeDir
echo "Executing CMake for ${SisClr_Blue}${SisClr_Bold}${ProjectName}${SisClr_None} (in ${SisClr_Blue}${SisClr_Bold}${CMakeDir}${SisClr_None})"
if [ -z "$CxxStandard" ]; then CMakeCStandardVariable="" ; else CMakeCStandardVariable="-DCMAKE_C_STANDARD=$CxxStandard" ; fi
if [ $MSVC_MT -eq 0 ]; then CMakeMsvcMtFlag="OFF" ; else CMakeMsvcMtFlag="ON" ; fi
if [ -z "$STLSoftDirGiven" ]; then CMakeSTLSoftVariable="" ; else CMakeSTLSoftVariable="-DSTLSOFT=$STLSoftDirGiven/" ; fi
if [ $TestingDisabled -eq 0 ]; then CMakeBuildTestingFlag="ON" ; else CMakeBuildTestingFlag="OFF" ; fi
if [ $VerboseMakefile -eq 0 ]; then CMakeVerboseMakefileFlag="OFF" ; else CMakeVerboseMakefileFlag="ON" ; fi
if [ $MinGW -ne 0 ]; then
cmake \
$CMakeCStandardVariable \
$CMakeSTLSoftVariable \
-DBUILD_TESTING:BOOL=$CMakeBuildTestingFlag \
-DCMAKE_BUILD_TYPE=$Configuration \
-G "MinGW Makefiles" \
-S $Dir \
-B $CMakeDir \
|| (cd ->/dev/null ; exit 1)
else
cmake \
$CMakeCStandardVariable \
$CMakeSTLSoftVariable \
-DBUILD_TESTING:BOOL=$CMakeBuildTestingFlag \
-DCMAKE_BUILD_TYPE=$Configuration \
-DCMAKE_VERBOSE_MAKEFILE:BOOL=$CMakeVerboseMakefileFlag \
-DMSVC_USE_MT:BOOL=$CMakeMsvcMtFlag \
-S $Dir \
-B $CMakeDir \
|| (cd ->/dev/null ; exit 1)
fi
status=0
if [ $RunMake -ne 0 ]; then
echo "Executing build (via command \`${SisClr_Blue}${SisClr_Bold}$MakeCmd${SisClr_None}\`)"
$MakeCmd
status=$?
fi
cd ->/dev/null
if [ $VerboseMakefile -ne 0 ]; then
echo -e "contents of $CMakeDir:"
ls -al $CMakeDir
fi
exit $status
# ############################## end of file ############################# #