# How to install() additional runtime (DLL) dependencies of an IMPORTED target?

**URL:** <https://discourse.cmake.org/t/how-to-install-additional-runtime-dll-dependencies-of-an-imported-target/7508>\
**Category:** Code\
**Created:** [February 20, 2023, 11:35pm UTC](https://discourse.cmake.org/t/how-to-install-additional-runtime-dll-dependencies-of-an-imported-target/7508 "2023-02-20T23:35:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ignus2](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ignus2/32/3075_2.png) [@ignus2](https://discourse.cmake.org/u/ignus2)\
**Post date:** [February 20, 2023, 11:35pm UTC](https://discourse.cmake.org/t/how-to-install-additional-runtime-dll-dependencies-of-an-imported-target/7508/1 "2023-02-20T23:35:53Z")

</div>

Porting an old project to CMake, Windows only. One of our modules uses an external SDK (header files, DLL, import library, debug/release). I encapsulate the external SDK like so:

```auto
set(EXTERNAL_SDK_DIR "/some/dir/to/sdk")
add_library(ExternalSDK SHARED IMPORTED)
set_target_properties(ExternalSDK PROPERTIES
    IMPORTED_CONFIGURATIONS "DEBUG;RELEASE"
    IMPORTED_LOCATION_DEBUG ${EXTERNAL_SDK_DIR}/debug/sdk.dll
    IMPORTED_IMPLIB_DEBUG ${EXTERNAL_SDK_DIR}/debug/sdk.lib
    IMPORTED_LOCATION_RELEASE ${EXTERNAL_SDK_DIR}/release/sdk.dll
    IMPORTED_IMPLIB_RELEASE ${EXTERNAL_SDK_DIR}/release/sdk.lib
    INTERFACE_INCLUDE_DIRECTORIES ${EXTERNAL_SDK_DIR}/include
)

```

This works nicely, I can then use it with `target_link_libraries()` as usual, and even install the sdk.dll using:

```auto
install(IMPORTED_RUNTIME_ARTIFACTS ExternalSDK RUNTIME DESTINATION .)

```

Now my problem is that ExternalSDK has **additional** DLL files it depends on, which is not required for linking (say: "sdk\_dep1.dll, sdk\_dep2.dll, etc.), but **must** be installed as well. These DLLs are located inside the SDK folders.

Is there some way of attaching these to the imported target, so the above `install(IMPORTED_RUNTIME_ARTIFACTS ...)` command also installs them? I tried setting `IMPORTED_LINK_DEPENDENT_LIBRARIES` and it’s per-config variants on ExternalSDK, but they still don’t get installed.

I’d appreciate any help with this! Thanks!

---

<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:** [February 21, 2023, 12:37am UTC](https://discourse.cmake.org/t/how-to-install-additional-runtime-dll-dependencies-of-an-imported-target/7508/2 "2023-02-21T00:37:47Z")

</div>

`IMPORTED_RUNTIME_ARTIFACTS` will only traverse DLLs known to CMake via `IMPORTED` targets. You can use `file(GET_RUNTIME_DEPENDENCIES)` to find other libraries needed.

---

<div class="post-metadata">

**Author:** ![ignus2](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ignus2/32/3075_2.png) [@ignus2](https://discourse.cmake.org/u/ignus2)\
**Post date:** [February 21, 2023, 1:24am UTC](https://discourse.cmake.org/t/how-to-install-additional-runtime-dll-dependencies-of-an-imported-target/7508/3 "2023-02-21T01:24:27Z")

</div>

I don’t really need to “find” these additional DLLs, they are already there explicitly in the SDK itself, they have a known name. They are loaded dynamically (using LoadLibrary()) by the SDK during runtime (they are not plugins, but conceptually similar).  
It seems to me `file(GET_RUNTIME_DEPENDENCIES)` is for some different purpose.

What I really want is to “bundle” or “tie” somehow these additional DLLs to the imported target, so the user of the imported target can easily install it together with it’s dependencies.

EDIT: While we’re at it, there’s another SDK which has additional **executables** bundled, which the SDK uses during runtime as surrogates to do some work, but the idea is the same, the executables will have to be copied next to the main SDK DLL (which the app is linked against). How should I go about bundling those?

---

<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:** [February 21, 2023, 2:20am UTC](https://discourse.cmake.org/t/how-to-install-additional-runtime-dll-dependencies-of-an-imported-target/7508/4 "2023-02-21T02:20:17Z")

</div>

> [@ignus2](#):
>
> They are loaded dynamically (using LoadLibrary()) by the SDK during runtime

They’'ll need to be managed manually then I’m afraid.

You’re best modeling this as if they were dependent targets with some genex to disable actually linking them somehow.

---

<div class="post-metadata">

**Author:** ![wuziq](https://discourse.cmake.org/user_avatar/discourse.cmake.org/wuziq/32/2830_2.png) [@wuziq](https://discourse.cmake.org/u/wuziq)\
**Post date:** [May 21, 2023, 8:35pm UTC](https://discourse.cmake.org/t/how-to-install-additional-runtime-dll-dependencies-of-an-imported-target/7508/5 "2023-05-21T20:35:30Z")

</div>

@ignus2 were you able to find a way to achieve what you were looking for?

---

<div class="post-metadata">

**Author:** ![ignus2](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ignus2/32/3075_2.png) [@ignus2](https://discourse.cmake.org/u/ignus2)\
**Post date:** [June 6, 2023, 8:47am UTC](https://discourse.cmake.org/t/how-to-install-additional-runtime-dll-dependencies-of-an-imported-target/7508/6 "2023-06-06T08:47:09Z")

</div>

@wuziq We found no general solution. So I wrote a function which takes care of installing the dependencies explicitly. The dependencies were wrapped as IMPORTED MODULE targets, though that is not strictly necessary, they might as well be installed as files.

---

<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 29, 2024, 12:32pm UTC](https://discourse.cmake.org/t/how-to-install-additional-runtime-dll-dependencies-of-an-imported-target/7508/7 "2024-05-29T12:32:26Z")

</div>

> [@ben.boeckel](#):
>
> They’'ll need to be managed manually then I’m afraid.
> 
> You’re best modeling this as if they were dependent targets with some genex to disable actually linking them somehow.

@ben.boeckel How would you please model this? As @ignus2 said, additional runtime dependencies come in the form of DLLs without import link libraries. So modelling the dependencies with `target_link_libraries` on the target (being IMPORTED or not) doesn’t seem to be a viable option to me. And neither is `IMPORTED_LINK_DEPENDENT_LIBRARIES`, as also reported by @ignus2.

---

<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:** [June 11, 2024, 4:57pm UTC](https://discourse.cmake.org/t/how-to-install-additional-runtime-dll-dependencies-of-an-imported-target/7508/8 "2024-06-11T16:57:29Z")

</div>

When I’ve done this before, I’ve tracked all intended “entry points” that are binaries. This includes executables, but also plugins intended to be `dlopen`’d (or equivalent).
