Warning, /geant4/cmake/Modules/G4InstallData.cmake is written in an unsupported language. File is not indexed.
0001 # - Configure and install Geant4 Data Libraries
0002 # The following functions and macros are defined to help define, install,
0003 # reuse and export datasets and associated variables.
0004 #
0005 # FUNCTIONS AND MACROS
0006 # ====================
0007 # Public API
0008 # ----------
0009 # function geant4_get_datasetnames(<output variable>)
0010 # Store list of currently known dataset names in output variable
0011 #
0012 # function geant4_tupleize_datasets(<output variable>)
0013 # Set output variable to list of old-style dataset tuples.
0014 # A tuple has the format:
0015 # NAME/VERSION/FILENAME/EXTENSION/ENVVAR/MD5SUM
0016 # Provided for backward compatibility.
0017 #
0018 # function geant4_export_datasets([BUILD|INSTALL] <output variable>)
0019 # Set output variable to list of dataset tuples for export to
0020 # configuration scripts
0021 # A tuple has the format:
0022 # NAME/ENVVAR/PATH/FILENAME/MD5SUM
0023 # BUILD will set the PATH entry to the path to the dataset used
0024 # for the build of Geant4.
0025 #
0026 # INSTALL will set the PATH entry to the path to the dataset used
0027 # by an install of Geant4.
0028 #
0029 # function geant4_add_dataset(NAME <id>
0030 # VERSION <ver>
0031 # FILENAME <file>
0032 # EXTENSION <ext>
0033 # ENVVAR <varname>
0034 # MD5SUM <md5>)
0035 # Define a new dataset with the following properties
0036 # NAME common name of the dataset
0037 # VERSION dataset version
0038 # FILENAME name of packaged dataset file
0039 # EXTENSION extension of packaged dataset file
0040 # ENVVAR environment variable used by Geant4 code
0041 # to locate this dataset
0042 # MD5SUM MD5 hash of packaged dataset file
0043 #
0044 # function geant4_has_dataset(<name> <output variable>)
0045 # Set output variable to TRUE if the named dataset exists
0046 # in the list of known datasets.
0047 #
0048 # function geant4_get_dataset_property(<name> <property> <output variable>)
0049 # Set output variable to value of dataset "name"'s property.
0050 # If property does not exist, then value will be blank.
0051 #
0052 # function geant4_set_dataset_property(<name> <property> <value>)
0053 # Set value of dataset property to supplied value
0054 #
0055 # function geant4_configure_datasets(DESTINATION <dir>
0056 # DOWNLOAD <installmissing>
0057 # TIMEOUT <seconds>
0058 # )
0059 # Perform the actual heavy lifting to configure each declared
0060 # dataset for reuse or download as needed.
0061 #
0062 # function geant4_dataset_isinstalled(<name>
0063 # <root directory>
0064 # <output variable>)
0065 # Check if named dataset is installed under the root directory.
0066 # Set output variable to TRUE if it is, FALSE otherwise.
0067 #
0068 # function geant4_install_dataset(<name> <destination> <timeout>)
0069 # Download dataset with name to build directory, timing out the
0070 # download after timeout seconds, and install it
0071 # into its directory under the destination directory.
0072 #
0073 # function geant4_reuse_dataset(<name> <destination> <is installed>)
0074 # Reuse the dataset with name located at destination directory.
0075 # If it is not installed, warn user that it will need installing
0076 # manually in destination.
0077 #
0078
0079 #-----------------------------------------------------------------------
0080 # GEANT4 PHYSICS DATA - GLOBAL CMAKE VARIABLES
0081 #-----------------------------------------------------------------------
0082 # URLs, directories and dataset entries
0083 # We may want these as properties so we can have a small API for
0084 # retrieving them globally
0085 #-----------------------------------------------------------------------
0086 # Geant4 Data Repository
0087 set(GEANT4_DATASETS_URL "https://cern.ch/geant4-data/datasets")
0088
0089 # Where to install data in the build tree
0090 set(GEANT4_BUILD_FULL_DATADIR ${PROJECT_BINARY_DIR}/data)
0091
0092 # Where to install data in the install tree (a Default)
0093 set(GEANT4_INSTALL_DATADIR_DEFAULT "${CMAKE_INSTALL_DATADIR}/data")
0094
0095 # File containing dataset list
0096 set(GEANT4_DATASETS_DEFINITIONS "G4DatasetDefinitions")
0097
0098
0099 #-----------------------------------------------------------------------
0100 # GEANT4 PHYSICS DATA - PUBLIC CMAKE API FOR DATASET HANDLING
0101 #-----------------------------------------------------------------------
0102 # Properties? Shouldn't clash with the tuplized variable...
0103 define_property(GLOBAL PROPERTY "GEANT4_DATASETS"
0104 BRIEF_DOCS "List of all defined Geant4 dataset names"
0105 FULL_DOCS
0106 "Each element of the list gives the name defined for the dataset.
0107 This name can be used in other Geant4 Data API functions to
0108 extract other properties of the dataset"
0109 )
0110
0111 #-----------------------------------------------------------------------
0112 # function geant4_get_datasetnames(<output variable>)
0113 # Store list of currently known dataset names in output variable
0114 #
0115 function(geant4_get_datasetnames _output)
0116 get_property(_tmp GLOBAL PROPERTY GEANT4_DATASETS)
0117 set(${_output} ${_tmp} PARENT_SCOPE)
0118 endfunction()
0119
0120 #-----------------------------------------------------------------------
0121 # function geant4_tupleize_datasets(<output variable>)
0122 # Set output variable to list of old-style dataset tuples.
0123 # A tuple has the format:
0124 # NAME/VERSION/FILENAME/EXTENSION/ENVVAR/MD5SUM
0125 # Provided for backward compatibility.
0126 #
0127 function(geant4_tupleize_datasets _output)
0128 geant4_get_datasetnames(_names)
0129 set(_tmplist)
0130
0131 foreach(_ds ${_names})
0132 set(_tuple ${_ds})
0133 foreach(_p VERSION FILENAME EXTENSION ENVVAR MD5SUM)
0134 get_property(_tmpprop GLOBAL PROPERTY ${_ds}_${_p})
0135 list(APPEND _tuple ${_tmpprop})
0136 endforeach()
0137 string(REPLACE ";" "/" _tuple "${_tuple}")
0138 list(APPEND _tmplist "${_tuple}")
0139 endforeach()
0140
0141 set(${_output} ${_tmplist} PARENT_SCOPE)
0142 endfunction()
0143
0144 #-----------------------------------------------------------------------
0145 # function geant4_export_datasets([BUILD|INSTALL] <output variable>)
0146 # Set output variable to list of dataset tuples for export to
0147 # Geant4Config.cmake
0148 # A tuple has the format:
0149 # NAME/ENVVAR/PATH/FILENAME/MD5SUM
0150 # BUILD will set the PATH entry to the path to the dataset used
0151 # for the build of Geant4.
0152 #
0153 # INSTALL will set the PATH entry to the path to the dataset used
0154 # by an install of Geant4.
0155 #
0156 #
0157 function(geant4_export_datasets _type _output)
0158 geant4_get_datasetnames(_names)
0159 set(_tmplist)
0160
0161 foreach(_ds ${_names})
0162 set(_tuple ${_ds})
0163 get_property(_tmpprop GLOBAL PROPERTY ${_ds}_ENVVAR)
0164 list(APPEND _tuple ${_tmpprop})
0165
0166 if(${_type} STREQUAL "BUILD")
0167 get_property(_tmpprop GLOBAL PROPERTY ${_ds}_BUILD_DIR)
0168 elseif(${_type} STREQUAL "INSTALL")
0169 get_property(_tmpprop GLOBAL PROPERTY ${_ds}_INSTALL_DIR)
0170 else()
0171 message(FATAL_ERROR "incorrect argument to geant4_export_datasets")
0172 endif()
0173 # Ensure CMake paths
0174 file(TO_CMAKE_PATH "${_tmpprop}" _tmpprop)
0175 list(APPEND _tuple ${_tmpprop})
0176
0177 get_property(_fname GLOBAL PROPERTY ${_ds}_FILENAME)
0178 get_property(_fvers GLOBAL PROPERTY ${_ds}_VERSION)
0179 get_property(_fextn GLOBAL PROPERTY ${_ds}_EXTENSION)
0180 list(APPEND _tuple "${_fname}.${_fvers}.${_fextn}")
0181
0182 get_property(_tmpprop GLOBAL PROPERTY ${_ds}_MD5SUM)
0183 list(APPEND _tuple ${_tmpprop})
0184
0185 # Because we have paths, use tuple separator that should not
0186 # appear in a path.
0187 string(REPLACE ";" "|" _tuple "${_tuple}")
0188 list(APPEND _tmplist "${_tuple}")
0189 endforeach()
0190
0191 set(${_output} ${_tmplist} PARENT_SCOPE)
0192 endfunction()
0193
0194 #-----------------------------------------------------------------------
0195 # function geant4_add_dataset(NAME <id>
0196 # VERSION <ver>
0197 # FILENAME <file>
0198 # EXTENSION <ext>
0199 # ENVVAR <varname>
0200 # MD5SUM <md5>)
0201 # Define a new dataset with the following properties
0202 # NAME common name of the dataset
0203 # VERSION dataset version
0204 # FILENAME name of packaged dataset file
0205 # EXTENSION extension of packaged dataset file
0206 # ENVVAR environment variable used by Geant4 code
0207 # to locate this dataset
0208 # MD5SUM MD5 hash of packaged dataset file
0209 #
0210 function(geant4_add_dataset)
0211 # - Parse arguments and create variables
0212 set(oneValueArgs NAME VERSION FILENAME EXTENSION ENVVAR MD5SUM)
0213 cmake_parse_arguments(_G4ADDDATA "" "${oneValueArgs}" "" ${ARGN})
0214
0215 # - Fail if already defined
0216 geant4_has_dataset(${_G4ADDDATA_NAME} _dsexists)
0217 if(_dsexists)
0218 message(FATAL_ERROR "Dataset ${_G4ADDDATA_NAME} is already defined")
0219 endif()
0220
0221 # - Set properties as global props <NAME>_<PROP>
0222 # Simple properties...
0223 foreach(_prop VERSION FILENAME EXTENSION ENVVAR MD5SUM)
0224 set_property(GLOBAL PROPERTY ${_G4ADDDATA_NAME}_${_prop} ${_G4ADDDATA_${_prop}})
0225 endforeach()
0226
0227 # Derived properties...
0228 # FILE : the full filename of the packed dataset
0229 set_property(GLOBAL PROPERTY ${_G4ADDDATA_NAME}_FILE
0230 "${_G4ADDDATA_FILENAME}.${_G4ADDDATA_VERSION}.${_G4ADDDATA_EXTENSION}"
0231 )
0232 # DIRECTORY : the name of the directory that results from unpacking
0233 # the packed dataset file.
0234 set_property(GLOBAL PROPERTY ${_G4ADDDATA_NAME}_DIRECTORY
0235 "${_G4ADDDATA_NAME}${_G4ADDDATA_VERSION}"
0236 )
0237 # URL : remote and full URL to the packed dataset file
0238 set_property(GLOBAL PROPERTY ${_G4ADDDATA_NAME}_URL
0239 "${GEANT4_DATASETS_URL}/${_G4ADDDATA_FILENAME}.${_G4ADDDATA_VERSION}.${_G4ADDDATA_EXTENSION}"
0240 )
0241
0242 # - add it to the list of defined datasets
0243 set_property(GLOBAL APPEND PROPERTY GEANT4_DATASETS ${_G4ADDDATA_NAME})
0244 endfunction()
0245
0246 #-----------------------------------------------------------------------
0247 # function geant4_has_dataset(<name> <output variable>)
0248 # Set output variable to TRUE if the named dataset exists
0249 # in the list of known datasets.
0250 #
0251 function(geant4_has_dataset _name _output)
0252 get_property(_dslist GLOBAL PROPERTY GEANT4_DATASETS)
0253 list(FIND _dslist ${_name} _index)
0254 if(_index GREATER -1)
0255 set(${_output} TRUE PARENT_SCOPE)
0256 else()
0257 set(${_output} FALSE PARENT_SCOPE)
0258 endif()
0259 endfunction()
0260
0261 #-----------------------------------------------------------------------
0262 # function geant4_get_dataset_property(<name> <property> <output variable>)
0263 # Set output variable to value of dataset "name"'s property.
0264 # If property does not exist, then value will be blank.
0265 #
0266 function(geant4_get_dataset_property _name _prop _output)
0267 geant4_has_dataset(${_name} _dsexists)
0268 if(NOT _dsexists)
0269 message(FATAL_ERROR "non-existent dataset ${_name}")
0270 endif()
0271
0272 get_property(_tmp GLOBAL PROPERTY ${_name}_${_prop})
0273 set(${_output} ${_tmp} PARENT_SCOPE)
0274 endfunction()
0275
0276 #-----------------------------------------------------------------------
0277 # function geant4_set_dataset_property(<name> <property> <value>)
0278 # Set value of dataset property to supplied value
0279 #
0280 function(geant4_set_dataset_property _name _prop _value)
0281 geant4_has_dataset(${_name} _dsexists)
0282 if(NOT _dsexists)
0283 message(FATAL_ERROR "non-existent dataset ${_name}")
0284 endif()
0285 set_property(GLOBAL PROPERTY ${_name}_${_prop} "${_value}")
0286 endfunction()
0287
0288 #-----------------------------------------------------------------------
0289 # function geant4_configure_datasets(DESTINATION <dir>
0290 # DOWNLOAD <installmissing>
0291 # TIMEOUT <seconds>
0292 # )
0293 # Perform the actual heavy lifting to configure each declared
0294 # dataset for reuse or download as needed.
0295 #
0296 function(geant4_configure_datasets)
0297 # - Parse arguments and create variables
0298 set(oneValueArgs DESTINATION DOWNLOAD TIMEOUT)
0299 cmake_parse_arguments(_G4CFGDSS "" "${oneValueArgs}" "" ${ARGN})
0300
0301 # - Load configuration
0302 include(${GEANT4_DATASETS_DEFINITIONS})
0303 geant4_get_datasetnames(_dsnames)
0304 set(_notinstalled )
0305
0306 foreach(_ds ${_dsnames})
0307 geant4_dataset_isinstalled(${_ds} "${_G4CFGDSS_DESTINATION}" _installed)
0308 if(NOT _installed AND _G4CFGDSS_DOWNLOAD)
0309 geant4_install_dataset(${_ds} "${_G4CFGDSS_DESTINATION}" ${_G4CFGDSS_TIMEOUT})
0310 else()
0311 geant4_reuse_dataset(${_ds} "${_G4CFGDSS_DESTINATION}" ${_installed})
0312 if(NOT _installed)
0313 list(APPEND _notinstalled ${_ds})
0314 endif()
0315 endif()
0316 endforeach()
0317
0318 # - Produce report on datasets needing manual install, advising
0319 # user on how to handle these.
0320 # Yes, it's long, but at least it's clear :-)
0321 if(_notinstalled)
0322 message(" *WARNING*")
0323 message(" Geant4 has been pre-configured to look for datasets")
0324 message(" in the directory:")
0325 message(" ")
0326 message(" ${_G4CFGDSS_DESTINATION}")
0327 message(" ")
0328 message(" but the following datasets are NOT present on disk at")
0329 message(" that location:")
0330 message(" ")
0331 foreach(_missing ${_notinstalled})
0332 geant4_get_dataset_property(${_missing} VERSION _vers)
0333 message(" ${_missing} (${_vers})")
0334 endforeach()
0335 message(" ")
0336 message(" - If you have access to cvmfs, you can use standard datasets")
0337 message(" by reconfiguring with:")
0338 message(" cmake -DGEANT4_INSTALL_DATADIR=/cvmfs/geant4.cern.ch/share/data <...>")
0339 message(" The variable can also be set in ccmake or cmake-gui.")
0340 message(" - If you want to have these datasets installed by Geant4,")
0341 message(" simply re-run cmake with GEANT4_INSTALL_DATA=ON. This will")
0342 message(" configure the build to download and install these datasets for you.")
0343 message(" For example, use:")
0344 message(" cmake -DGEANT4_INSTALL_DATA=ON <otherargs>")
0345 message(" ")
0346 message(" If you're running on a Windows system, this is the best")
0347 message(" solution as CMake will unpack the datasets for you")
0348 message(" without any further software being required")
0349 message(" ")
0350 message(" - Alternatively, you can install these datasets manually")
0351 message(" now or after you have installed Geant4. To do this,")
0352 message(" download the following files:")
0353 message(" ")
0354 foreach(_missing ${_notinstalled})
0355 geant4_get_dataset_property(${_missing} URL _url)
0356 message(" ${_url}")
0357 endforeach()
0358 message(" ")
0359 message(" and unpack them under the directory:")
0360 message(" ")
0361 message(" ${_G4CFGDSS_DESTINATION}")
0362 message(" ")
0363 message(" As we supply the datasets packed in gzipped tar files,")
0364 message(" you will need the 'tar' utility to unpack them.")
0365 message(" ")
0366 message(" Nota bene: Missing datasets will not affect or break")
0367 message(" compilation and installation of the Geant4")
0368 message(" libraries.")
0369 message(" ")
0370 endif()
0371 endfunction()
0372
0373 #-----------------------------------------------------------------------
0374 # function geant4_dataset_isinstalled(<name>
0375 # <root directory>
0376 # <output variable>)
0377 # Check if named dataset is installed under the root directory.
0378 # Set output variable to TRUE if it is, FALSE otherwise.
0379 #
0380 function(geant4_dataset_isinstalled _name _rdirectory _output)
0381 geant4_get_dataset_property(${_name} DIRECTORY _dsdir)
0382 set(_expectedpath ${_rdirectory}/${_dsdir})
0383
0384 if(IS_DIRECTORY ${_expectedpath})
0385 set(${_output} TRUE PARENT_SCOPE)
0386 else()
0387 set(${_output} FALSE PARENT_SCOPE)
0388 endif()
0389 endfunction()
0390
0391 #-----------------------------------------------------------------------
0392 # function geant4_install_dataset(<name> <destination> <timeout>)
0393 # Download dataset with name to build directory, timing out the
0394 # download after timeout seconds, and install it
0395 # into its directory under the destination directory.
0396 #
0397 function(geant4_install_dataset _name _destination _timeout)
0398 # - Extract needed dataset properties
0399 geant4_get_dataset_property(${_name} DIRECTORY _ds_dir)
0400 geant4_get_dataset_property(${_name} VERSION _ds_version)
0401 geant4_get_dataset_property(${_name} URL _ds_url)
0402 geant4_get_dataset_property(${_name} MD5SUM _ds_md5sum)
0403
0404 message(STATUS "Configuring download of missing dataset ${_name} (${_ds_version})")
0405
0406 # - Dispatch to ExternalProject
0407 include(ExternalProject)
0408
0409 # - We want to retain timestamps in extracted archives as the data files
0410 # are "constants". CMake >= 3.24 changed this behaviour, so we setup
0411 # ExternalProject based on running version
0412 set(__ep_extract_timestamp_arg )
0413 if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24)
0414 set(__ep_extract_timestamp_arg DOWNLOAD_EXTRACT_TIMESTAMP TRUE)
0415 endif()
0416
0417 ExternalProject_add(${_name}
0418 PREFIX Externals/${_name}-${_ds_version}
0419 SOURCE_DIR ${GEANT4_BUILD_FULL_DATADIR}/${_ds_dir}
0420 URL ${_ds_url}
0421 URL_MD5 ${_ds_md5sum}
0422 TIMEOUT ${_timeout}
0423 ${__ep_extract_timestamp_arg}
0424 CONFIGURE_COMMAND ""
0425 BUILD_COMMAND ""
0426 INSTALL_COMMAND "")
0427
0428 # - Configure the dataset's build and install locations
0429 geant4_set_dataset_property(${_name} BUILD_DIR "${PROJECT_BINARY_DIR}/data/${_ds_dir}")
0430 geant4_set_dataset_property(${_name} INSTALL_DIR "${_destination}/${_ds_dir}")
0431
0432 # - Add install target, and report back paths...
0433 install(DIRECTORY ${PROJECT_BINARY_DIR}/data/${_ds_dir}
0434 DESTINATION ${_destination}
0435 COMPONENT Data
0436 )
0437 endfunction()
0438
0439 #-----------------------------------------------------------------------
0440 # function geant4_reuse_dataset(<name> <destination> <is installed>)
0441 # Reuse the dataset with name located at destination directory.
0442 # If it is not installed, warn user that it will need installing
0443 # manually in destination.
0444 #
0445 function(geant4_reuse_dataset _name _destination _ispresent)
0446 geant4_get_dataset_property(${_name} VERSION _ds_ver)
0447 geant4_get_dataset_property(${_name} DIRECTORY _ds_dir)
0448 if(_ispresent)
0449 message(STATUS "Reusing dataset ${_name} (${_ds_ver})")
0450 else()
0451 message(STATUS "Pre-configuring dataset ${_name} (${_ds_ver})")
0452 endif()
0453
0454 # - In both cases, the build and install dirs are identical
0455 geant4_set_dataset_property(${_name} BUILD_DIR "${_destination}/${_ds_dir}")
0456 geant4_set_dataset_property(${_name} INSTALL_DIR "${_destination}/${_ds_dir}")
0457 endfunction()
0458
0459 #-----------------------------------------------------------------------
0460 # GEANT4 PHYSICS DATA - USER INTERFACE AND PROCESSING
0461 #-----------------------------------------------------------------------
0462 # User options for installing data
0463 # - Choose a directory under which to install the data.
0464 # - Choose whether to download and install missing datasets.
0465 # - Change download timeout for problematic connections
0466 #-----------------------------------------------------------------------
0467 # Choose Physics Data Install Dir
0468 # This follows the pattern for interface and setting as in GNUInstallDirs
0469 if(NOT GEANT4_INSTALL_DATADIR)
0470 set(GEANT4_INSTALL_DATADIR "" CACHE PATH "read-only architecture independent Geant4 physics data (DATADIR/data")
0471 set(GEANT4_INSTALL_DATADIR "${GEANT4_INSTALL_DATADIR_DEFAULT}")
0472 endif()
0473
0474 if(NOT IS_ABSOLUTE ${GEANT4_INSTALL_DATADIR})
0475 set(GEANT4_INSTALL_FULL_DATADIR "${CMAKE_INSTALL_PREFIX}/${GEANT4_INSTALL_DATADIR}")
0476 else()
0477 set(GEANT4_INSTALL_FULL_DATADIR "${GEANT4_INSTALL_DATADIR}")
0478 endif()
0479
0480 #-----------------------------------------------------------------------
0481 # Select whether to download and install missing datasets
0482 option(GEANT4_INSTALL_DATA "Download/Install datasets missing from GEANT4_INSTALL_DATADIR" OFF)
0483
0484 #-----------------------------------------------------------------------
0485 # Provide an option for increasing the download timeout
0486 # Helps with large datasets over slow connections.
0487 set(GEANT4_INSTALL_DATA_TIMEOUT 1500 CACHE STRING "Timeout for Data Library downloads")
0488 mark_as_advanced(GEANT4_INSTALL_DATA_TIMEOUT)
0489
0490 #-----------------------------------------------------------------------
0491 # Set up check, download and install of needed data
0492 #
0493 geant4_configure_datasets(
0494 DESTINATION ${GEANT4_INSTALL_FULL_DATADIR}
0495 DOWNLOAD ${GEANT4_INSTALL_DATA}
0496 TIMEOUT ${GEANT4_INSTALL_DATA_TIMEOUT}
0497 )
0498