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 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user