Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-30 07:57:41

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   detector_benchmarks)
0093     sourcepath=$module/benchmarks/rich
0094     ;;
0095   juggler)
0096     prefix=$JUGGLER_INSTALL_PREFIX
0097     nproc=2 # maybe memory hungry
0098     genOpt CMAKE_FIND_DEBUG_MODE=OFF
0099     ;;
0100   athena)
0101     genOpt IRT_AUXFILE=ON
0102     # symlink beamline compact files
0103     printf "\nsymlink beamline to local...\n"
0104     rm -vf $module/ip6
0105     ln -svf $BEAMLINE_PATH/ip6 $module/ip6
0106     ;;
0107   NPDet)
0108     prefix=$module/install
0109     ;;
0110   DD4hep)
0111     prefix=$module/install
0112     genOpt DD4HEP_USE_GEANT4=ON
0113     genOpt DD4HEP_USE_EDM4HEP=ON
0114     genOpt DD4HEP_USE_HEPMC3=ON
0115     genOpt Boost_NO_BOOST_CMAKE=ON
0116     genOpt DD4HEP_USE_LCIO=ON
0117     genOpt BUILD_TESTING=ON
0118     genOpt ROOT_DIR=$ROOTSYS
0119     genOpt CMAKE_BUILD_TYPE=Release
0120     ;;
0121   Catch2)
0122     ;;
0123   afterburner)
0124     sourcepath=$module/cpp
0125     genOpt HEPMC3_ROOTIO=ON
0126     ;;
0127 esac
0128 
0129 ########################################
0130 # build cmake commands
0131 
0132 # set buildsystem generation command
0133 genOpt CMAKE_INSTALL_PREFIX=$prefix
0134 genOpts+=$extraOpts
0135 buildSys=$module/build
0136 cmakeGen="cmake -S $sourcepath -B $buildSys $genOpts"
0137 
0138 # set build command
0139 buildOpts="-j $nproc"
0140 # if [ $clean -eq 1 ]; then
0141 #   buildOpts+=" --fresh" # FIXME: need cmake 3.24+; replaces `rm $buildSys` below
0142 # fi
0143 cmakeBuild="cmake --build $buildSys -j$nproc"
0144 
0145 # set install command
0146 cmakeInstall="cmake --install $buildSys"
0147 
0148 # print
0149 printf """
0150 CMAKE COMMANDS:
0151 ========================================\n
0152 [ generate buildsystem ]\n$cmakeGen\n
0153 [ build ]\n$cmakeBuild\n
0154 [ install ]\n$cmakeInstall\n
0155 ========================================\n
0156 """
0157 
0158 ########################################
0159 # module-specific cleans
0160 if [ $clean -eq 1 ]; then
0161   # remove build system
0162   # FIXME: delete when using `cmake --fresh`
0163   echo "--- CLEAN BUILDSYSTEM $buildSys"
0164   mkdir -p $buildSys
0165   rm -rv $buildSys
0166   case $module in
0167     epic)
0168       echo "--- CLEAN: rendered compact files from source directory..."
0169       rm -vf $module/epic*.xml
0170       echo "--- CLEAN: transient compact files from scripts/vary_params.rb..."
0171       rm -vf $module/epic_drich_variant*.xml
0172       rm -vf $module/compact/drich_variant*.xml
0173       rm -vf ${DETECTOR_PATH}/epic_drich_variant*.xml
0174       rm -vf ${DETECTOR_PATH}/compact/drich_variant*.xml
0175       ;;
0176   esac
0177 fi
0178 
0179 ########################################
0180 # run cmake
0181 [ $fast -eq 0 ] && $cmakeGen
0182 $cmakeBuild
0183 $cmakeInstall
0184 
0185 ########################################
0186 # post-cmake tasks
0187 function warn_env {
0188   printf "\nIf this is your first time installing module '$module' to prefix\n  '$prefix'\nsource environ.sh again\n\n"
0189 }
0190 case $module in
0191   epic)
0192     warn_env
0193     ;;
0194   EICrecon)
0195     warn_env
0196     ;;
0197   athena)
0198     # make legacy prefix compatible with EPIC expectations
0199     printf "\ncompatibility updates for built targets...\n"
0200     rm -vf $DETECTOR_PATH/ip6
0201     ln -svf $BEAMLINE_PATH/ip6 $DETECTOR_PATH/ip6
0202     ln -svf $DETECTOR_PATH/compact/subsystem_views/drich_only.xml $DETECTOR_PATH/${DETECTOR}_drich_only.xml
0203     ;;
0204   NPDet)
0205     printf "\nDone. To use, run:  source scripts/this_NPDet.sh\n\n"
0206     printf "Troubleshooting: try instead to directly call scripts in NPDet/install/bin\n\n"
0207     ;;
0208   DD4hep)
0209     printf "\nDone. To use, run:  source scripts/this_DD4hep.sh\n\n"
0210     ;;
0211 esac