ExternalProject: Work around delayed directory removal on Windows
Address the race condition on Windows which occurs when creating a local build tree within ExternalProject.cmake .
Issue 19580 - Windows: Directory removal sometimes fails
Original (v3.18) Command:
file(REMOVE_RECURSE \${directory})
Documented Workaround is better but still unreliable.
Workaround edition:
file(RENAME \"\${directory}\" \"\${directory}.to_delete\")
file(REMOVE_RECURSE \"\${directory}.to_delete\")
The addition of several wait to completion loops, and one rename retry loop,
are redundant in small projects but necessary to support large projects,
potentially accessed across Network Attached Storage (NAS). These loops add
minimal overhead if the command has already completed.
[All feedback is welcome]
Relates #19580
Edited by Craig Scott