# installing a pre-built module and its various dependencies

**URL:** <https://discourse.cmake.org/t/installing-a-pre-built-module-and-its-various-dependencies/5227>\
**Category:** Code\
**Tags:** comp:msvc, os:windows, gen:ninja\
**Created:** [March 16, 2022, 12:05pm UTC](https://discourse.cmake.org/t/installing-a-pre-built-module-and-its-various-dependencies/5227 "2022-03-16T12:05:53Z")\
**Posts on this page:** 2\
**Page:** 1

<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:** [March 16, 2022, 12:05pm UTC](https://discourse.cmake.org/t/installing-a-pre-built-module-and-its-various-dependencies/5227/1 "2022-03-16T12:05:53Z")

</div>

Apologies in advance if this approach is completely wrong-headed. I could be missing obvious things but am just too tunnel-visioned to realize it. Anyway…

We have a pre-built .dll, called Foo.dll, that we load with LoadLibrary(). There’s no import library.

Foo.dll depends on various other (legacy) pre-built .dlls, as well as a data file called bar.bin and a config file called baz.conf.

I’ve created a Foo-config.cmake like so:

> **Foo-config.cmake**
>
> ```auto
> ...
> add_library(Foo::Foo MODULE IMPORTED)
> set_target_properties(Foo::Foo PROPERTIES
> INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
> IMPORTED_LOCATION "${_IMPORT_PREFIX}/bin/Foo.dll"
> )
> ...
> 
> ```

The resulting .zip contains:

- Foo.dll
- All of its other .dll dependencies (about 5 other .dlls)
- bar.bin and baz.conf
- include/Foo.h
- lib/cmake/Foo-config.cmake and lib/cmake/Foo-config-version.cmake

Now, I’m using cmake to create an application that depends on Foo.dll. I use `FetchContent_*` and `find_package` to pull the .zip from our internal artifactory and make it known to cmake. No problems there.

However, here’s what I’m not sure about:

- How to associate `Foo::Foo` to my application’s target, if that’s even necessary. I’d like to do it, because the `TARGET_RUNTIME_DLLS` generator expression sounds promising here.
  - `target_link_libraries` doesn’t work because then Foo.dll is on the link line, which produces a link error.
  - As a result, Foo’s include directory also isn’t added to the application’s header search paths, and `target_include_directories(App PUBLIC Foo)` doesn’t seem to work, either.

- The best way to install all of Foo.dll’s dependencies along with the application. I acknowledge that my Foo-config.cmake is likely missing some key things. Or, maybe I just need to use `install(FILES ...)`, referencing the files relative to the source directory from `FetchContent`?

Can this use case be accomplished with cmake? Any guidance would be appreciated.

---

<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:** [March 17, 2022, 5:47am UTC](https://discourse.cmake.org/t/installing-a-pre-built-module-and-its-various-dependencies/5227/2 "2022-03-17T05:47:08Z")

</div>

> [@wuziq](#):
>
> `target_link_libraries` doesn’t work because then Foo.dll is on the link line, which produces a link error.

Right, the module is only loadable, so the linker doesn’t care about it.

> [@wuziq](#):
>
> As a result, Foo’s include directory also isn’t added to the application’s header search paths, and `target_include_directories(App PUBLIC Foo)` doesn’t seem to work, either.

I would make a second `INTERFACE` target with the compilation requirements. You can then add this to `Foo::Foo`’s interface (for whatever it’s worth) and use it in any consuming bit. Calling it `Foo::Headers` or `Foo::SDK` is probably apt.

> [@wuziq](#):
>
> The best way to install all of Foo.dll’s dependencies along with the application.

[`file(GET_RUNTIME_DEPENDENCIES)`](https://cmake.org/cmake/help/latest/command/file.html#get-runtime-dependencies) should work here.
