FetchContent: Avoid writing files and including ExternalProject unnecessarily
After the previous round of performance optimizations in !5749 (merged) and !5774 (merged), the remaining significant contributors to the time taken per call to
FetchContent_MakeAvailable() when no changes are needed became clearer. As mentioned in #21780 (comment 898872), the
configure_file() command writes files even in cases where it ultimately didn't need to. This has a measurable impact on some platforms with relatively slow file systems (notably Windows and VMs). We can do the comparison of file contents directly ourselves and only write files after confirming we actually need to.
A minor contributor but measurable nonetheless was including the
ExternalProject module every time we did a population (i.e. once per dependency). That is no longer necessary since
ExternalProject now doesn't rely on variables and we just need the
_ep_do_preconfigure_steps_now() command to be defined. Including
ExternalProject once when
FetchContent is included saves a small but measurable cost per dependency.
I think this round of changes should conclude my efforts on
FetchContent performance improvement for a while (see #21703 for context). I don't see any more places where we can get useful gains without a lot of work or making things less robust. This last set should get us to a very good place performance-wise anyway.