# RUNTIME\_DEPENDENCIES

**URL:** https://discourse.cmake.org/t/runtime-dependencies/4497
**Category:** Code
**Created:** [November 17, 2021, 4:38pm UTC](https://discourse.cmake.org/t/runtime-dependencies/4497 "2021-11-17T16:38:53Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Leon0402](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/l/ccd318/32.png) [@Leon0402](https://discourse.cmake.org/u/Leon0402)
#### Post date: [November 17, 2021, 4:38pm UTC](https://discourse.cmake.org/t/runtime-dependencies/4497/1 "2021-11-17T16:38:54Z")

</div>

Hi,

I use RUNTIME\_DEPENDENCIES to copy all dlls. But it doesn’t find all. In particular, it doesn’t find postgresql dlls. They are on my PATH though.

Adding postgreql to the `DIRECTORIES` options gives me the lib directory, but I need the bin directory  
`DIRECTORIES $<TARGET_FILE_DIR:PostgreSQL::PostgreSQL>`

Using `$<TARGET_RUNTIME_DLLS:PostgreSQL::PostgreSQL>` doesn’t work either. FindPostgresql.cmake does set `IMPORTED_LOCATION`, but also sets the target to `UNKNOWN`, so according to the documentation it is not considered.

Questions therefore are:

- Is the PATH not considered by `file(RUNTIME_DEPENDENCIES)`? Can I change it
- Why is the PostgreSQL::PostgreSQL target set to Unknown? Or why is it ignored by `TARGET_RUNTIME_DLLS` even though it has `IMPORTED_LOCATION` set

I could also not generate the RUNTIME\_DEPENDENCIES as they are on the PATH anyway in this case, but how would I ignore all the dlls without listing each explicitly in `POST_EXCLUDE_REGEXES` as Postgresql as many dlls.

---

<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 17, 2021, 7:46pm UTC](https://discourse.cmake.org/t/runtime-dependencies/4497/2 "2021-11-17T19:46:38Z")

</div>

> [@Leon0402](#):
>
> Or why is it ignored by `TARGET_RUNTIME_DLLS` even though it has `IMPORTED_LOCATION` set

On an `UNKNOWN` library, the `IMPORTED_LOCATION` is the `.lib` file, not the DLL. There’s nowhere to put the DLL path on an `UNKNOWN` library. Someday I’d like to get back to [this MR](https://gitlab.kitware.com/cmake/cmake/-/merge_requests/5820) to help reduce the number of `UNKNOWN` imported libraries. The docs were [updated recently](https://gitlab.kitware.com/cmake/cmake/-/merge_requests/6700) to [clarify this situation](https://gitlab.kitware.com/cmake/cmake/-/issues/22845).

---

<div class="post-metadata">

### Author: ![Leon0402](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/l/ccd318/32.png) [@Leon0402](https://discourse.cmake.org/u/Leon0402)
#### Post date: [November 17, 2021, 7:53pm UTC](https://discourse.cmake.org/t/runtime-dependencies/4497/3 "2021-11-17T19:53:53Z")

</div>

So this is something that would need to be improved in the findPostgresql.cmake script?

What’s about my other question with the `PATH`. Why is it not considered for the `file(RUNTIME_DEPENDENCIES)` command?

---

<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 17, 2021, 8:08pm UTC](https://discourse.cmake.org/t/runtime-dependencies/4497/4 "2021-11-17T20:08:28Z")

</div>

CMake doesn’t know the name of the DLL to search for, so why would it look in `PATH` in the first place?

---

<div class="post-metadata">

### Author: ![Leon0402](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/l/ccd318/32.png) [@Leon0402](https://discourse.cmake.org/u/Leon0402)
#### Post date: [November 17, 2021, 8:14pm UTC](https://discourse.cmake.org/t/runtime-dependencies/4497/5 "2021-11-17T20:14:36Z")

</div>

`file(RUNTIME_DEPENDENCIES)` doesn’t know the name of the DLL? How would that be possible?

At least if it doesn’t find a dll it tells me the exact name of the dll that is missing. So it has to know the dll name I assume?

Edit:

```auto
install(TARGETS BeansServer COMPONENT Beans 
    RUNTIME_DEPENDENCIES
      PRE_EXCLUDE_REGEXES "api-ms-" "ext-ms-"
      POST_EXCLUDE_REGEXES ".*system32/.*\\.dll"
      DIRECTORIES $<TARGET_FILE_DIR:Qt6::Core>
      FRAMEWORK DESTINATION Beans.app/Contents/Frameworks
  )

```

Error Message:  
`file Could not resolve file libpq.dll`

And this DLL is on the PATH. If I execute the executable generated by the target everything works fine.

---

<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 17, 2021, 8:30pm UTC](https://discourse.cmake.org/t/runtime-dependencies/4497/6 "2021-11-17T20:30:11Z")

</div>

Oh, `file(GET_RUNTIME_DEPENDENCIES)`. For some reason, I kept reading it as the genex, sorry.

It doesn’t search `PATH` for the same reason that `LD_LIBRARY_PATH` and `DYLD_LIBRARY_PATH` are ignored on Linux and macOS. See [this answer](https://discourse.cmake.org/t/runtime-dependencies-cannot-find-dll/3782/4).

---

<div class="post-metadata">

### Author: ![Leon0402](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/l/ccd318/32.png) [@Leon0402](https://discourse.cmake.org/u/Leon0402)
#### Post date: [November 17, 2021, 8:33pm UTC](https://discourse.cmake.org/t/runtime-dependencies/4497/7 "2021-11-17T20:33:20Z")

</div>

Wrong link? → Xcode indent settings?

So is there any solution to my problem? Do I need to hardcode the path to Postgresql dlls so that `file(GET_RUNTIME_DEPENDENCIES)` works on Windows? That’s not very nice 😕

---

<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 17, 2021, 8:40pm UTC](https://discourse.cmake.org/t/runtime-dependencies/4497/8 "2021-11-17T20:40:19Z")

</div>

Yep, wrong clipboard; I’ve updated the link. I’d say that `FindPostgreSQL` should be improved to know that it found a `SHARED` or `STATIC` library. Then you can use `$<TARGET_DIR>` for the relevant targets to get the search paths.
