forked from SixTrack/SixTrack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmake_six
executable file
·303 lines (263 loc) · 8.62 KB
/
cmake_six
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#! /usr/bin/env bash
# make_six-like wrapper for cmake and make
# To run it, say (for example) "./cmake_six 64BIT -32BIT nagfor"
# To see all available options, run ./cmake_six help
set -e #Stop on error
#For debugging
#set -v
#set -x
echo "Welcome to cmake_six, a wrapper for cmake and make."
echo "For help, run 'cmake_six help'"
echo ""
#Get options
compilers=(defaultcompiler gfortran gcc g++ gcc-g++ gfortran-gcc-g++ ifort ifort-icc ifort-icc-icpc nagfor clang clang++ clang-clang++) # Valid compilers. defaultcompiler = system default compilers
compilers_CMAKE=('' '-DCMAKE_Fortran_COMPILER=gfortran' '-DCMAKE_C_COMPILER=gcc' '-DCMAKE_CXX_COMPILER=g++' '-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++' '-DCMAKE_Fortran_COMPILER=gfortran -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++' '-DCMAKE_Fortran_COMPILER=ifort' '-DCMAKE_Fortran_COMPILER=ifort -DCMAKE_C_COMPILER=icc' '-DCMAKE_Fortran_COMPILER=ifort -DCMAKE_C_COMPILER=icc -DCMAKE_CXX_COMPILER=icpc' '-DCMAKE_Fortran_COMPILER=nagfor' '-DCMAKE_C_COMPILER=clang' '-DCMAKE_CXX_COMPILER=clang++' '-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++')
options_COMPILER=defaultcompiler #which compilers to use
buildtypes=(defaultbuildtype release debug)
buildtypes_CMAKE=('' '-DCMAKE_BUILD_TYPE=Release' '-DCMAKE_BUILD_TYPE=Debug')
options_BUILDTYPE=defaultbuildtype #Which build type to make (should be in 'buildtypes')
## Make build folder if it doesn't exist
mkdir -p build
cd build
## Look for special options 'clean' and 'help'
for var in "$@" #Loop over command line arguments
do
if [[ $var == clean ]]; then
echo "Cleaning cmake_six builds!"
set +e
#ls SixTrack_cmakesix*
rm -rf SixTrack_cmakesix*
exit
elif [[ $var == help ]]; then
echo "VALID OPTIONS FOR cmake_six:"
echo
echo "Compilers:"
for c in ${compilers[@]}
do
echo $c
done
echo
echo "Build types:"
for c in ${buildtypes[@]}
do
echo $c
done
echo ""
echo "Flags and default options:"
mkdir cmake_tmp
cd cmake_tmp
#Skip "-A" flag
cmake -LH ../../.
cd ..
rm -rf cmake_tmp
echo ""
echo "Call cmake_six with FLAG as an argument to turn ON, and -FLAG to turn off."
echo ""
echo "Special options to cmake_six:"
echo "clean : Remove all build directories"
echo "help : Display this message"
echo ""
echo "Examples:"
echo "cmake_six gfortran"
echo "cmake_six gfortran release"
echo "cmake_six gfortran debug"
echo "cmake_six gfortran COLLIMAT -CRLIBM"
echo "cmake_six clean"
echo "cmake_six ifort-icc"
echo "cmake_six BIGNPART STF"
echo ""
echo "Specifying just a compiler for one language will cause cmake to use what it thinks is the default for your platform for the others."
exit
elif [[ $var == BUILD_TESTING ]]; then
testing=1
elif [[ $var == lxplus ]]; then
export PATH=/cvmfs/sft.cern.ch/lcg/contrib/CMake/latest/Linux-x86_64/bin:$PATH
export CMAKE_ROOT=/cvmfs/sft.cern.ch/lcg/contrib/CMake/latest/Linux-x86_64
source /cvmfs/sft.cern.ch/lcg/contrib/gcc/9/x86_64-centos7-gcc9-opt/setup.sh
fi
done
options_ALL=() # All set options
options_ON=() # All options switched ON
options_OFF=() # All options switched OFF
for var in "$@" #Loop over command line arguments
do
## Negative options
if [[ $var == -* ]]; then
#echo "OFF" $var
varOn=${var:1} # Without the "-"
for v in ${options_ALL[@]}
do
if [[ $v == $varOn ]]; then
echo "ERROR: option $v used more than once"
exit 1
fi
done
for v in ${compilers[@]}
do
if [[ $v == $varOn ]]; then
echo "ERROR: can't switch a compiler off"
exit 1
fi
done
for v in ${buildtypes[@]}
do
if [[ $v == $varOn ]]; then
echo "ERROR: can't switch a build type off"
exit 1
fi
done
options_ALL+=(${var:1})
options_OFF+=(${var:1})
## Positive options
else
#echo "ON" $var
varOn=$var
for v in ${options_ALL[@]}
do
if [[ $v == $varOn ]]; then
echo "ERROR: option $v used more than once"
exit 1
fi
done
thisWasSpecial="NO"
for v in ${compilers[@]}
do
if [[ $v == $varOn ]]; then
if [[ $options_COMPILER != "defaultcompiler" ]]; then
echo "ERROR: can't set multiple compilers"
exit 1
fi
options_COMPILER=$varOn
thisWasSpecial="YES"
fi
done
for v in ${buildtypes[@]}
do
if [[ $v == $varOn ]]; then
if [[ $options_BUILDTYPE != "defaultbuildtype" ]]; then
echo "ERROR: can't set multiple build types"
exit 1
fi
options_BUILDTYPE=$varOn
thisWasSpecial="YES"
fi
done
if [[ $var == "lxplus" ]]; then
thisWasSpecial="YES"
fi
if [[ $thisWasSpecial == "NO" ]]; then
options_ALL+=($var)
options_ON+=($var)
fi
thisWasSpecial="NO"
fi
done
#Sort the options
# http://stackoverflow.com/questions/7442417/how-to-sort-an-array-in-bash
IFS=$'\n' options_sorted_ALL=($(sort <<<"${options_ALL[*]}"))
IFS=$'\n' options_sorted_ON=($(sort <<<"${options_ON[*]}"))
IFS=$'\n' options_sorted_OFF=($(sort <<<"${options_OFF[*]}"))
echo "options_ON =" ${options_sorted_ON[@]}
echo "options_OFF =" ${options_sorted_OFF[@]}
#Build compiler options
CMAKE_OPTIONS_LIST=""
for i in $(seq 0 $(expr ${#compilers[@]} - 1 ) )
do
#echo $i ${compilers[$i]} ${compilers_CMAKE[$i]}
if [ $options_COMPILER == ${compilers[$i]} ]; then
#echo "FOUND!"
CMAKE_OPTIONS_LIST+=${compilers_CMAKE[$i]}
CMAKE_OPTIONS_LIST+=" "
fi
done
#Add build type option
for i in $(seq 0 $(expr ${#buildtypes[@]} - 1 ) )
do
if [ $options_BUILDTYPE == ${buildtypes[$i]} ]; then
#echo "FOUND!"
CMAKE_OPTIONS_LIST+=${buildtypes_CMAKE[$i]}
fi
done
#Make folder & build cmake options list
NAME="SixTrack_cmakesix"
for opt in ${options_sorted_ON[@]}
do
NAME+=_$opt
CMAKE_OPTIONS_LIST+=" -D$opt=ON"
done
for opt in ${options_sorted_OFF[@]}
do
NAME+=_NO$opt
CMAKE_OPTIONS_LIST+=" -D$opt=OFF"
done
NAME+=_$options_COMPILER
NAME+=_$options_BUILDTYPE
echo "NAME= '"$NAME"'"
echo "CMAKE options = '"$CMAKE_OPTIONS_LIST"'"
echo ""
#Run cmake
if [ -d $NAME ]; then
echo "Folder '"$NAME"' already exists, deleting!"
rm -rf $NAME
fi
mkdir $NAME
cd $NAME
set +e #From here on we catch errors manually...
#Use EVAL to split the options from $CMAKE_OPTIONS_LIST:
# http://stackoverflow.com/questions/6087494/bash-inserting-quotes-into-string-before-execution
#Use TEE:
# http://stackoverflow.com/questions/692000/how-do-i-write-stderr-to-a-file-while-using-tee-with-a-pipe
eval cmake -G \"Unix Makefiles\" $CMAKE_OPTIONS_LIST ../../. > >(tee cmake_stdout_log.txt) 2> >(tee cmake_stderr_log.txt)
if [ $? != 0 ]; then
echo ""
echo "ERROR in CMAKE;"
echo "Most likely you specified a bad argument!"
echo "The output from CMAKE should tell you more, so please look above this error message."
echo "Please run cmake_six help"
echo ""
# echo "cleaning up..."
#
# cd ..
# rm -rf $NAME
exit 1
fi
echo ""
if [ -s cmake_stderr_log.txt ]; then
echo ""
echo "Warning in CMAKE;"
echo "Did you misspell an argument?"
echo "Run './cmake_six help' to see possible arguments, remember UPPER/lower-cAsE"
echo "The output from CMAKE should tell you more, so please look above this error message."
echo ""
exit 1
fi
#Run make
#make -j | tee make_log.txt # No pretty colors...
#make -j # VERBOSE=1
if [[ $(pwd) == /afs/* && $testing == 1 ]]; then
#Random crashes with parallel make on AFS.
# echo "Warning: Running make single-threaded to avoid random crashes on AFS"
# echo "This will be slower that running parallel make..."
# make
# make does not seem to crash any more on afs even with -j in 2021, so for now it will be re-enabled.
make -j
else
#FreeBSD's make doesn't like a bare -j, so specify 8 CPUs
make -j 8
fi
if [ $? != 0 ]; then
echo ""
echo "ERROR in MAKE;"
echo "Could be a bug..."
echo ".. or maybe you need to install some libraries (or the compiler, or static versions of the libraries)?"
echo "The output from MAKE should tell you more, so please look above this error message."
echo ""
echo "You may also look at the unfinished compilation in the folder build/"$NAME
echo "try running 'make VERBOSE=1' in that folder for more information."
echo ""
exit 1
fi
echo ""
echo "Done! If everything went well, you'll find the executable in build/"$NAME
#echo "If you want to package the results to a tarball / .deb / .rpm etc., run 'make package' in this folder."
#