4242# then the module will issue a FATAL_ERROR if this build of Geant4 does
4343# not have the requested component(s).
4444#
45- # The list of components available generally corresponds to the optional
46- # extras that Geant4 can be built with and are:
47- #
48- # multithreaded (Libraries built with multithreading support)
49- #
45+ # The components available generally correspond to configurations of
46+ # the Geant4 libraries or optional extras that Geant4 can be built with.
47+ #
48+ # Library Configuration
49+ # ---------------------
50+ # static (Static libraries available. Using this component
51+ # when static libraries are available will result in
52+ # Geant4_LIBRARIES being populated with the static
53+ # versions of the Geant4 libraries. It does not
54+ # guarantee the use of static third party libraries.)
55+ # multithreaded (Libraries have multithreading support. Using this
56+ # component will add the compiler definitions needed
57+ # to activate multithread mode to Geant4_DEFINITIONS,
58+ # if the libraries support it.)
59+ #
60+ # Optional Components
61+ # -------------------
5062# gdml (GDML support)
5163# g3tog4 (Geant3 geometry call list reader library)
5264#
7486# argument is set. This is because these options do not depend on specific
7587# components being available.
7688#
77- # You can also query Geant4's use, or otherwise, of its builtin versions
89+ # You can also query whether the Geant4 found uses the builtin versions
7890# of CLHEP, ZLIB and Expat after calling find_package via the variables
7991#
8092# Geant4_builtin_clhep_FOUND (TRUE if Geant4 built with internal CLHEP)
91103# system APIs as required, and you should use these to ensure you compile
92104# and link against the same API version.
93105#
94- # Environment variables for and directory paths to physics datasets
106+ # Environment variables for, and directory paths to, physics datasets
95107# used by some Geant4 physics processes may be determined from the
96108# variables
97109#
98110# Geant4_DATASETS (List of dataset names known to Geant4)
99111# Geant4_DATASET_<NAME>_ENVVAR (Name of environment variable used by
100- # Geant4 to query for path to dataset
112+ # Geant4 to obtain path to dataset
101113# <NAME>)
102114# Geant4_DATASET_<NAME>_PATH (Path to dataset <NAME>. NB this may
103115# point to a non-existent path if Geant4
@@ -440,19 +452,24 @@ endif()
440452
441453#-----------------------------------------------------------------------
442454# Now perform final configuration of libraries...
443- # We provide FOUND variables for shared and static but for now we don't
444- # allow users to choose - we prefer shared if available, and fallback to
445- # static otherwise
446- #
455+ # We provide FOUND variables for presence of shared and static
456+ # User can supply "static" component to force use of static libraries, if
457+ # available.
447458set (Geant4_shared_FOUND @BUILD_SHARED_LIBS @)
448459set (Geant4_static_FOUND @BUILD_STATIC_LIBS@)
449460
461+ # - Default setting : shared if available, static otherwise
450462if (Geant4_shared_FOUND)
451463 set (_geant4_lib_use_suffix "" )
452464else ()
453465 set (_geant4_lib_use_suffix "-static" )
454466endif ()
455467
468+ if (Geant4_FIND_REQUIRED_static AND Geant4_static_FOUND)
469+ set (_geant4_lib_use_suffix "-static" )
470+ list (REMOVE_ITEM Geant4_FIND_COMPONENTS static )
471+ endif ()
472+
456473# The list of libraries probably should be autogenerated, but we hard code
457474# for now. We don't have to divide the list of shared libraries, but we
458475# do so for consistency with the way we'll need to do it for static.
@@ -487,6 +504,28 @@ if(_geant4_use_g3tog4_library)
487504 set (_geant4_g3tog4_library G3toG4${_geant4_lib_use_suffix} )
488505endif ()
489506
507+ # - Factory registration mechanism in physics_lists requires whole
508+ # archive to be linked when using static libs, so requires wrapping
509+ # with suitable compiler dependent flags
510+ set (_geant4_physicslists_library G4physicslists${_geant4_lib_use_suffix} )
511+ if (_geant4_lib_use_suffix STREQUAL "-static" )
512+ # - Use CMAKE_CXX_COMPILER_ID, which should be reliable enough...
513+ # Though the GNU/Clang/Intel compilers/linkers *should* use identical
514+ # flags,keep their sections separate until behaviour confirmed
515+ #
516+ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" )
517+ set (_geant4_physicslists_library -Wl,--whole-archive G4physicslists${_geant4_lib_use_suffix} -Wl,--no -whole-archive)
518+ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
519+ set (_geant4_physicslists_library -Wl,-force_load G4physicslists${_geant4_lib_use_suffix} )
520+ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Intel" )
521+ set (_geant4_physicslists_library -Wl,--whole-archive G4physicslists${_geant4_lib_use_suffix} -Wl,--no -whole-archive)
522+ else ()
523+ # Needs determination of other compiler options.
524+ # NB: MSVC has /OPT:NOREF, but may apply globally...
525+ set (_geant4_physicslists_library G4physicslists${_geant4_lib_use_suffix} )
526+ endif ()
527+ endif ()
528+
490529# - 'Kernel' libraries
491530list (APPEND _geant4_internal_libraries
492531 G4vis_management${_geant4_lib_use_suffix}
@@ -497,7 +536,7 @@ list(APPEND _geant4_internal_libraries
497536 G4analysis${_geant4_lib_use_suffix}
498537 G4error_propagation${_geant4_lib_use_suffix}
499538 G4readout${_geant4_lib_use_suffix}
500- G4physicslists ${_geant4_lib_use_suffix }
539+ ${_geant4_physicslists_library }
501540 G4run${_geant4_lib_use_suffix}
502541 G4event${_geant4_lib_use_suffix}
503542 G4tracking${_geant4_lib_use_suffix}
0 commit comments