file(GET_RUNTIME_DEPENDENCIES...) regex back-/forward-slash and capitalisation sensitivity on Windows
I've hit a couple of issues with regexes and file(GET_RUNTIME_DEPENDENCIES...)
on Windows... Some of these might overlap with #22551.
My basic problem is that it is (very) non-trivial to effectively write the following code:
list(APPEND POST_EXCLUDE_GLOB "$ENV{windir}/**/*") # Ignore everything in the windows directory and below
With some of the changes I suggest below, we might be able to at least do the following:
file(TO_CMAKE_PATH "$ENV{windir}" _windir) # "Normalise" backslashes
string(TOLOWER "${_windir}" _windir) # "Normalise" to lowercase
string(REGEX REPLACE "([][+.()^$/\\?*])" "\\\\\\1" _windirRegex "${_windir}") # Convert to regex
list(APPEND POST_EXCLUDE_REGEX "^${_windirRegex}")
The main problem is that the lack of normalisation of the inputs to the regexs makes generating regexes from (possibly external) inputs very non-trivial. More specifically:
- The results of the dependency search is a path with a mix of forward and back-slashes (eg.
C:\WINDOWS\system32/advapi32.dll;C:\WINDOWS\system32/bcrypt.dll
). These paths could probably afford to be normalised with something likefile(TO_CMAKE_PATH)
before being passed through toPOST_XXX_REGEX
to allow the regexes to be written assuming forward slashes. - The documentation states that only the filename portion of the path is converted to lower-case without giving a reason why. Given the case insensitivity of Windows, shouldn't the entire path be converted to lower-case to solve the same problem that the lower-case filename does?
- I notice that my installed DLLs are all lower-case (
qt5core.dll
vsQt5Core.dll
) because I'm populating the install call with the results offile(GET_REQUIRED_DEPENDENCIES...)
. This doesn't really matter on Windows, but perhaps the regex tests should be performed on slash- and capitalisation-"normalised" inputs, with the resulting dependency lists containing the actual file paths without that normalisation having been performed on them. Put another way - the messy details of the implementation probably shouldn't bleed out into the results. If the user wants everything normalised they can easily do it themselves with existing CMake functionality. - It might be nice to have a "verbose" mode that would allow better debugging of the dependency walking process. If the "normalised" inputs to the regexes are different to the resulting dependency lists (as suggested above), this would be critical.
- Generating a regex is non-trivial. Did you consider having a ant-like GLOB pattern matcher instead? We've written our own
GLOB_TO_REGEX
and it makes things much easier (but I'm pretty sure it's broken in many different ways!).
I hope that I've helped identify some useful pain points... Thanks for all your work with this - I much prefer the new approach to the old GetPrerequisites
!