How to disable system directory search for file(GET_RUNTIME_DEPENDENCIES

We are building an executable with the visual studio compiler.
When deploying we want to include the msvc redist dll’s as customers might not have installed them.
Furthermore, we do not want to use those located in system32 on our CI and developer PC’s but want to use a fetched copy we store in a company repo.

I currently discovered file(GET_RUNTIME_DEPENDENCIES and am able to use it to find and install all but the system DLL’s with the regex: POST_EXCLUDE_REGEXES ".*WINDOWS.system32.*".
Also, I was able to copy the redist DLL’s with the regex: POST_INCLUDE_REGEXES ".*msvcp.*" ".*vccorlib.*" ".*vcruntime.*" ".*concrt.*" ".*ucrtbase.*".

But I cannot find a way to let the tool find the redist DLL’s in the given DIRECTORIES instead of system32.
The search order of the method cannot be changed as far as I can tell, but maybe there is some workaround?

Related: GET_RUNTIME_DEPENDENCIES has difficulties with windows API sets

I think the DIRECTORIES argument should work. I think these are pure fallbacks though and PRE_EXCLUDE will halt searching for the matched DLL. I think you may be able to use the PATH environment variable to influence searching though (by adding your fetched copy path at the beginning) That’s just a Windows thing though.

Cc: @kyle.edwards

1 Like

Hi!

Any update on this? I am trying to do the same. Hacking the PATH variable is not a viable solution for us.

I’m in the same boat.

My Win32 project makes use of ONNX Runtime, found with find_package(onnxruntime) using the ONNX Runtime generated CMake config files.

There’s no problem resolving my project’s runtime dependencies in Debug build where the binaries are postfixed with _d, so there’s no ambiguity resolving onnxruntime_d.dll. However in Release build, the system onnxruntime.dll from C:\Windows\system32 is found rather than the packaged one provided with ONNX Runtime CMake config file. To prevent this, I’ve added POST_EXCLUDE_REGEXES ".*system32/.*\\.dll" to install(RUNTIME_DEPENDENCY_SET but this yields to the cancellation of further onnxruntime.dll lookup, even though the runtime directory provided by ONNX Runtime CMake config file is correctly listed in the DIRECTORIES argument. Playing with the other PRE_INCLUDE_* POST_INCLUDE_* arguments didn’t help. Or I didn’t found the right combination.