From f162426b1429e0a56966a651484f8a97953e02f5 Mon Sep 17 00:00:00 2001 From: Ben Morgan Date: Thu, 22 Feb 2024 18:52:37 +0000 Subject: [PATCH 1/3] Workaround missing G4persistency target bug in Geant4 11.2 Geant4 11.2 split the G4persistency target into subcomponents: - G4mctruth - G4geomtext - G4gdml (optional, only if Geant4 built with GDML support) and so projects use the direct CMake targets will fail to link these versions. A bug fix will be made in Geant4 itself to address this. Workaround issue in Celeritas by translating request for "persistency" target in celeritas_get_g4libs to appropriate underlying targets. Use translation rather than creation of our own imported target to: - avoid possible (albeit unlikely) clashes with other projects that might create the same target. - Reduce dependence on use of Celeritas' FindGeant4 wrapper by downstream projects. --- cmake/CeleritasUtils.cmake | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/cmake/CeleritasUtils.cmake b/cmake/CeleritasUtils.cmake index 7b62bf3ac6..78ab9d4203 100644 --- a/cmake/CeleritasUtils.cmake +++ b/cmake/CeleritasUtils.cmake @@ -646,10 +646,23 @@ function(celeritas_get_g4libs var) foreach(_lib IN LISTS ARGN) set(_lib Geant4::G4${_lib}${_ext}) - if(NOT TARGET "${_lib}") - message(AUTHOR_WARNING "No Geant4 library '${_lib}' exists") + + # Workaround for differing target names in 11.2.0,1 for G4persistency + # We do this here and not in FindGeant4 because we have no + # guarantee projects using Celeritas and Geant4 won't mess with target + # names themselves (and if we had to create a "celeritas::" target, + # we'd still have to specialize here). + if(_lib MATCHES "persistency" AND NOT TARGET "${_lib}") + list(APPEND _result Geant4::G4mctruth${_ext} Geant4::G4geomtext${_ext}) + if(TARGET "Geant4::G4gdml${_ext}") + list(APPEND _result Geant4::G4gdml${_ext}) + endif() else() - list(APPEND _result "${_lib}") + if(NOT TARGET "${_lib}") + message(AUTHOR_WARNING "No Geant4 library '${_lib}' exists") + else() + list(APPEND _result "${_lib}") + endif() endif() endforeach() endif() From fda2efcb3e07166aafc9d165a6495679ca229dba Mon Sep 17 00:00:00 2001 From: Philippe Canal Date: Thu, 22 Feb 2024 13:31:26 -0600 Subject: [PATCH 2/3] Ignore request for G4tasking if G4 11.2+ --- cmake/CeleritasUtils.cmake | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmake/CeleritasUtils.cmake b/cmake/CeleritasUtils.cmake index 78ab9d4203..cfdbe1e572 100644 --- a/cmake/CeleritasUtils.cmake +++ b/cmake/CeleritasUtils.cmake @@ -647,6 +647,10 @@ function(celeritas_get_g4libs var) foreach(_lib IN LISTS ARGN) set(_lib Geant4::G4${_lib}${_ext}) + # Tasking was merged into core management + if(_lib MATCHES "tasking" AND NOT TARGET "${_lib}") + continue() + endif() # Workaround for differing target names in 11.2.0,1 for G4persistency # We do this here and not in FindGeant4 because we have no # guarantee projects using Celeritas and Geant4 won't mess with target From 5d8c27661ba191d2f692273789f253e260329bb4 Mon Sep 17 00:00:00 2001 From: Ben Morgan Date: Fri, 23 Feb 2024 16:42:17 +0000 Subject: [PATCH 3/3] Simplify logic of Geant4 target checking Check obvious case first, then the special cases for persistency and tasking. Post-process list to remove duplicates to avoid ld warnings observed on macOS. --- cmake/CeleritasUtils.cmake | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/cmake/CeleritasUtils.cmake b/cmake/CeleritasUtils.cmake index cfdbe1e572..e78007268d 100644 --- a/cmake/CeleritasUtils.cmake +++ b/cmake/CeleritasUtils.cmake @@ -644,31 +644,30 @@ function(celeritas_get_g4libs var) set(_ext "-static") endif() - foreach(_lib IN LISTS ARGN) - set(_lib Geant4::G4${_lib}${_ext}) - - # Tasking was merged into core management - if(_lib MATCHES "tasking" AND NOT TARGET "${_lib}") - continue() - endif() - # Workaround for differing target names in 11.2.0,1 for G4persistency - # We do this here and not in FindGeant4 because we have no - # guarantee projects using Celeritas and Geant4 won't mess with target - # names themselves (and if we had to create a "celeritas::" target, - # we'd still have to specialize here). - if(_lib MATCHES "persistency" AND NOT TARGET "${_lib}") + foreach(_shortlib IN LISTS ARGN) + set(_lib Geant4::G4${_shortlib}${_ext}) + if(TARGET "${_lib}") + list(APPEND _result "${_lib}") + elseif(_shortlib STREQUAL "persistency") + # Workaround for differing target names in 11.2.0,1 for G4persistency + # We do this here and not in FindGeant4 because we have no + # guarantee projects using Celeritas and Geant4 won't mess with target + # names themselves (and if we had to create a "celeritas::" target, + # we'd still have to specialize here). list(APPEND _result Geant4::G4mctruth${_ext} Geant4::G4geomtext${_ext}) if(TARGET "Geant4::G4gdml${_ext}") list(APPEND _result Geant4::G4gdml${_ext}) endif() + elseif(_shortlib STREQUAL "tasking") + # Same workaround for tasking, which was split between G4global and G4run + # from 11.1 + list(APPEND _result Geant4::G4run${_ext} Geant4::G4global${_ext}) else() - if(NOT TARGET "${_lib}") - message(AUTHOR_WARNING "No Geant4 library '${_lib}' exists") - else() - list(APPEND _result "${_lib}") - endif() + message(AUTHOR_WARNING "No Geant4 library '${_lib}' exists") endif() endforeach() + # This avoids "ld: warning: ignoring duplicate libraries:" + list(REMOVE_DUPLICATES _result) endif() set(${var} "${_result}" PARENT_SCOPE) endfunction()