# install(TARGETS...RUNTIME\_DEPENDENCIES...): file Could not resolve runtime dependencies for other targets

**URL:** <https://discourse.cmake.org/t/install-targets-runtime-dependencies-file-could-not-resolve-runtime-dependencies-for-other-targets/15150>\
**Category:** Code\
**Created:** [September 4, 2025, 3:05pm UTC](https://discourse.cmake.org/t/install-targets-runtime-dependencies-file-could-not-resolve-runtime-dependencies-for-other-targets/15150 "2025-09-04T15:05:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anton\_Kryukov](https://discourse.cmake.org/user_avatar/discourse.cmake.org/anton_kryukov/32/5011_2.png) [@Anton\_Kryukov](https://discourse.cmake.org/u/Anton_Kryukov)\
**Post date:** [September 4, 2025, 3:05pm UTC](https://discourse.cmake.org/t/install-targets-runtime-dependencies-file-could-not-resolve-runtime-dependencies-for-other-targets/15150/1 "2025-09-04T15:05:37Z")

</div>

I am using CMake 3.31 and the Visual Studio generator in this example, but I don’t think it should matter for the problem that I am facing.  
My project has many targets T1, T2,… All targets have install rules

```cmake
install(TARGETS ${tgt}
  RUNTIME COMPONENT "Bin"
  LIBRARY COMPONENT "Bin"
)
install(TARGETS ${tgt} RUNTIME_DEPENDENCIES
  ...
  EXCLUDE_FROM_ALL
  RUNTIME COMPONENT "BinWithDeps" EXCLUDE_FROM_ALL
  LIBRARY COMPONENT "BinWithDeps" EXCLUDE_FROM_ALL
)   

```

I need to be able to **install subsets of targets with their runtime dependencies**. For that I create custom targets CT1, CT2,… like

```cmake
add_custom_target(${customTgt}
  COMMAND ${CMAKE_COMMAND}
   -DBUILD_TYPE="$<CONFIG>"
   -DCOMPONENT="BinWithDeps"
   -DCMAKE_INSTALL_PREFIX="${MyPrefix}"
   -P ${installScript}
)

```

for which I explicitly specify top level dependencies like

```auto
add_dependencies(${customTgt} T2)

```

(T2 transitively depends on T1 in this example). For each custom target CTn I figure out the full dependency subset by recursively examining the `LINK_LIBRARIES` property of the dependencies and generate a `CTn_install.cmake` script that ends up looking like

```cmake
if(EXISTS build/T1/cmake_install.cmake)
  include(build/T1/cmake_install.cmake)
endif()
if(EXISTS build/T2/cmake_install.cmake)
  include(build/T2/cmake_install.cmake)
endif()
...

```

Then

```auto
cmake --build build -DCMAKE_INSTALL_PREFIX=MyPrefix --config Release --target CTn

```

is expected to do what I need. However, it fails with a message like

```auto
file Could not resolve runtime dependencies:
    T1.dll

```

during processing of T2’s `cmake_install.cmake`. The error points to the line in the script with the `file(GET_RUNTIME_DEPENDENCIES...)` command which lists the T1 artifact in the `POST_EXCLUDE_FILES_STRICT` section.  
The same error happens if I just run

```auto
cmake --install build --component BinWithDeps --config Release --prefix MyPrefix

```

so, the problem does not seem to result from the way the custom target is defined.  
I understand why in-project targets are excluded from the runtime dependency checks, but what I don’t understand is **why inability to resolve their artifacts’ location should be considered a failure** if they are explicitly excluded by CMake itself.  
More importantly, I am looking for suggestions how to achieve what I need, maybe using a different approach.

---

<div class="post-metadata">

**Author:** ![Anton\_Kryukov](https://discourse.cmake.org/user_avatar/discourse.cmake.org/anton_kryukov/32/5011_2.png) [@Anton\_Kryukov](https://discourse.cmake.org/u/Anton_Kryukov)\
**Post date:** [September 6, 2025, 5:18pm UTC](https://discourse.cmake.org/t/install-targets-runtime-dependencies-file-could-not-resolve-runtime-dependencies-for-other-targets/15150/2 "2025-09-06T17:18:07Z")

</div>

I have reworked my approach slightly by trying to use a component install with a `RUNTIME_DEPENDENCY_SET` instead of crafting an install.cmake script myself, but the result is the same.  
The install commands that I use boil down to

```Cmake
set(component "C1")
set(targets "T1" "T2")

install(TARGETS ${targets}
    RUNTIME_DEPENDENCY_SET ${component}
    EXCLUDE_FROM_ALL
    RUNTIME COMPONENT ${component} EXCLUDE_FROM_ALL
    LIBRARY COMPONENT ${component} EXCLUDE_FROM_ALL
)
install(IMPORTED_RUNTIME_ARTIFACTS ${targets}
    RUNTIME_DEPENDENCY_SET ${component}
    EXCLUDE_FROM_ALL
    RUNTIME COMPONENT ${component} EXCLUDE_FROM_ALL
    LIBRARY COMPONENT ${component} EXCLUDE_FROM_ALL
)

if (WIN32)
  string(REPLACE "\\" "[/\\]" SystemRootPattern "^$ENV{SystemRoot}")
  string(APPEND SystemRootPattern "[/\\]")
endif()

install(RUNTIME_DEPENDENCY_SET ${component}
    PRE_EXCLUDE_REGEXES
      "$<$<PLATFORM_ID:Windows>:^api-ms-.*>"
      "$<$<PLATFORM_ID:Windows>:^ext-ms-.*>"
      "$<$<PLATFORM_ID:Windows>:msvcr[0-9]+.dll$>"
    POST_EXCLUDE_REGEXES
      "$<$<PLATFORM_ID:Linux>:^/lib/.*>"
      "$<$<PLATFORM_ID:Linux>:^/usr/.*>"
      "$<$<BOOL:SystemRootPattern>:${SystemRootPattern}>"
    EXCLUDE_FROM_ALL
    RUNTIME COMPONENT ${component} EXCLUDE_FROM_ALL
    LIBRARY COMPONENT ${component} EXCLUDE_FROM_ALL
)

```

and running

```shell
cmake --fresh -S . -B build -G "Visual Studio 17 2022" -A x64 -T v143
cmake --build build --config Release
cmake --install build --component C1 --config Release --prefix .\build\install-C1-x64-v143

```

with the reult

```auto
CMake Error at build/C1/cmake_install.cmake:126 (file):
  file Could not resolve runtime dependencies:

    T1.dll
Call Stack (most recent call first):
  build/cmake_install.cmake:47 (include)

```

I have poured through CMake documentation and fail to see where my misunderstanding lies.  
Is there an “accepted” way to install a subset of depentent binaries from a bigger CMake project?
