# sets the rpath for the Heffte target
get_target_property(_heffte_list Heffte LINK_LIBRARIES)
foreach(_heffte_target ${_heffte_list})
    if (TARGET ${_heffte_target})
        get_target_property(_heffte_target_list ${_heffte_target} INTERFACE_LINK_LIBRARIES)
        foreach(_heffte_subtarget ${_heffte_target_list})
            get_filename_component(_heffte_libpath ${_heffte_subtarget} DIRECTORY)
            if (EXISTS "${_heffte_libpath}")
                list(APPEND _heffte_rpath ${_heffte_libpath})
            endif()
        endforeach()
    elseif(EXISTS ${_heffte_target}) # some vars are neither targets nor files
        get_filename_component(_heffte_libpath ${_heffte_target} DIRECTORY)
        list(APPEND _heffte_rpath ${_heffte_libpath})
    endif()
endforeach()
if (_heffte_rpath)
    list(REMOVE_DUPLICATES _heffte_rpath)
    message(STATUS "Setting Heffte INSTALL_RPATH = ${_heffte_rpath}")
    set_target_properties(Heffte PROPERTIES INSTALL_RPATH "${_heffte_rpath}")
endif()
unset(_heffte_list)
unset(_heffte_target_list)
unset(_heffte_target)
unset(_heffte_subtarget)
unset(_heffte_rpath)
unset(_heffte_libpath)

