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