Warning, /geant4/cmake/Modules/G4OptionalComponents.cmake is written in an unsupported language. File is not indexed.
0001 # - Setup core required and optional components of Geant4
0002 #
0003 # Here we provide options to enable and configure required and optional
0004 # components, which may require third party libraries.
0005 #
0006 # We don't configure User Interface options here because these require
0007 # a higher degree of configuration so to keep things neat these have their
0008 # own Module.
0009 #
0010 # Options configured here:
0011 # CLHEP - Control use of internal G4clhep, or locate external CLHEP
0012 # Also control selection of singular or modular CLHEP libs
0013 # EXPAT - Control use of internal G4expat, or locate external EXPAT.
0014 # ZLIB - Control use of internal G4zlib, or locate external ZLIB
0015 # GDML - Requires external XercesC
0016 # G3TOG4 - UNIX only
0017 # USOLIDS - Allow use of VecGeom classes in geometry, and must find
0018 # external VecGeom install
0019 # FREETYPE - For analysis/vis modules, find external FreeType install
0020
0021 #-----------------------------------------------------------------------
0022 # CLHEP
0023 # ^^^^^
0024 #
0025 # By default, Geant4 is built with its own internal copy of the CLHEP
0026 # libraries and headers. An external install of CLHEP may be used
0027 # instead by setting the `GEANT4_USE_SYSTEM_CLHEP` to `ON`.
0028 #
0029 # CMake can be pointed to the required external install of CLHEP
0030 # by providing the `CLHEP_ROOT_DIR` option. Setting this variable
0031 # will automatically enable use of an external CLHEP.
0032 #
0033 set(_default_use_system_clhep OFF)
0034 if(CLHEP_ROOT_DIR)
0035 set(_default_use_system_clhep ON)
0036 list(INSERT CMAKE_PREFIX_PATH 0 "${CLHEP_ROOT_DIR}")
0037 endif()
0038
0039 option(GEANT4_USE_SYSTEM_CLHEP "Use system CLHEP library" ${_default_use_system_clhep})
0040
0041 if(GEANT4_USE_SYSTEM_CLHEP)
0042 find_package(CLHEP 2.4.6.0 REQUIRED CONFIG)
0043 geant4_save_package_variables(CLHEP CLHEP_DIR)
0044 else()
0045 set(CLHEP_FOUND TRUE)
0046 set(CLHEP_LIBRARIES G4clhep)
0047 endif()
0048
0049 geant4_add_feature(GEANT4_USE_SYSTEM_CLHEP "Using system CLHEP library")
0050
0051 #-----------------------------------------------------------------------
0052 # Find required EXPAT package
0053 # We always use the internal G4expat on WIN32.
0054 # On other platforms, we default to use the system library.
0055 # If we use the internal G4expat, fix the EXPAT_XXX variables to point
0056 # to the internal location of expat headers and library target so Geant4
0057 # clients of expat have a consistent interface.
0058 #
0059 if(WIN32)
0060 set(EXPAT_FOUND TRUE)
0061 set(GEANT4_USE_BUILTIN_EXPAT TRUE)
0062 set(EXPAT_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/source/externals/expat/include)
0063 set(G4EXPAT_LIBRARIES G4expat)
0064 else()
0065 option(GEANT4_USE_SYSTEM_EXPAT "Use system Expat library" ON)
0066
0067 if(GEANT4_USE_SYSTEM_EXPAT)
0068 # If system package requested, find it or fail
0069 find_package(EXPAT REQUIRED)
0070
0071 # Check version requirement externally to provide information
0072 # on using internal expat.
0073 if(${EXPAT_VERSION_STRING} VERSION_LESS "2.0.1")
0074 set(__badexpat_include_dir ${EXPAT_INCLUDE_DIR})
0075 set(__badexpat_library ${EXPAT_LIBRARY})
0076 unset(EXPAT_FOUND)
0077 unset(EXPAT_INCLUDE_DIR CACHE)
0078 unset(EXPAT_LIBRARY CACHE)
0079 unset(EXPAT_LIBRARY_RELEASE CACHE)
0080 unset(EXPAT_LIBRARY_DEBUG CACHE)
0081 message(FATAL_ERROR
0082 "Detected system expat header and library:
0083 EXPAT_INCLUDE_DIR = ${__badexpat_include_dir}
0084 EXPAT_LIBRARY = ${__badexpat_library}
0085 are of insufficient version '${EXPAT_VERSION_STRING}' (Required >= 2.0.1)
0086 Set the above CMake variables to point to an expat install of the required version, or set GEANT4_USE_SYSTEM_EXPAT to OFF to use Geant4's packaged version.")
0087 endif()
0088
0089 # Backward compatibility for sources.cmake using the variable
0090 set(G4EXPAT_LIBRARIES EXPAT::EXPAT)
0091 geant4_save_package_variables(EXPAT EXPAT_INCLUDE_DIR EXPAT_LIBRARY EXPAT_LIBRARY_RELEASE EXPAT_LIBRARY_DEBUG)
0092 else()
0093 set(EXPAT_FOUND TRUE)
0094 set(GEANT4_USE_BUILTIN_EXPAT TRUE)
0095 set(EXPAT_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/source/externals/expat/include)
0096 set(G4EXPAT_LIBRARIES G4expat)
0097 endif()
0098 endif()
0099
0100 geant4_add_feature(GEANT4_USE_SYSTEM_EXPAT "Using system EXPAT library")
0101
0102 #-----------------------------------------------------------------------
0103 # Find required ZLIB package, defaulting in internal
0104 option(GEANT4_USE_SYSTEM_ZLIB "Use system zlib library" OFF)
0105 if(GEANT4_USE_SYSTEM_ZLIB)
0106 find_package(ZLIB REQUIRED)
0107 # Backward compatibility for sources.cmake using the variable
0108 set(G4ZLIB_LIBRARIES ZLIB::ZLIB)
0109 geant4_save_package_variables(ZLIB ZLIB_INCLUDE_DIR ZLIB_LIBRARY_DEBUG ZLIB_LIBRARY_RELEASE)
0110 else()
0111 set(ZLIB_FOUND TRUE)
0112 set(GEANT4_USE_BUILTIN_ZLIB TRUE)
0113 set(G4ZLIB_LIBRARIES G4zlib)
0114 endif()
0115
0116 geant4_add_feature(GEANT4_USE_SYSTEM_ZLIB "Using system zlib library")
0117
0118 #-----------------------------------------------------------------------
0119 # Find required PTL, optional TBB support, defaulting to internal
0120 option(GEANT4_USE_SYSTEM_PTL "Use system PTL library" OFF)
0121 option(GEANT4_USE_TBB "Use TBB as PTL's tasking backend" OFF)
0122 cmake_dependent_option(GEANT4_USE_PTL_LOCKS "Enable mutex locking in PTL task subqueues" OFF "NOT GEANT4_USE_SYSTEM_PTL" OFF)
0123 mark_as_advanced(GEANT4_USE_SYSTEM_PTL GEANT4_USE_PTL_LOCKS GEANT4_USE_TBB)
0124
0125 if(GEANT4_USE_SYSTEM_PTL)
0126 if(GEANT4_USE_TBB)
0127 find_package(PTL 2.0.0 REQUIRED TBB)
0128 else()
0129 find_package(PTL 2.0.0 REQUIRED)
0130 if(PTL_TBB_FOUND AND NOT GEANT4_USE_TBB)
0131 set(GEANT4_USE_TBB ON CACHE BOOL "Use TBB as PTL's tasking backend (forced)" FORCE)
0132 message(STATUS "Forcing GEANT4_USE_TBB to ON, required by system PTL: ${PTL_DIR}")
0133 endif()
0134 endif()
0135 set(PTL_LIBRARIES PTL::ptl)
0136 geant4_save_package_variables(PTL PTL_DIR)
0137 else()
0138 # Prempt PTL's find of TBB so we can cache the variables
0139 if(GEANT4_USE_TBB)
0140 find_package(TBB REQUIRED)
0141 endif()
0142 set(PTL_FOUND TRUE)
0143 set(GEANT4_USE_BUILTIN_PTL TRUE)
0144 set(PTL_LIBRARIES G4ptl)
0145 endif()
0146
0147 geant4_add_feature(GEANT4_USE_SYSTEM_PTL "Using system PTL library")
0148 geant4_add_feature(GEANT4_USE_PTL_LOCKS "Enabled mutex locking in PTL task subqueues")
0149 geant4_add_feature(GEANT4_USE_TBB "Using TBB as PTL's tasking backend")
0150 # Always cache TBB even if not used. Empty vars will not be exported.
0151 geant4_save_package_variables(TBB TBB_DIR TBB_INCLUDE_DIR TBB_LIBRARY TBB_LIBRARY_DEBUG TBB_LIBRARY_RELEASE)
0152
0153 #-----------------------------------------------------------------------
0154 # Optional Support for GDML - requires Xerces-C package
0155 # Relies on XercesC::XercesC imported target (since CMake 3.5)
0156 set(_default_use_gdml OFF)
0157 if(XERCESC_ROOT_DIR)
0158 set(_default_use_gdml ON)
0159 list(INSERT CMAKE_PREFIX_PATH 0 "${XERCESC_ROOT_DIR}")
0160 endif()
0161
0162 option(GEANT4_USE_GDML "Build Geant4 with GDML support" ${_default_use_gdml})
0163
0164 if(GEANT4_USE_GDML)
0165 find_package(XercesC REQUIRED)
0166 geant4_save_package_variables(XercesC XercesC_INCLUDE_DIR XercesC_LIBRARY_DEBUG XercesC_LIBRARY_RELEASE)
0167 endif()
0168
0169 geant4_add_feature(GEANT4_USE_GDML "Building Geant4 with GDML support")
0170
0171 #-----------------------------------------------------------------------
0172 # Optional use of smart stack
0173 # With this option, G4StackManager uses G4SmartTrackStack instead of
0174 # ordinary G4TrackStack as the Urgent stack. G4SmartTrackStack tries to
0175 # stick to the same kind of particle as the previous track when Pop()
0176 # is called. This G4SmartTrackStack may provide some performance
0177 # improvements in particular for crystal calorimeters in high energy
0178 # physics experiments. On the other hand, G4SmartTrackStack won't give
0179 # any benefit for granular geometry or lower energy applications, while
0180 # it may causes some visible memory footprint increase.
0181
0182 option(GEANT4_USE_SMARTSTACK "Use smart track stack" OFF)
0183 mark_as_advanced(GEANT4_USE_SMARTSTACK)
0184 geant4_add_feature(GEANT4_USE_SMARTSTACK "Use smart track stack")
0185
0186 #-----------------------------------------------------------------------
0187 # Optional support for G3TOG4 convertion interface.
0188 # We do not build the rztog4 application.
0189 # -- OLDER NOTES --
0190 # The G3toG4 *library* should always be built, but the rztog4 application
0191 # requires a Fortran compiler AND CERNLIB, so is optional.
0192 # Only on *NIX because converter requires CERNLIB, and Windows support for
0193 # this is an unknown quantity at present (can always change later).
0194 # -- OLDER NOTES --
0195 #
0196 if(UNIX)
0197 option(GEANT4_USE_G3TOG4 "Build Geant3 ASCII call list reader library" OFF)
0198 GEANT4_ADD_FEATURE(GEANT4_USE_G3TOG4 "Building Geant3 ASCII call list reader library")
0199 endif()
0200
0201 #-----------------------------------------------------------------------
0202 # Optional support for VecGeom - Requires VecGeom package
0203 # GEANT4_USE_USOLIDS is a list argument which must take values:
0204 # - Empty/CMake boolean false : DEFAULT, do not replace G4 solids with VecGeom
0205 # - ALL/CMake boolean true : Replace all G4 solids with VecGeom
0206 # - List : Replace listed G4 solids with VecGeom equivalents. Valid elements are
0207 set(GEANT4_USOLIDS_SHAPES
0208 BOX
0209 CONS
0210 CTUBS
0211 ELLIPSOID
0212 ELLIPTICALCONE
0213 ELLIPTICALTUBE
0214 EXTRUDEDSOLID
0215 HYPE
0216 GENERICPOLYCONE
0217 GENERICTRAP
0218 ORB
0219 PARA
0220 PARABOLOID
0221 POLYCONE
0222 POLYHEDRA
0223 SPHERE
0224 TESSELLATEDSOLID
0225 TET
0226 TRAP
0227 TRD
0228 TORUS
0229 TUBS
0230 )
0231
0232 set(GEANT4_USE_USOLIDS OFF CACHE STRING "EXPERIMENTAL: List Geant4 solids to replace with VecGeom equivalents (ALL;${GEANT4_USOLIDS_SHAPES})")
0233 mark_as_advanced(GEANT4_USE_USOLIDS)
0234
0235 # - Must be a CMake list - no real way to enforce this
0236 # Preprocess by stripping any spaces and uppercasing
0237 string(REPLACE " " "" __g4_usolids_shape_list "${GEANT4_USE_USOLIDS}")
0238 string(TOUPPER "${__g4_usolids_shape_list}" __g4_usolids_shape_list)
0239
0240 # - Check for use of all or usolids
0241 set(GEANT4_USE_ALL_USOLIDS OFF)
0242 string(REGEX MATCH "ALL|^(1|ON|YES|TRUE)" GEANT4_USE_ALL_USOLIDS "${__g4_usolids_shape_list}")
0243
0244 # - Check and validate partial non-empty list
0245 if(NOT GEANT4_USE_ALL_USOLIDS AND GEANT4_USE_USOLIDS)
0246 set(GEANT4_USE_PARTIAL_USOLIDS ON)
0247 set(GEANT4_USE_PARTIAL_USOLIDS_SHAPE_LIST)
0248
0249 foreach(__g4_usolids_requested_shape ${__g4_usolids_shape_list})
0250 list(FIND GEANT4_USOLIDS_SHAPES "${__g4_usolids_requested_shape}" __g4solids_shape_index)
0251 if(__g4solids_shape_index GREATER -1)
0252 list(APPEND GEANT4_USE_PARTIAL_USOLIDS_SHAPE_LIST ${__g4_usolids_requested_shape})
0253 else()
0254 message(FATAL_ERROR "GEANT4_USE_USOLIDS: unknown shape '${__g4_usolids_requested_shape}' in input, must be one of\n${GEANT4_USOLIDS_SHAPES}\n")
0255 endif()
0256 endforeach()
0257 endif()
0258
0259
0260 # - Geant4 USolids/VecGom setup
0261 if(GEANT4_USE_ALL_USOLIDS OR GEANT4_USE_PARTIAL_USOLIDS)
0262 find_package(VecGeom 1.2.6 REQUIRED)
0263 geant4_save_package_variables(VecGeom VecGeom_DIR)
0264
0265 # If VecCore_DIR is set, means updated VecGeom install used, so
0266 # also store VecCore_DIR
0267 if(VecCore_DIR)
0268 geant4_save_package_variables(VecGeom VecCore_DIR)
0269 endif()
0270
0271 if(GEANT4_USE_ALL_USOLIDS)
0272 set(G4GEOM_USE_USOLIDS TRUE)
0273 geant4_add_feature(GEANT4_USE_USOLIDS "Replacing Geant4 solids with all VecGeom equivalents (EXPERIMENTAL)")
0274 else()
0275 set(G4GEOM_USE_PARTIAL_USOLIDS TRUE)
0276 foreach(__g4_usolid_shape ${GEANT4_USE_PARTIAL_USOLIDS_SHAPE_LIST})
0277 set(G4GEOM_USE_U${__g4_usolid_shape} TRUE)
0278 endforeach()
0279 geant4_add_feature(GEANT4_USE_USOLIDS "Replacing Geant4 solids with VecGeom equivalents for ${GEANT4_USE_PARTIAL_USOLIDS_SHAPE_LIST} (EXPERIMENTAL)")
0280 endif()
0281 endif()
0282
0283
0284 #-----------------------------------------------------------------------
0285 # Optional support for Freetype - Requires external Freetype install
0286 #
0287 option(GEANT4_USE_FREETYPE "Build Geant4 Analysis/Visualization with Freetype support" OFF)
0288 mark_as_advanced(GEANT4_USE_FREETYPE)
0289
0290 if(GEANT4_USE_FREETYPE)
0291 find_package(Freetype REQUIRED)
0292 geant4_save_package_variables(Freetype
0293 FREETYPE_INCLUDE_DIR_freetype2
0294 FREETYPE_INCLUDE_DIR_ft2build
0295 FREETYPE_LIBRARY_DEBUG
0296 FREETYPE_LIBRARY_RELEASE)
0297 endif()
0298
0299 geant4_add_feature(GEANT4_USE_FREETYPE "Building Geant4 Analysis/Visualization with Freetype support")
0300
0301 #-----------------------------------------------------------------------
0302 # Optional support for HDF5
0303 # - Requires external HDF5 1.8 or higher install
0304 # - Install must be MT safe if building Geant4 in MT mode
0305 #
0306 option(GEANT4_USE_HDF5 "Build Geant4 analysis library with HDF5 support" OFF)
0307 mark_as_advanced(GEANT4_USE_HDF5)
0308
0309 if(GEANT4_USE_HDF5)
0310 find_package(HDF5 1.8 REQUIRED)
0311 include("${CMAKE_CURRENT_LIST_DIR}/G4HDF5Shim.cmake")
0312 # Backward compatibility
0313 set(HDF5_LIBRARIES hdf5::hdf5)
0314
0315 # May have found via config mode...
0316 if(HDF5_DIR)
0317 geant4_save_package_variables(HDF5 HDF5_DIR)
0318 else()
0319 # Otherwise almost certainly used compiler wrapper
0320 geant4_save_package_variables(HDF5 HDF5_C_COMPILER_EXECUTABLE HDF5_C_LIBRARY_hdf5)
0321 endif()
0322 endif()
0323
0324 geant4_add_feature(GEANT4_USE_HDF5 "Building Geant4 analysis library with HDF5 support")