Lancashire survive Middlesex's rescue bid at Lord's to book a One-Day Cup semi-final against Hampshire on Sunday.