Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-05-18 07:43:06

0001 #!/bin/bash
0002 # general cmake wrapper, with module-specific settings
0003 
0004 set -e
0005 
0006 ### custom compiler ##################
0007 # export CC=gcc; export CXX=g++;
0008 # export CC=clang; export CXX=clang++;
0009 ######################################
0010 
0011 # check environment
0012 if [ -z "$DRICH_DEV" ]; then echo "ERROR: source environ.sh"; exit 1; fi
0013 if [ -z "$BUILD_NPROC" ]; then export BUILD_NPROC=1; fi
0014 
0015 # set module, and check for existence
0016 if [ $# -eq 0 ]; then
0017   echo """
0018   USAGE: $0 [MODULE] [OPTIONS]
0019 
0020   - [MODULE] is a repository directory, e.g., \"epic\"
0021 
0022   - [OPTIONS] will be passed to cmake
0023     - pass no OPTIONS to use the defaults set in $0
0024     - if the first OPTION is:
0025       - \"clean\": the build and install directories will be cleaned
0026       - \"fast\": skip buildsystem generation
0027   """
0028   exit 2
0029 fi
0030 module=$(echo $1 | sed 's;/$;;')
0031 shift
0032 if [ ! -d "$module" ]; then
0033   echo "WARNING: module \"$module\" does not exist"
0034   exit 0
0035 fi
0036 
0037 # determine if clean build, and set extraOpts
0038 clean=0
0039 fast=0
0040 extraOpts=""
0041 if [ $# -ge 1 ]; then
0042   case $1 in
0043     clean) clean=1; shift; ;;
0044     fast)  fast=1;  shift; ;;
0045   esac
0046   extraOpts=$*
0047 fi
0048 echo """
0049 BUILDING:
0050 module    = $module
0051 clean     = $clean
0052 fast      = $fast 
0053 extraOpts = $extraOpts
0054 """
0055 
0056 ########################################
0057 # common options
0058 prefix=$EIC_SHELL_PREFIX
0059 nproc=$BUILD_NPROC
0060 
0061 ########################################
0062 # override container builds with local builds
0063 export CMAKE_PREFIX_PATH=$prefix:$CMAKE_PREFIX_PATH
0064 
0065 ########################################
0066 # module-specific options and preparation
0067 genOpts=""
0068 function genOpt() { genOpts+="-D$* "; }
0069 sourcepath=$module
0070 case $module in
0071   EDM4eic)
0072     genOpt BUILD_DATA_MODEL=ON
0073     ;;
0074   EDM4hep)
0075     genOpt BUILD_DATA_MODEL=ON
0076     genOpt USE_EXTERNAL_CATCH2=OFF
0077     ;;
0078   irt)
0079     genOpt CMAKE_BUILD_TYPE=Debug  # build with debugging symbols
0080     genOpt DELPHES=OFF
0081     genOpt EVALUATION=OFF
0082     genOpt IRT_ROOT_IO=ON
0083     ;;
0084   epic)
0085     ;;
0086   EICrecon)
0087     # genOpts+="-LAH " # dump variables
0088     genOpt CMAKE_BUILD_TYPE=Debug  # build with debugging symbols
0089     genOpt CMAKE_FIND_DEBUG_MODE=OFF
0090     genOpt EICRECON_VERBOSE_CMAKE=ON
0091     ;;
0092   reconstruction_benchmarks)
0093     ;;
0094   juggler)
0095     prefix=$JUGGLER_INSTALL_PREFIX
0096     nproc=2 # maybe memory hungry
0097     genOpt CMAKE_FIND_DEBUG_MODE=OFF
0098     ;;
0099   athena)
0100     genOpt IRT_AUXFILE=ON
0101     # symlink beamline compact files
0102     printf "\nsymlink beamline to local...\n"
0103     rm -vf $module/ip6
0104     ln -svf $BEAMLINE_PATH/ip6 $module/ip6
0105     ;;
0106   NPDet)
0107     prefix=$module/install
0108     ;;
0109   DD4hep)
0110     prefix=$module/install
0111     genOpt DD4HEP_USE_GEANT4=ON
0112     genOpt DD4HEP_USE_EDM4HEP=ON
0113     genOpt DD4HEP_USE_HEPMC3=ON
0114     genOpt Boost_NO_BOOST_CMAKE=ON
0115     genOpt DD4HEP_USE_LCIO=ON
0116     genOpt BUILD_TESTING=ON
0117     genOpt ROOT_DIR=$ROOTSYS
0118     genOpt CMAKE_BUILD_TYPE=Release
0119     ;;
0120   Catch2)
0121     ;;
0122   afterburner)
0123     sourcepath=$module/cpp
0124     genOpt HEPMC3_ROOTIO=ON
0125     ;;
0126 esac
0127 
0128 ########################################
0129 # build cmake commands
0130 
0131 # set buildsystem generation command
0132 genOpt CMAKE_INSTALL_PREFIX=$prefix
0133 genOpts+=$extraOpts
0134 buildSys=$module/build
0135 cmakeGen="cmake -S $sourcepath -B $buildSys $genOpts"
0136 
0137 # set build command
0138 buildOpts="-j $nproc"
0139 # if [ $clean -eq 1 ]; then
0140 #   buildOpts+=" --fresh" # FIXME: need cmake 3.24+; replaces `rm $buildSys` below
0141 # fi
0142 cmakeBuild="cmake --build $buildSys -j$nproc"
0143 
0144 # set install command
0145 cmakeInstall="cmake --install $buildSys"
0146 
0147 # print
0148 printf """
0149 CMAKE COMMANDS:
0150 ========================================\n
0151 [ generate buildsystem ]\n$cmakeGen\n
0152 [ build ]\n$cmakeBuild\n
0153 [ install ]\n$cmakeInstall\n
0154 ========================================\n
0155 """
0156 
0157 ########################################
0158 # module-specific cleans
0159 if [ $clean -eq 1 ]; then
0160   # remove build system
0161   # FIXME: delete when using `cmake --fresh`
0162   echo "--- CLEAN BUILDSYSTEM $buildSys"
0163   mkdir -p $buildSys
0164   rm -rv $buildSys
0165   case $module in
0166     epic)
0167       echo "--- CLEAN: rendered compact files from source directory..."
0168       rm -vf $module/epic*.xml
0169       echo "--- CLEAN: transient compact files from scripts/vary_params.rb..."
0170       rm -vf $module/epic_drich_variant*.xml
0171       rm -vf $module/compact/drich_variant*.xml
0172       rm -vf ${DETECTOR_PATH}/epic_drich_variant*.xml
0173       rm -vf ${DETECTOR_PATH}/compact/drich_variant*.xml
0174       ;;
0175   esac
0176 fi
0177 
0178 ########################################
0179 # run cmake
0180 [ $fast -eq 0 ] && $cmakeGen
0181 $cmakeBuild
0182 $cmakeInstall
0183 
0184 ########################################
0185 # post-cmake tasks
0186 function warn_env {
0187   printf "\nIf this is your first time installing module '$module' to prefix\n  '$prefix'\nsource environ.sh again\n\n"
0188 }
0189 case $module in
0190   epic)
0191     warn_env
0192     ;;
0193   EICrecon)
0194     warn_env
0195     ;;
0196   athena)
0197     # make legacy prefix compatible with EPIC expectations
0198     printf "\ncompatibility updates for built targets...\n"
0199     rm -vf $DETECTOR_PATH/ip6
0200     ln -svf $BEAMLINE_PATH/ip6 $DETECTOR_PATH/ip6
0201     ln -svf $DETECTOR_PATH/compact/subsystem_views/drich_only.xml $DETECTOR_PATH/${DETECTOR}_drich_only.xml
0202     ;;
0203   NPDet)
0204     printf "\nDone. To use, run:  source scripts/this_NPDet.sh\n\n"
0205     printf "Troubleshooting: try instead to directly call scripts in NPDet/install/bin\n\n"
0206     ;;
0207   DD4hep)
0208     printf "\nDone. To use, run:  source scripts/this_DD4hep.sh\n\n"
0209     ;;
0210 esac