setupLCG.sh 15 KB
Newer Older
1
# Set the default LCG_XX release version
2
lcg_xx=85
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
lcgrel=

#-------------------------------------------------------------------------------
# Check that this setup script has been sourced
#-------------------------------------------------------------------------------

if [ "$BASH_SOURCE" = "$0" ]; then # See CORALCOOL-2823
  echo "ERROR! The setup script was not sourced?" > /dev/stderr
  exit 1
elif [ "$BASH_SOURCE" = "" ]; then
  echo "ERROR! The setup script was not sourced from bash?" > /dev/stderr
  return 1
fi

# Determine the path to this sourced script
topdir=`dirname ${BASH_SOURCE}`
topdir=`cd ${topdir}; pwd`

#-------------------------------------------------------------------------------
# Parse command line arguments
#-------------------------------------------------------------------------------

usage()
{ 
Andrea Valassi's avatar
Andrea Valassi committed
27
28
  echo "Usage:   . $BASH_SOURCE [-b <BINARY_TAG>] [-l <xx_for_lcgxx>|-r <path_to_lcgrel>]" > /dev/stderr
  echo "Example: . $BASH_SOURCE -l 85"
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  echo "Example: . $BASH_SOURCE -r /cvmfs/sft.cern.ch/lcg/releases/LCG_85"
  echo "Example: . $BASH_SOURCE -b x86_64-slc6-clang37-opt -r /afs/cern.ch/sw/lcg/app/nightlies/dev2/Mon"
  echo "Example: . $BASH_SOURCE -b aarch64-ubuntu1404-gcc49-opt -r /home/${USER}/nightlies/20160207"
}

# Optionally choose an LCG release from command line arguments
# [Default: use the environment variable BINARY_TAG previously set by the user]
if [ "$1" == "-b" ]; then
  if [ "$2" != "" ]; then export BINARY_TAG=$2; shift 2; else usage; return 1; fi
fi

# Optionally choose an LCG release from command line arguments
# [Default: use the variable lcg_xx defined at the top of this script]
if [ "$1" == "-r" ]; then
43
  if [ "$2" != "" ]; then lcgrel=${2%/}; shift 2; else usage; return 1; fi
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
else
  if [ "$1" == "-l" ]; then
    if [ "$2" != "" ]; then lcg_xx=$2; shift 2; else usage; return 1; fi
  fi
  if [ -d /cvmfs ]; then
    lcgrel=/cvmfs/sft.cern.ch/lcg/releases/LCG_${lcg_xx}
  else
    lcgrel=/afs/cern.ch/sw/lcg/releases/LCG_${lcg_xx}
  fi
fi

# Fail if unexpected arguments are present
if [ "$*" != "" ]; then
  usage
  return 1
fi

# Sanity check on command line arguments
echo "INFO: set up CORAL/COOL against ${lcgrel}"
if [ ! -d "$lcgrel" ]; then
  echo "ERROR! Directory '${lcgrel}' does not exist" > /dev/stderr
  return 1
fi

#-------------------------------------------------------------------------------
# Check that BINARY_TAG has been set
#-------------------------------------------------------------------------------

# Require BINARY_TAG to be set a priori (CORALCOOL-2846).
# [Do not set BINARY_TAG from host arch/os/compiler any more (CORALCOOL-2851)]
# [Do not set BINARY_TAG from CMTCONFIG/CMAKECONFIG any more (CORALCOOL-2850)]
if [ "$BINARY_TAG" == "" ]; then
  echo "ERROR! BINARY_TAG is not set" > /dev/stderr
  exit 1
fi
echo "INFO: set up CORAL/COOL for BINARY_TAG ${BINARY_TAG}"

#-------------------------------------------------------------------------------
# Set up CMAKE_PREFIX_PATH for the given release (CORALCOOL-2846)
#-------------------------------------------------------------------------------

# Set up CMAKE_PREFIX_PATH for the given release (CORALCOOL-2846)
# Keep both tcmalloc and gperftools for now (eventually drop tcmalloc)
# [NB CORAL is included, any local build must be prepended a posteriori]
88
for pkgname in ccache Boost CppUnit expat frontier_client mysql oracle Python QMtest sqlite XercesC gperftools tcmalloc igprof libaio libunwind valgrind CORAL ROOT qt; do 
89
90
91
92
93
94
95
96
  pkgpath=${lcgrel}/${pkgname}
  if [ -d ${pkgpath} ]; then 
    export CMAKE_PREFIX_PATH=`find ${pkgpath} -mindepth 2 -maxdepth 2 -name ${BINARY_TAG}`:${CMAKE_PREFIX_PATH}
  fi 
done

#-------------------------------------------------------------------------------
# Set up CC and CXX from LCG_externals_${BINARY_TAG}.txt (CORALCOOL-2846)
Andrea Valassi's avatar
Andrea Valassi committed
97
# If the LCG summary does not exist, warn if CC and CXX have not been set
98
99
100
101
102
103
#-------------------------------------------------------------------------------

# 1. Parse the "LCG summary" file LCG_externals_${BINARY_TAG}.txt if it exists
# This file is created by lcgjenkins/extract_LCG_summary.py for release LCG_XX
# Do not extract BINARY_TAG from the PLATFORM line any longer (CORALCOOL-2846)
# Do not build CMAKE_PREFIX_PATH from this file any longer (CORALCOOL-2846)
104
# Warn if CC and CXX are already set, as these will be overridden by new values
105
106
107
108
109
lcgsum=${lcgrel}/LCG_externals_${BINARY_TAG}.txt
if [ -f ${lcgsum} ]; then
  echo "INFO: set up compiler from ${lcgsum}"
  comfla=`egrep "^COMPILER:" $lcgsum | sed "s|^COMPILER:||" | awk '{split($0,a,";"); print a[1]}' | awk '{sub(/^ +/, ""); print}'` 
  comver=`egrep "^COMPILER:" $lcgsum | sed "s|^COMPILER:||" | awk '{split($0,a,";"); print a[2]}' | awk '{sub(/^ +/, ""); print}'` 
110
111
112
  if [ "$CC" != "" ]; then echo "WARNING! CC will be overridden" > /dev/stderr; fi
  if [ "$CXX" != "" ]; then echo "WARNING! CXX will be overridden" > /dev/stderr; fi

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
  if [ "$comfla" == "gcc" ]; then
    export CC=lcg-gcc-${comver}
    export CXX=lcg-g++-${comver}
  elif [ "$comfla" == "icc" ]; then
    export CC=lcg-icc-${comver}
    export CXX=lcg-icpc-${comver}
  elif [ "$comfla" == "clang" ]; then
    export CC=lcg-clang-${comver}
    export CXX=lcg-clang++-${comver}
  else
    echo "ERROR! Unknown compiler flavor: '$comfla'" > /dev/stderr
    return 1
  fi
  # Set a _single_ path to _all_ lcg-gcc-x.y.z compilers (LHCb recipe),
  # so that the correct compiler will then be used depending on BINARY_TAG
  # Ensure that lcg-gcc-x.y.z scripts use actual compilers from cvmfs,
  # otherwise compiler is taken from AFS even for script on cvmfs (LBCORE-867)
  # Use AFS if no cvmfs (e.g. on buildcoverity, SPI-863)
  # Use a fixed version of LBSCRIPTS instead of prod for better version control
  # [Moved back here from Makefile (CORALCOOL-2846 and CORALCOOL-2847)]
  if [ -d /cvmfs ]; then
    export PATH=/cvmfs/lhcb.cern.ch/lib/lhcb/LBSCRIPTS/LBSCRIPTS_v8r6p7/InstallArea/scripts:$PATH
    export LCG_release_area=/cvmfs/sft.cern.ch/lcg/releases
  else
    export PATH=/afs/cern.ch/lhcb/software/releases/LBSCRIPTS/LBSCRIPTS_v8r6p7/InstallArea/scripts:$PATH
  fi
  # Ensure that lcg-gcc-x.y.z scripts work correctly on CentOS7 (CORALCOOL-2811)
  # [Moved back here from Makefile (CORALCOOL-2846 and CORALCOOL-2847)]
  if [ "$(lsb_release -si)" == "CentOS" ]; then
    export LCG_hostos="$(uname -i)"-cc"$(lsb_release -sr | cut -d. -f1)"
  else
    unset LCG_hostos
  fi

Andrea Valassi's avatar
Andrea Valassi committed
147
# 2. If the LCG summary does not exist, warn if CC and CXX have not been set
148
149
# [Note that lcgcmake relies on lcgjenkins/jk-setup.sh]
else
Andrea Valassi's avatar
Andrea Valassi committed
150
151
152
  echo "WARNING! cannot set up compiler from missing file ${lcgsum}"
  if [ "$CC" == "" ]; then echo "WARNING! CC is not set" > /dev/stderr; fi
  if [ "$CXX" == "" ]; then echo "WARNING! CXX is not set" > /dev/stderr; fi
153
154
155
156
157
158
159
160
161
162
fi

#-------------------------------------------------------------------------------
# Set up CMAKE_BUILD_TYPE from LCG build type in BINARY_TAG (CORALCOOL-2846)
#-------------------------------------------------------------------------------

# Set CMAKE_BUILD_TYPE from the LCG build type in BINARY_TAG
# [See lcg_get_target_platform in heptools-common.cmake from lcgcmake]
lcgbty=${BINARY_TAG##*-}
if [ "$lcgbty" == "opt" ]; then
Andrea Valassi's avatar
Andrea Valassi committed
163
  CMAKE_BUILD_TYPE=Release
164
elif [ "$lcgbty" == "dbg" ]; then
Andrea Valassi's avatar
Andrea Valassi committed
165
  CMAKE_BUILD_TYPE=Debug
166
elif [ "$lcgbty" == "cov" ]; then
Andrea Valassi's avatar
Andrea Valassi committed
167
  CMAKE_BUILD_TYPE=Coverage
168
elif [ "$lcgbty" == "pro" ]; then
Andrea Valassi's avatar
Andrea Valassi committed
169
  CMAKE_BUILD_TYPE=Profile
170
elif [ "$lcgbty" == "o2g" ]; then
Andrea Valassi's avatar
Andrea Valassi committed
171
  CMAKE_BUILD_TYPE=RelWithDebInfo
172
elif [ "$lcgbty" == "min" ]; then
Andrea Valassi's avatar
Andrea Valassi committed
173
  CMAKE_BUILD_TYPE=MinSizeRel
174
175
176
177
178
else
  echo "ERROR! Unknown LCG build type: '$lcgbty'" > /dev/stderr
  return 1
fi

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
#-------------------------------------------------------------------------------
# Set up CMAKE_CXX_FLAGS from BINARY_TAG (CORALCOOL-2854 and CORALCOOL-2846)
#-------------------------------------------------------------------------------

# Build flags (C++ std)
if [[ $BINARY_TAG == *clang* ]]; then
  CMAKE_CXX_FLAGS="-std=c++14"
elif [[ $BINARY_TAG == *gcc6* ]]; then # CORALCOOL-2895 and CORALCOOL-2913
  CMAKE_CXX_FLAGS="-std=c++14"
elif [[ $BINARY_TAG == *gcc5* ]]; then
  CMAKE_CXX_FLAGS="-std=c++14"
elif [[ $BINARY_TAG == *gcc49* ]]; then
  CMAKE_CXX_FLAGS="-std=c++1y"
elif [[ $BINARY_TAG == *gcc48* ]]; then
  CMAKE_CXX_FLAGS="-std=c++11"
fi

# Build flags (gcc-toolchain options for clang)
# [NB These are now no longer passed to lcgcmake (CORALCOOL-2846): is this ok?]
if [[ $BINARY_TAG == *mac* ]]; then
  : # noop
elif [[ $BINARY_TAG == *clang35* ]]; then # See CORALCOOL-2821
  CMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS} --gcc-toolchain=/cvmfs/sft.cern.ch/lcg/releases/gcc/4.9.1/x86_64-slc6" # cvmfs instead of AFS, see CORALCOOL-2855
elif [[ $BINARY_TAG == *clang37* ]]; then # See CORALCOOL-2821
  CMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS} --gcc-toolchain=/cvmfs/sft.cern.ch/lcg/releases/gcc/4.9.3/x86_64-slc6" # cvmfs instead of AFS, see CORALCOOL-2855
fi

206
#-------------------------------------------------------------------------------
207
208
209
210
211
212
# Set up Boost extra configuration for CMake as in lcgcmake (SPI-842)
#-------------------------------------------------------------------------------

# Follow the same logic as in lcgcmake/cmake/toolchain/heptools-common.cmake 
# See CORALCOOL-2806 (mac), SPI-842 (clang) and CORALCOOL-2797 (icc)
if [[ $BINARY_TAG == *mac* ]]; then
213
  Boost_COMPILER=" -DBoost_COMPILER=-xgcc42"
214
215
elif [[ $BINARY_TAG == *clang* ]]; then
  Boost_COMPILER=${BINARY_TAG%-*}
216
  Boost_COMPILER=" -DBoost_COMPILER=-${Boost_COMPILER#*-*-}"
217
elif [[ $BINARY_TAG == *icc* ]]; then
218
  Boost_COMPILER=" -DBoost_COMPILER=-il"
219
220
221
222
223
224
else
  Boost_COMPILER=
fi

# Always add Boost 1.59 (LCG80-84) and 1.61 (LCG85 and above)
# See CORALCOOL-2806 (1.59) and CORALCOOL-2903 (1.61) 
225
226
# Add only the two-digit Boost version as in Pere's lcgcmake patch (SPI-842)
Boost_extra_configuration="-DBoost_NO_BOOST_CMAKE=ON -DBoost_ADDITIONAL_VERSIONS='1.59 1.61'$Boost_COMPILER"
227
228
229

#-------------------------------------------------------------------------------
# Set up CMake
230
231
#-------------------------------------------------------------------------------

232
# Use CMake 3.6.0 from /cvmfs/sft.cern.ch/lcg/contrib on Linux
233
# Use AFS if no cvmfs (e.g. on buildcoverity, SPI-863)
234
235
236
237
238
# [Do not use the LCG stack cmake on Linux as it may use a different GLIBCXX]
if [ `uname -s` != "Linux" ]; then
  if [ -d ${lcgrel}/CMake ]; then
    export PATH=`find ${lcgrel}/CMake -mindepth 2 -maxdepth 2 -name ${BINARY_TAG}`/bin:${PATH}
  fi
239
240
241
242
243
244
245
246
247
248
elif [ -d /cvmfs ]; then
  export PATH=/cvmfs/sft.cern.ch/lcg/contrib/CMake/3.6.0/Linux-x86_64/bin:$PATH
else
  export PATH=/afs/cern.ch/sw/lcg/contrib/CMake/3.6.0/Linux-x86_64/bin:$PATH
fi

#-------------------------------------------------------------------------------
# Set up ninja
#-------------------------------------------------------------------------------

249
# Use ninja 1.4.0 from /cvmfs/sft.cern.ch/lcg/contrib/ninja on Linux
250
251
# Use AFS if no cvmfs (e.g. on buildcoverity, SPI-863)
# The hardcoded ninja path is valid on Linux but not on Darwin (CORALCOOL-2911)
252
253
254
255
# [Do not use the LCG stack ninja on Linux as it may use a different GLIBCXX]
if [ `uname -s` != "Linux" ]; then
  if [ -d ${lcgrel}/ninja ]; then
    export PATH=`find ${lcgrel}/ninja -mindepth 2 -maxdepth 2 -name ${BINARY_TAG}`/bin:${PATH}
256
    export CMAKE_PREFIX_PATH=`find ${lcgrel}/ninja -mindepth 2 -maxdepth 2 -name ${BINARY_TAG}`:${CMAKE_PREFIX_PATH}
257
258
  fi
else
259
260
261
262
263
264
265
266
267
268
269
270
271
  if [ -d /cvmfs/sft.cern.ch/lcg/contrib/ninja/1.4.0/x86_64-slc6 ]; then
    export PATH=/cvmfs/sft.cern.ch/lcg/contrib/ninja/1.4.0/x86_64-slc6:$PATH
  else
    export PATH=/afs/cern.ch/sw/lcg/contrib/ninja/1.4.0/x86_64-slc6:$PATH
  fi
fi

#-------------------------------------------------------------------------------
# Set up ccache
#-------------------------------------------------------------------------------

# Use the installation in the LCG release if it exists (CORALCOOL-2846)
if [ -d ${lcgrel}/ccache ]; then
272
  export PATH=`find ${lcgrel}/ccache -mindepth 2 -maxdepth 2 -name ${BINARY_TAG}`/bin:${PATH}
273
274
275
276
277
278
279
280
fi

# Configure the ccache directory (CORALCOOL-2844 and CORALCOOL-2846)
# Keep this here to allow interactive queries in this shell
export CCACHE_DIR=$topdir/.ccache
export CCACHE_CONFIGPATH=$CCACHE_DIR/ccache.conf

#-------------------------------------------------------------------------------
Andrea Valassi's avatar
Andrea Valassi committed
281
# Set up command line options to CMake
282
283
#-------------------------------------------------------------------------------

Andrea Valassi's avatar
Andrea Valassi committed
284
CMAKEFLAGS=
285

Andrea Valassi's avatar
Andrea Valassi committed
286
287
288
289
290
# Use ninja by default, if it exists, in the build rules generated by CMake
# [This is a CMake standard variable]
if ninja --version > /dev/null 2>&1; then 
  CMAKEFLAGS="-GNinja $CMAKEFLAGS"
fi
291

Andrea Valassi's avatar
Andrea Valassi committed
292
293
294
# Set BINARY_TAG (CORALCOOL-2849)
# [This is a CORAL/COOL variable, not a CMake standard variable]
CMAKEFLAGS="-DBINARY_TAG=$BINARY_TAG $CMAKEFLAGS"
295

Andrea Valassi's avatar
Andrea Valassi committed
296
297
298
299
# Set CMAKE_BUILD_TYPE
# [This is a CMake standard variable]
CMAKEFLAGS="-DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE $CMAKEFLAGS"

300
301
302
# Set CMAKE_CXX_FLAGS
CMAKEFLAGS="-DCMAKE_CXX_FLAGS=$CMAKE_CXX_FLAGS $CMAKEFLAGS"

Andrea Valassi's avatar
Andrea Valassi committed
303
304
305
306
307
308
309
310
# Set CMAKE_VERBOSE_MAKEFILE
# ** This is now enabled by default only in lcgcmake and cc-build, not here! **
# [This is a CMake standard variable]
# This sets VERBOSE=1 for make and passes -v as ninja command line argument
# Note that CMake >= 3.3 is required fo this to have an effect on ninja
# See https://github.com/ninja-build/ninja/issues/900
###CMAKEFLAGS="-DCMAKE_VERBOSE_MAKEFILE=ON $CMAKEFLAGS"

311
312
313
314
# Set Boost_ADDITIONAL_VERSIONS, Boost_COMPILER, Boost_NO_BOOST_CMAKE
# [These are CMake standard variables]
CMAKEFLAGS="$Boost_extra_configuration $CMAKEFLAGS"

Andrea Valassi's avatar
Andrea Valassi committed
315
316
317
318
319
320
321
322
323
324
325
# Enable ccache by default
# [This is a CORAL/COOL variable, not a CMake standard variable]
CMAKEFLAGS="-DCMAKE_USE_CCACHE=ON $CMAKEFLAGS"

# Relocate paths below LCG_releases_base (CORALCOOL-2829)
# [This is a CORAL/COOL variable, not a CMake standard variable]
CMAKEFLAGS="-DLCG_releases_base:STRING=${lcgrel} $CMAKEFLAGS"

# Export CMAKEFLAGS for future use in the CORAL/COOL Makefile
# [** NB: This is a CORAL/COOL variable, not a CMake standard variable! **]
export CMAKEFLAGS
Andrea Valassi's avatar
Andrea Valassi committed
326

327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
#-------------------------------------------------------------------------------
# Set up optional configuration parameters
#-------------------------------------------------------------------------------

# Optionally override installation directory location
# Use absolute paths or paths relative to the _build_ directory!
###export CMAKEFLAGS="-DCMAKE_INSTALL_PREFIX=../my.${BINARY_TAG} $CMAKEFLAGS"
###export CMAKEFLAGS="-DCMAKE_INSTALL_PREFIX=/tmp/my.${BINARY_TAG} $CMAKEFLAGS"

# Add setup overrides if any are present
if [ -f $topdir/overrideSetupCMake.sh ]; then
  echo "INFO: override defaults using $topdir/overrideSetupCMake.sh"
  . $topdir/overrideSetupCMake.sh
else
  echo "INFO: no overrides found"
fi
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357

#-------------------------------------------------------------------------------
# Dump all variables set by the setupLCG.sh script
#-------------------------------------------------------------------------------

###echo BINARY_TAG=$BINARY_TAG
###echo CMAKE_PREFIX_PATH=$CMAKE_PREFIX_PATH
###echo CMAKEFLAGS=$CMAKEFLAGS
###echo PATH=$PATH
###echo CC=$CC
###echo CXX=$CXX
###echo LCG_release_area=$LCG_release_area
###echo LCG_hostos=$LCG_hostos
###echo CCACHE_DIR=$CCACHE_DIR
###echo CCACHE_CONFIGPATH=$CCACHE_CONFIGPATH