From a53b3051de51d801debcb6381a9549d8401163f0 Mon Sep 17 00:00:00 2001 From: AndreaRigoni Date: Fri, 3 Apr 2026 08:41:00 +0000 Subject: [PATCH] fix EXPAT::EXPAT-NOTFOUND when building with Geant4 on conda Geant4's G4EXPATShim creates EXPAT::EXPAT (uppercase) with IMPORTED_LOCATION set to ${EXPAT_LIBRARY}, which is empty when EXPAT is found via conda's config-mode package (expat::expat, lowercase). After find_package(Geant4), patch EXPAT::EXPAT with the real library path taken from expat::expat IMPORTED_LOCATION_NOCONFIG, falling back to find_library if needed. Co-Authored-By: Claude Sonnet 4.6 --- CMakeLists.txt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index c6e0d82..b288747 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -169,6 +169,26 @@ if(Geant4_FOUND) add_compile_definitions(HAVE_GEANT4) set(HAVE_GEANT4 1) + # Workaround: Geant4's G4EXPATShim creates EXPAT::EXPAT (uppercase) with + # IMPORTED_LOCATION "${EXPAT_LIBRARY}", but EXPAT_LIBRARY is empty when using + # conda's config-mode expat package (which installs as expat::expat lowercase). + # Resolve the actual library path from expat::expat or via find_library. + if(TARGET EXPAT::EXPAT) + get_target_property(_expat_loc EXPAT::EXPAT IMPORTED_LOCATION) + if(NOT _expat_loc OR _expat_loc MATCHES "NOTFOUND|^$") + if(TARGET expat::expat) + get_target_property(_expat_loc expat::expat IMPORTED_LOCATION_NOCONFIG) + endif() + if(NOT _expat_loc OR _expat_loc MATCHES "NOTFOUND|^$") + find_library(_expat_loc NAMES expat) + endif() + if(_expat_loc) + set_target_properties(EXPAT::EXPAT PROPERTIES IMPORTED_LOCATION "${_expat_loc}") + endif() + endif() + unset(_expat_loc) + endif() + # Sanitize Geant4 targets to remove Qt5 dependencies that conflict with VTK/Qt6 if(TARGET Geant4::G4interfaces) set_target_properties(Geant4::G4interfaces PROPERTIES