# How to disable system directory search for file(GET\_RUNTIME\_DEPENDENCIES

**URL:** https://discourse.cmake.org/t/how-to-disable-system-directory-search-for-file-get-runtime-dependencies/2014
**Category:** Code
**Tags:** os:windows, comp:msvc
**Created:** [October 16, 2020, 6:25pm UTC](https://discourse.cmake.org/t/how-to-disable-system-directory-search-for-file-get-runtime-dependencies/2014 "2020-10-16T18:25:24Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Warmyone](https://discourse.cmake.org/user_avatar/discourse.cmake.org/warmyone/32/1648_2.png) [@Warmyone](https://discourse.cmake.org/u/Warmyone)
#### Post date: [October 16, 2020, 6:25pm UTC](https://discourse.cmake.org/t/how-to-disable-system-directory-search-for-file-get-runtime-dependencies/2014/1 "2020-10-16T18:25:24Z")

</div>

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](https://discourse.cmake.org/t/get-runtime-dependencies-has-difficulties-with-windows-api-sets/1768)

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 25, 2020, 12:08am UTC](https://discourse.cmake.org/t/how-to-disable-system-directory-search-for-file-get-runtime-dependencies/2014/2 "2020-11-25T00:08:01Z")

</div>

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

---

<div class="post-metadata">

### Author: ![jpfeuffer](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jpfeuffer/32/1529_2.png) [@jpfeuffer](https://discourse.cmake.org/u/jpfeuffer)
#### Post date: [January 12, 2023, 4:59pm UTC](https://discourse.cmake.org/t/how-to-disable-system-directory-search-for-file-get-runtime-dependencies/2014/3 "2023-01-12T16:59:21Z")

</div>

Hi!

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

---

<div class="post-metadata">

### Author: ![emaschino](https://discourse.cmake.org/user_avatar/discourse.cmake.org/emaschino/32/6126_2.png) [@emaschino](https://discourse.cmake.org/u/emaschino)
#### Post date: [May 31, 2024, 10:18am UTC](https://discourse.cmake.org/t/how-to-disable-system-directory-search-for-file-get-runtime-dependencies/2014/4 "2024-05-31T10:18:20Z")

</div>

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.
