Import Geant4 11.4.0 source tree

This commit is contained in:
Gabriele Cosmo
2025-12-05 08:54:02 +01:00
parent a499fb82e9
commit b4a16de652
6484 changed files with 232674 additions and 221097 deletions
+19
View File
@@ -284,6 +284,25 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|.*Clang")
endif()
endif()
#.rst:
# - ``GEANT4_BUILD_XCODE_WARNINGS``
# - Build libraries on macOS command line with extended warnings from Xcode
if(APPLE AND
(NOT CMAKE_GENERATOR STREQUAL "Xcode") AND
(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang"))
set(__geant4_appleclang_additional "-Wshorten-64-to-32")
option(GEANT4_BUILD_XCODE_WARNINGS "Enable additional warnings used by Xcode when building with Command Line Tools")
geant4_add_feature(GEANT4_BUILD_XCODE_WARNINGS "Compiling Geant4 with additional warnings '${__geant4_appleclang_additional}'")
mark_as_advanced(GEANT4_BUILD_XCODE_WARNINGS)
if(GEANT4_BUILD_XCODE_WARNINGS)
string(APPEND CMAKE_CXX_FLAGS " ${__geant4_appleclang_additional}")
endif()
endif()
#.rst:
# - ``GEANT4_BUILD_ENABLE_ASSERTIONS``
# - Build libraries with assertions enabled even in release build types (Release, RelWithDebInfo, MinSizeRel)
-158
View File
@@ -1,158 +0,0 @@
#.rst
# G4ClangFormat
# =============
#
# Functions and helper targets for formatting sources of a target using
# clang-format
# - Include guard
include_guard(DIRECTORY)
# Default logging directory
set(G4FORMAT_LOGDIR ${PROJECT_BINARY_DIR}/format CACHE PATH
"Output folder of files that are formatted")
# Find clang-format (optional)
find_program(CLANG_FORMATTER NAMES
clang-format-6 # prefer clang-format version 6.0
clang-format-6.0
clang-format-mp-6.0 # Apple macports version
clang-format)
function(exclude_from_format)
cmake_parse_arguments(ARG "" "" "HEADERS;SOURCES;FILES" ${ARGN})
function(_add_labels _path)
foreach(_FILE ${ARGN})
if(NOT IS_ABSOLUTE ${_FILE})
set(_FILE ${CMAKE_CURRENT_LIST_DIR}${_path}/${_FILE})
endif()
set(_LABELS "EXCLUDE_FORMAT")
get_source_file_property(_EXISTING_LABELS ${_FILE} LABELS)
if(_EXISTING_LABELS)
list(APPEND _LABELS ${_EXISTING_LABELS})
endif()
set_source_files_properties(${_FILE} PROPERTIES LABELS "${_LABELS}")
get_source_file_property(_EXISTING_LABELS ${_FILE} LABELS)
endforeach()
endfunction()
_add_labels("/include" ${ARG_HEADERS})
_add_labels("/src" ${ARG_SOURCES})
_add_labels("" ${ARG_FILES})
endfunction()
#------------------------------------------------------------------------------#
function(create_format_directory)
if(NOT EXISTS ${G4FORMAT_LOGDIR})
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${G4FORMAT_LOGDIR})
endif()
endfunction()
#------------------------------------------------------------------------------#
function(geant4_format_target)
if(NOT CLANG_FORMATTER)
return()
endif()
cmake_parse_arguments(G4FMTTARGET "" "NAME" "SOURCES" ${ARGN})
string(REGEX REPLACE "-format$" "" G4TARGET_NAME "${G4FMTTARGET_NAME}")
# ensure not empty list
if("${G4FMTTARGET_SOURCES}" STREQUAL "")
return()
endif()
# create output directory
create_format_directory()
set(SOURCES ) # list of sources
set(FILELOG ) # string of sources (for log)
foreach(_SOURCE ${G4FMTTARGET_SOURCES})
# files in binary directory are almost always generated files
string(FIND "${_SOURCE}" "${PROJECT_BINARY_DIR}" IN_BINARY_DIR)
# ignore generated files
if(IN_BINARY_DIR GREATER -1)
continue()
endif()
# check if exists (valid full path)
if(EXISTS "${_SOURCE}")
# do nothing -- absolute path was specified
elseif(EXISTS "${CMAKE_CURRENT_LIST_DIR}/${_SOURCE}")
# a relative path was specified
set(_SOURCE ${CMAKE_CURRENT_LIST_DIR}/${_SOURCE})
else()
# neither relative nor absolute
message(STATUS "[format] file not found: '${_SOURCE}'")
continue()
endif()
#string(REPLACE "${PROJECT_SOURCE_DIR}/" "" _SOURCE ${_SOURCE})
get_source_file_property(SOURCE_LABELS ${_SOURCE} LABELS)
list(FIND SOURCE_LABELS "EXCLUDE_FORMAT" EXCLUDE_FORMAT)
if(EXCLUDE_FORMAT GREATER -1)
continue()
endif()
# append to log
set(FILELOG "${FILELOG}${_SOURCE}\n")
# add to list to be processed
list(APPEND SOURCES ${_SOURCE})
endforeach()
# write format file
set(FMTLOG_OUT ${G4FORMAT_LOGDIR}/${G4TARGET_NAME}.txt)
file(WRITE ${FMTLOG_OUT} "${FILELOG}")
file(RELATIVE_PATH FMTLOG_RELATIVE_OUT ${PROJECT_BINARY_DIR} ${FMTLOG_OUT})
# get the number of source files
list(LENGTH SOURCES NUM_SOURCES)
# if there are too many source files (arguments), command will fail
# so process no more than 500 at a time
if(NUM_SOURCES GREATER 500)
# function to generate indices
function(generate_indices VAR NUM)
set(INDICES )
set(N 0)
while(N LESS NUM)
list(APPEND INDICES ${N})
math(EXPR N "${N}+1")
endwhile()
set(${VAR} ${INDICES} PARENT_SCOPE)
endfunction()
# generate 500 indices
generate_indices(INDICES 500)
set(FORMAT_COMMANDS )
# while there are still sources in list
while(NUM_SOURCES GREATER 0)
# if below 500, re-generate indices
if(NUM_SOURCES LESS 500)
generate_indices(INDICES ${NUM_SOURCES})
endif()
# get the subset of first 500
list(GET SOURCES ${INDICES} SOURCES_SUBSET)
# add the target for block of 500
list(APPEND FORMAT_COMMANDS COMMAND ${CLANG_FORMATTER} -i ${SOURCES_SUBSET})
# remove 500 we just processed
list(REMOVE_AT SOURCES ${INDICES})
# update the number of sources remaining
list(LENGTH SOURCES NUM_SOURCES)
endwhile()
# add the custom command
list(LENGTH FORMAT_COMMANDS NUM_COMMANDS)
if(NUM_COMMANDS GREATER 0)
add_custom_target(${G4FMTTARGET_NAME}
${FORMAT_COMMANDS}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMENT "Running '${CLANG_FORMATTER}' on source files in '${G4TARGET_NAME}' target (see ${FMTLOG_RELATIVE_OUT})...")
endif()
else()
list(LENGTH SOURCES NUM_SOURCES)
if(NUM_SOURCES GREATER 0)
# if less than 500 source files, add all in one target
add_custom_target(${G4FMTTARGET_NAME}
COMMAND ${CLANG_FORMATTER} -i ${SOURCES}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMENT
"Running '${CLANG_FORMATTER}' on source files in '${G4TARGET_NAME}' target (see ${FMTLOG_RELATIVE_OUT})...")
endif()
endif(NUM_SOURCES GREATER 500)
endfunction()
@@ -269,13 +269,6 @@ if(NOT GEANT4_BUILD_GRANULAR_LIBS)
set(G4_BUILTWITH_QT "no")
endif()
# - QT3D
if(GEANT4_USE_QT3D)
set(G4_BUILTWITH_QT3D "yes")
else()
set(G4_BUILTWITH_QT3D "no")
endif()
# - Motif
if(GEANT4_USE_XM)
set(G4_BUILTWITH_MOTIF "yes")
+10 -10
View File
@@ -18,21 +18,21 @@ geant4_add_dataset(
# - Low energy electromagnetics
geant4_add_dataset(
NAME G4EMLOW
VERSION 8.7
VERSION 8.8
FILENAME G4EMLOW
EXTENSION tar.gz
ENVVAR G4LEDATA
MD5SUM 949c9422ae668208562be1b991750df1
MD5SUM 328330009df633f7e9b3a9f445745298
)
# - Photon evaporation
geant4_add_dataset(
NAME PhotonEvaporation
VERSION 6.1
VERSION 6.1.2
FILENAME G4PhotonEvaporation
EXTENSION tar.gz
ENVVAR G4LEVELGAMMADATA
MD5SUM 92d68b937cdad0fd49892a66878863de
MD5SUM d80ba9bdefcf9e23487a26adfa273304
)
# - Radioisotopes
@@ -48,11 +48,11 @@ geant4_add_dataset(
# - Particle XS - replaces Neutron XS
geant4_add_dataset(
NAME G4PARTICLEXS
VERSION 4.1
VERSION 4.2
FILENAME G4PARTICLEXS
EXTENSION tar.gz
ENVVAR G4PARTICLEXSDATA
MD5SUM 878252a464ba6b38f085741840f053e6
MD5SUM b63341cc97a472b04ff607b094493174
)
# - PII
@@ -99,11 +99,11 @@ geant4_add_dataset(
# - INCL
geant4_add_dataset(
NAME G4INCL
VERSION 1.2
VERSION 1.3
FILENAME G4INCL
EXTENSION tar.gz
ENVVAR G4INCLDATA
MD5SUM 0a76df936839bb557dae7254117eb58e
MD5SUM 72c3ff5f7f1e6f727f2ebf3b11ce784f
)
# - ENSDFSTATE
@@ -119,11 +119,11 @@ geant4_add_dataset(
# - Channeling
geant4_add_dataset(
NAME G4CHANNELING
VERSION 1.0
VERSION 2.0
FILENAME G4CHANNELING
EXTENSION tar.gz
ENVVAR G4CHANNELINGDATA
MD5SUM b2f692ec7109418c6354ea1ecbc62da7
MD5SUM e853fbcba1e8640f7c3a437253955482
)
# - TENDL
+90 -9
View File
@@ -497,10 +497,11 @@ endfunction()
#
# .. code-block:: cmake
#
# geant4_add_category(<name> MODULES <module> [<module> ...])
# geant4_add_category(<name> [INTERFACE] [MODULES <module> [<module> ...]])
#
# Add a Geant4 category ``<name>`` to the project, composed of the modules
# supplied in the ``MODULES`` list.
# Add a Geant4 category ``<name>`` to the project. It can be composed from modules
# supplied in the ``MODULES`` list, or the ``INTERFACE`` option can be used
# to create an alias to one or more other categories.
#
# Calling this function does not create an actual CMake library target.
# Because modules declare dependencies on modules rather than libraries, we
@@ -512,12 +513,23 @@ function(geant4_add_category _name)
__geant4_category_assert_not_exists(${_name})
set_property(GLOBAL APPEND PROPERTY GEANT4_DEFINED_CATEGORIES ${_name})
cmake_parse_arguments(G4ADDCAT
""
"INTERFACE"
""
"MODULES"
${ARGN}
)
# - Modules must not be empty (Could also just be ARGN)
# INTERFACE/MODULES are mutually exclusive
if(G4ADDCAT_INTERFACE AND G4ADDCAT_MODULES)
message(FATAL_ERROR "geant4_add_category: INTERFACE and MODULES arguments are mutually exclusive")
endif()
if(G4ADDCAT_INTERFACE)
geant4_set_category_property(${_name} PROPERTY IS_ALIAS TRUE)
geant4_set_category_property(${_name} PROPERTY CATEGORIES)
return()
endif()
# - Modules must not be empty (Could also just be ARGN)
if(NOT G4ADDCAT_MODULES)
message(FATAL_ERROR "geant4_add_category: Missing/empty 'MODULES' argument")
endif()
@@ -532,6 +544,23 @@ function(geant4_add_category _name)
geant4_set_category_property(${_name} PROPERTY CMAKE_LIST_FILE "${CMAKE_CURRENT_LIST_FILE}")
endfunction()
#-----------------------------------------------------------------------
#.rst:
# .. cmake:command:: geant4_category_is_alias
#
# .. code-block:: cmake
#
# geant4_category_is_alias(<category> <outputvar>)
#
# Set ``outputvar`` to ``TRUE`` if ``<category>`` is an alias to one or
# more others.
#
function(geant4_category_is_alias _outvar _name)
__geant4_category_assert_exists(${_name})
geant4_get_category_property(_result ${_name} IS_ALIAS)
set(${_outvar} ${_result} PARENT_SCOPE)
endfunction()
#-----------------------------------------------------------------------
#.rst:
# .. cmake:command:: geant4_category_modules
@@ -544,6 +573,11 @@ endfunction()
#
function(geant4_category_modules _name)
__geant4_category_assert_exists(${_name})
geant4_category_is_alias(check ${_name})
if(check)
message(FATAL_ERROR "geant4_category_modules: Trying to add modules to ALIAS-type category '${_name}'")
endif()
# ARGN must not be empty
if(NOT ARGN)
message(FATAL_ERROR "no modules given to add to to category '${_name}'")
@@ -575,6 +609,34 @@ function(geant4_category_modules _name)
geant4_set_category_property(${_name} PROPERTY IS_INTERFACE ${__cat_is_interface})
endfunction()
#-----------------------------------------------------------------------
#.rst:
# .. cmake:command:: geant4_category_interfaces
#
# .. code-block:: cmake
#
# geant4_category_interfaces(<category> <cat> [<mat> ...]))
#
# Add categories to alias category ``<category>``
#
function(geant4_category_interfaces _name)
__geant4_category_assert_exists(${_name})
geant4_category_is_alias(check ${_name})
if(NOT check)
message(FATAL_ERROR "geant4_category_modules: Trying to add categories to non-ALIAS category '${_name}'")
endif()
# ARGN must not be empty
if(NOT ARGN)
message(FATAL_ERROR "no categories given to add to to category '${_name}'")
endif()
foreach(iface ${ARGN})
__geant4_category_assert_exists(${iface})
geant4_set_category_property(${_name} APPEND PROPERTY CATEGORIES ${iface})
endforeach()
endfunction()
#-----------------------------------------------------------------------
#.rst:
# .. cmake:command:: geant4_get_categories
@@ -627,6 +689,8 @@ endfunction()
# * ``IS_INTERFACE``
# * ``MODULES``
# * ``PUBLIC_HEADERS``
# * ``IS_ALIAS``
# * ``CATEGORIES``
#
# The properties of a category may be queried and set using the following
# commands.
@@ -1190,7 +1254,7 @@ endmacro()
# This is used internally by the property get/set functions.
#
function(__geant4_category_validate_property _property)
if(NOT (${_property} MATCHES "CMAKE_LIST_FILE|IS_INTERFACE|MODULES|PUBLIC_HEADERS"))
if(NOT (${_property} MATCHES "CMAKE_LIST_FILE|IS_INTERFACE|MODULES|PUBLIC_HEADERS|DEFINE_SYMBOL|IS_ALIAS|CATEGORIES"))
message(FATAL_ERROR "Undefined property '${_property}'")
endif()
endfunction()
@@ -1216,7 +1280,7 @@ function(__geant4_category_reset)
# Reset category properties, then categories
geant4_get_categories(__all_categories)
foreach(__cat ${__all_categories})
foreach(_prop CMAKE_LIST_FILE IS_INTERFACE MODULES PUBLIC_HEADERS)
foreach(_prop CMAKE_LIST_FILE IS_INTERFACE MODULES PUBLIC_HEADERS DEFINE_SYMBOL IS_ALIAS CATEGORIES)
geant4_set_category_property(${__cat} PROPERTY ${_prop})
endforeach()
endforeach()
@@ -1277,10 +1341,11 @@ function(__geant4_add_library _name _type)
message(FATAL_ERROR "Invalid library type '${_type}'")
endif()
# Check if the overall library is binary or header-only
# Check if the overall library is binary, header-only, or an alias (really an interface in CMake terms)
set(_lib_cmake_type ${_type})
geant4_get_category_property(_lib_is_interface ${_name} IS_INTERFACE)
if(_lib_is_interface)
geant4_get_category_property(_lib_is_alias ${_name} IS_ALIAS)
if(_lib_is_interface OR _lib_is_alias)
set(_lib_cmake_type "INTERFACE")
endif()
@@ -1297,6 +1362,16 @@ function(__geant4_add_library _name _type)
if(_lib_cmake_type STREQUAL "INTERFACE")
target_compile_features(${_target_name} INTERFACE ${GEANT4_TARGET_COMPILE_FEATURES})
set(_props_to_process "INTERFACE")
# Shortcut: If this category is also an "alias", we just extract the link interface directly
if(_is_lib_is_alias)
geant4_get_category_property(iface ${_name} CATEGORIES)
if(_type STREQUAL "STATIC")
list(TRANSFORM iface APPEND "-static")
endif()
target_link_libraries(${_target_name} INTERFACE ${iface})
return()
endif()
else()
target_compile_features(${_target_name} PUBLIC ${GEANT4_TARGET_COMPILE_FEATURES})
set(_props_to_process "PUBLIC" "PRIVATE" "INTERFACE")
@@ -1310,6 +1385,12 @@ function(__geant4_add_library _name _type)
target_compile_definitions(${_target_name} PUBLIC G4LIB_BUILD_DLL)
set_target_properties(${_target_name} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
# Check if we have a DEFINE_SYMBOL for this category
geant4_get_category_property(_lib_define_symbol ${_name} DEFINE_SYMBOL)
if(_lib_define_symbol)
set_target_properties(${_target_name} PROPERTIES DEFINE_SYMBOL ${_lib_define_symbol})
endif()
# MacOS
# Use '@rpath' in install names of libraries on macOS to provide relocatibility
# Add '@loader_path' to INSTALL_RPATH on macOS so that Geant4
-34
View File
@@ -194,40 +194,6 @@ if(GEANT4_USE_QT)
get_target_property(QT_QMAKE_EXECUTABLE Qt${QT_VERSION_MAJOR}::qmake IMPORTED_LOCATION)
geant4_add_feature(GEANT4_USE_QT "Build Geant4 with Qt${QT_VERSION_MAJOR} support")
# Qt3D is only supported on 5.15 and above, but always on if available
set(QT3D_MINIMUM_VERSION 5.15.0)
set(GEANT4_USE_QT3D OFF)
if(QT_VERSION VERSION_GREATER_EQUAL QT3D_MINIMUM_VERSION)
find_package(Qt${QT_VERSION_MAJOR}3DCore ${QT_VERSION} EXACT QUIET)
find_package(Qt${QT_VERSION_MAJOR}3DExtras ${QT_VERSION} EXACT QUIET)
find_package(Qt${QT_VERSION_MAJOR}3DRender ${QT_VERSION} EXACT QUIET)
# Forward correct minimum version to CMake/etc files
set(QT3D_MINIMUM_VERSION ${QT_VERSION})
if(Qt${QT_VERSION_MAJOR}3DCore_FOUND AND Qt${QT_VERSION_MAJOR}3DExtras_FOUND AND Qt${QT_VERSION_MAJOR}3DRender_FOUND)
set(GEANT4_USE_QT3D ON)
geant4_save_package_variables(Qt${QT_VERSION_MAJOR}
Qt${QT_VERSION_MAJOR}3DCore_DIR
Qt${QT_VERSION_MAJOR}3DExtras_DIR
Qt${QT_VERSION_MAJOR}3DRender_DIR)
geant4_add_feature(GEANT4_USE_QT3D "Build Geant4 Qt3D driver")
else()
set(_g4_qt3d_missing)
if(NOT Qt${QT_VERSION_MAJOR}3DCore_FOUND)
list(APPEND _g4_qt3d_missing "Qt${QT_VERSION_MAJOR}3DCore")
endif()
if(NOT Qt${QT_VERSION_MAJOR}3DExtras_FOUND)
list(APPEND _g4_qt3d_missing "Qt${QT_VERSION_MAJOR}3DExtras")
endif()
if(NOT Qt${QT_VERSION_MAJOR}3DRender_FOUND)
list(APPEND _g4_qt3d_missing "Qt${QT_VERSION_MAJOR}3DRender")
endif()
message(STATUS "Disabling Geant4 Qt3D driver, missing Qt packages: ${_g4_qt3d_missing}")
endif()
endif()
# Variables for export to GNUmake
execute_process(COMMAND ${QT_QMAKE_EXECUTABLE} -query QT_INSTALL_PREFIX OUTPUT_VARIABLE G4QTHOME OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${QT_QMAKE_EXECUTABLE} -query QT_INSTALL_LIBS OUTPUT_VARIABLE G4QTLIBPATH OUTPUT_STRIP_TRAILING_WHITESPACE)