This is a followup to #25188 that I thought was worth doing while fixing that issue. However, since it's not strictly needed for the fix I'll make it a separate ticket.
Depends on #25188
CC: @vbraun
Component: build
Author: Erik Bray
Reviewer: Dima Pasechnik
Issue created by migration from https://trac.sagemath.org/ticket/25198