# IMPORTED\_RUNTIME\_ARTIFACTS with and without RUNTIME\_DEPENDENCY\_SET

**URL:** <https://discourse.cmake.org/t/imported-runtime-artifacts-with-and-without-runtime-dependency-set/6661>\
**Category:** Code\
**Tags:** os:linux, os:windows\
**Created:** [October 13, 2022, 11:04pm UTC](https://discourse.cmake.org/t/imported-runtime-artifacts-with-and-without-runtime-dependency-set/6661 "2022-10-13T23:04:16Z")\
**Posts on this page:** 9\
**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:** [October 13, 2022, 11:04pm UTC](https://discourse.cmake.org/t/imported-runtime-artifacts-with-and-without-runtime-dependency-set/6661/1 "2022-10-13T23:04:16Z")

</div>

myLib:

```auto
add_library(myLib SHARED lib.cpp lib.h)
target_include_directories(myLib PUBLIC ${CMAKE_CURRENT_LIST_DIR})

```

main:

```auto
add_executable(main main.cpp)
target_link_libraries(main PRIVATE myLib)

install(TARGETS main
    RUNTIME DESTINATION out
)

install(IMPORTED_RUNTIME_ARTIFACTS main
    RUNTIME_DEPENDENCY_SET mainDeps
)

install(RUNTIME_DEPENDENCY_SET mainDeps
    LIBRARY DESTINATION out
)

```

Result (looks good to me):

```auto
...
[build] -- Installing: .../out/main
[build] -- Installing: .../out/myLib.so
...

```

However:

main:

```auto
add_executable(main main.cpp)
target_link_libraries(main PRIVATE myLib)

install(TARGETS main
    RUNTIME DESTINATION out
)

install(IMPORTED_RUNTIME_ARTIFACTS main
    LIBRARY DESTINATION out
)

```

Result (myLib.so not installed):

```auto
...
[build] -- Installing: .../out/main
...

```

1. Shouldn’t these behave the same way, though?
2. I suspect everything is wrong from the start because `myLib` isn’t an IMPORTED target. Is that correct?
3. What’s the canonical way to achieve what I’m going for, which is to install an executable (or shared library) and its runtime library dependencies all in the same directory? I understand that there might be nuance between imported libraries (like Boost) and libraries that I define myself (like myLib). Do I need to manually identify and install the dependencies myself (e.g., `install(IMPORTED_RUNTIME_ARTIFACTS ${Boost_LIBRARIES})`? Or is there a more “automatic” way of doing this (something that my first main CMakeLists.txt seems to imply)?

---

<div class="post-metadata">

**Author:** ![kyle.edwards](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kyle.edwards](https://discourse.cmake.org/u/kyle.edwards)\
**Post date:** [October 14, 2022, 1:55pm UTC](https://discourse.cmake.org/t/imported-runtime-artifacts-with-and-without-runtime-dependency-set/6661/2 "2022-10-14T13:55:39Z")

</div>

> 1. Shouldn’t these behave the same way, though?

No. `IMPORTED_RUNTIME_ARTIFACTS` only installs the artifacts from that specific target, not from any of its dependencies. `RUNTIME_DEPENDENCY_SET` is needed to install the dependencies.

> 1. I suspect everything is wrong from the start because `myLib` isn’t an IMPORTED target. Is that correct?

Neither `main` nor `myLib` is `IMPORTED`, so yes, `IMPORTED_RUNTIME_ARTIFACTS` is not what you want here.

> 1. What’s the canonical way to achieve what I’m going for, which is to install an executable (or shared library) and its runtime library dependencies all in the same directory? I understand that there might be nuance between imported libraries (like Boost) and libraries that I define myself (like myLib).

```cmake
install(TARGETS main myLib
  RUNTIME DESTINATION out
  LIBRARY DESTINATION out
  RUNTIME_DEPENDENCIES)

```

Since `myLib` is not `IMPORTED`, it has to be installed manually with `install(TARGETS)`. However, Boost et al can be captured with `RUNTIME_DEPENDENCIES` since they’re `IMPORTED`.

---

<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:** [October 14, 2022, 8:22pm UTC](https://discourse.cmake.org/t/imported-runtime-artifacts-with-and-without-runtime-dependency-set/6661/3 "2022-10-14T20:22:07Z")

</div>

> ```auto
> install(TARGETS main myLib
> RUNTIME DESTINATION out
> LIBRARY DESTINATION out
> RUNTIME_DEPENDENCIES)
> 
> ```
> 
> Since `myLib` is not `IMPORTED`, it has to be installed manually with `install(TARGETS)`. However, Boost et al can be captured with `RUNTIME_DEPENDENCIES` since they’re `IMPORTED`.

I tried this, but cmake gave an error:

```auto
[cmake] install TARGETS given unknown argument "RUNTIME_DEPENDENCIES".

```

Looking at the docs, it seems that `RUNTIME_DEPENDENCIES` should maybe come first:

```auto
install(TARGETS main myLib
    RUNTIME_DEPENDENCIES
    RUNTIME DESTINATION out
    LIBRARY DESTINATION out
)

```

But then cmake complains:

```auto
[cmake] install TARGETS given target "myLib" which does not exist.

```

Confusing since it obviously exists, I can link against it.

---

<div class="post-metadata">

**Author:** ![kyle.edwards](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kyle.edwards](https://discourse.cmake.org/u/kyle.edwards)\
**Post date:** [October 14, 2022, 8:29pm UTC](https://discourse.cmake.org/t/imported-runtime-artifacts-with-and-without-runtime-dependency-set/6661/4 "2022-10-14T20:29:33Z")

</div>

> [@wuziq](#):
>
> Looking at the docs, it seems that `RUNTIME_DEPENDENCIES` should maybe come first:

Oh, right, my bad.

> [@wuziq](#):
>
> Confusing since it obviously exists, I can link against it.

Is `myLib` `IMPORTED` at this point? If so, I would expect `install(TARGETS)` to give the error that it gave (yes, I know that error is confusing.)

---

<div class="post-metadata">

**Author:** ![kyle.edwards](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kyle.edwards](https://discourse.cmake.org/u/kyle.edwards)\
**Post date:** [October 14, 2022, 8:30pm UTC](https://discourse.cmake.org/t/imported-runtime-artifacts-with-and-without-runtime-dependency-set/6661/5 "2022-10-14T20:30:35Z")

</div>

> [@kyle.edwards](#):
>
> Is `myLib` `IMPORTED` at this point?

What I mean is, are `main` and `myLib` built as part of the same project or different projects?

---

<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:** [October 14, 2022, 8:58pm UTC](https://discourse.cmake.org/t/imported-runtime-artifacts-with-and-without-runtime-dependency-set/6661/6 "2022-10-14T20:58:42Z")

</div>

`main` and `myLib` are part of the same project:

```auto
add_subdirectory(myLib)
add_subdirectory(main)

```

where those directories each contain a CMakeLists.txt with the corresponding contents I gave in the OP.

---

<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:** [October 14, 2022, 9:00pm UTC](https://discourse.cmake.org/t/imported-runtime-artifacts-with-and-without-runtime-dependency-set/6661/7 "2022-10-14T21:00:45Z")

</div>

I’ve tried with cmake 3.21.1 and 3.23.3, if that matters.

---

<div class="post-metadata">

**Author:** ![kyle.edwards](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kyle.edwards](https://discourse.cmake.org/u/kyle.edwards)\
**Post date:** [October 14, 2022, 9:02pm UTC](https://discourse.cmake.org/t/imported-runtime-artifacts-with-and-without-runtime-dependency-set/6661/8 "2022-10-14T21:02:30Z")

</div>

The fact that `myLib` is in a different subdirectory from where the `install()` is happening might not be helping. Try moving the `install()` to the top directory after the `add_subdirectory()` calls.

---

<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:** [October 14, 2022, 9:06pm UTC](https://discourse.cmake.org/t/imported-runtime-artifacts-with-and-without-runtime-dependency-set/6661/9 "2022-10-14T21:06:20Z")

</div>

That was it! It works now. Thank you!!
