-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.sh
executable file
·210 lines (192 loc) · 5.18 KB
/
build.sh
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
#!/bin/bash
# general cmake wrapper, with module-specific settings
set -e
### custom compiler ##################
# export CC=gcc; export CXX=g++;
# export CC=clang; export CXX=clang++;
######################################
# check environment
if [ -z "$DRICH_DEV" ]; then echo "ERROR: source environ.sh"; exit 1; fi
if [ -z "$BUILD_NPROC" ]; then export BUILD_NPROC=1; fi
# set module, and check for existence
if [ $# -eq 0 ]; then
echo """
USAGE: $0 [MODULE] [OPTIONS]
- [MODULE] is a repository directory, e.g., \"epic\"
- [OPTIONS] will be passed to cmake
- pass no OPTIONS to use the defaults set in $0
- if the first OPTION is:
- \"clean\": the build and install directories will be cleaned
- \"fast\": skip buildsystem generation
"""
exit 2
fi
module=$(echo $1 | sed 's;/$;;')
shift
if [ ! -d "$module" ]; then
echo "WARNING: module \"$module\" does not exist"
exit 0
fi
# determine if clean build, and set extraOpts
clean=0
fast=0
extraOpts=""
if [ $# -ge 1 ]; then
case $1 in
clean) clean=1; shift; ;;
fast) fast=1; shift; ;;
esac
extraOpts=$*
fi
echo """
BUILDING:
module = $module
clean = $clean
fast = $fast
extraOpts = $extraOpts
"""
########################################
# common options
prefix=$EIC_SHELL_PREFIX
nproc=$BUILD_NPROC
########################################
# override container builds with local builds
export CMAKE_PREFIX_PATH=$prefix:$CMAKE_PREFIX_PATH
########################################
# module-specific options and preparation
genOpts=""
function genOpt() { genOpts+="-D$* "; }
sourcepath=$module
case $module in
EDM4eic)
genOpt BUILD_DATA_MODEL=ON
;;
EDM4hep)
genOpt BUILD_DATA_MODEL=ON
genOpt USE_EXTERNAL_CATCH2=OFF
;;
irt)
genOpt CMAKE_BUILD_TYPE=Debug # build with debugging symbols
genOpt DELPHES=OFF
genOpt EVALUATION=OFF
genOpt IRT_ROOT_IO=ON
;;
epic)
;;
EICrecon)
# genOpts+="-LAH " # dump variables
genOpt CMAKE_BUILD_TYPE=Debug # build with debugging symbols
genOpt CMAKE_FIND_DEBUG_MODE=OFF
genOpt EICRECON_VERBOSE_CMAKE=ON
;;
reconstruction_benchmarks)
;;
juggler)
prefix=$JUGGLER_INSTALL_PREFIX
nproc=2 # maybe memory hungry
genOpt CMAKE_FIND_DEBUG_MODE=OFF
;;
athena)
genOpt IRT_AUXFILE=ON
# symlink beamline compact files
printf "\nsymlink beamline to local...\n"
rm -vf $module/ip6
ln -svf $BEAMLINE_PATH/ip6 $module/ip6
;;
NPDet)
prefix=$module/install
;;
DD4hep)
prefix=$module/install
genOpt DD4HEP_USE_GEANT4=ON
genOpt DD4HEP_USE_EDM4HEP=ON
genOpt DD4HEP_USE_HEPMC3=ON
genOpt Boost_NO_BOOST_CMAKE=ON
genOpt DD4HEP_USE_LCIO=ON
genOpt BUILD_TESTING=ON
genOpt ROOT_DIR=$ROOTSYS
genOpt CMAKE_BUILD_TYPE=Release
;;
Catch2)
;;
afterburner)
sourcepath=$module/cpp
genOpt HEPMC3_ROOTIO=ON
;;
esac
########################################
# build cmake commands
# set buildsystem generation command
genOpt CMAKE_INSTALL_PREFIX=$prefix
genOpts+=$extraOpts
buildSys=$module/build
cmakeGen="cmake -S $sourcepath -B $buildSys $genOpts"
# set build command
buildOpts="-j $nproc"
# if [ $clean -eq 1 ]; then
# buildOpts+=" --fresh" # FIXME: need cmake 3.24+; replaces `rm $buildSys` below
# fi
cmakeBuild="cmake --build $buildSys -j$nproc"
# set install command
cmakeInstall="cmake --install $buildSys"
# print
printf """
CMAKE COMMANDS:
========================================\n
[ generate buildsystem ]\n$cmakeGen\n
[ build ]\n$cmakeBuild\n
[ install ]\n$cmakeInstall\n
========================================\n
"""
########################################
# module-specific cleans
if [ $clean -eq 1 ]; then
# remove build system
# FIXME: delete when using `cmake --fresh`
echo "--- CLEAN BUILDSYSTEM $buildSys"
mkdir -p $buildSys
rm -rv $buildSys
case $module in
epic)
echo "--- CLEAN: rendered compact files from source directory..."
rm -vf $module/epic*.xml
echo "--- CLEAN: transient compact files from scripts/vary_params.rb..."
rm -vf $module/epic_drich_variant*.xml
rm -vf $module/compact/drich_variant*.xml
rm -vf ${DETECTOR_PATH}/epic_drich_variant*.xml
rm -vf ${DETECTOR_PATH}/compact/drich_variant*.xml
;;
esac
fi
########################################
# run cmake
[ $fast -eq 0 ] && $cmakeGen
$cmakeBuild
$cmakeInstall
########################################
# post-cmake tasks
function warn_env {
printf "\nIf this is your first time installing module '$module' to prefix\n '$prefix'\nsource environ.sh again\n\n"
}
case $module in
epic)
warn_env
;;
EICrecon)
warn_env
;;
athena)
# make legacy prefix compatible with EPIC expectations
printf "\ncompatibility updates for built targets...\n"
rm -vf $DETECTOR_PATH/ip6
ln -svf $BEAMLINE_PATH/ip6 $DETECTOR_PATH/ip6
ln -svf $DETECTOR_PATH/compact/subsystem_views/drich_only.xml $DETECTOR_PATH/${DETECTOR}_drich_only.xml
;;
NPDet)
printf "\nDone. To use, run: source scripts/this_NPDet.sh\n\n"
printf "Troubleshooting: try instead to directly call scripts in NPDet/install/bin\n\n"
;;
DD4hep)
printf "\nDone. To use, run: source scripts/this_DD4hep.sh\n\n"
;;
esac