# Install IMPORTED\_RUNTIME\_ARTIFACTS does nothing

**URL:** <https://discourse.cmake.org/t/install-imported-runtime-artifacts-does-nothing/5123>\
**Category:** Usage\
**Created:** [February 26, 2022, 2:31am UTC](https://discourse.cmake.org/t/install-imported-runtime-artifacts-does-nothing/5123 "2022-02-26T02:31:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![marstaik](https://discourse.cmake.org/user_avatar/discourse.cmake.org/marstaik/32/2230_2.png) [@marstaik](https://discourse.cmake.org/u/marstaik)\
**Post date:** [February 26, 2022, 2:31am UTC](https://discourse.cmake.org/t/install-imported-runtime-artifacts-does-nothing/5123/1 "2022-02-26T02:31:58Z")

</div>

Hi, I’ve been trying to find a simple way to copy an imported libs runtime artifacts into an installation directory. In my project, I have a final executable that is built, as well as a static/shared libraries (plural) that are built depending on configuration.

NOTE: I am using 3.23.0 RC2

For the executable, I can copy the runtime dependencies easily with:

```auto
function(COPY_RUNTIME_DEPS TARGET)
    add_custom_command(TARGET ${TARGET} POST_BUILD 
            COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:${TARGET}> $<TARGET_FILE_DIR:${TARGET}>
            COMMAND_EXPAND_LISTS
            )
endfunction()

```

But this doesn’t work for imported targets. My “libraries” are also mostly INTERFACE libraries, and the few that do compile into .dll/.so or statics, don’t depend on this imported library directly. As such, the above method just does not work.

I’ve tried to use IMPORTED\_RUNTIME\_ARTIFACTS with the imported library, and although there are no CMake errors, it does absolutely nothing.

I’m just trying to copy over libsodium’s libraries, depending on build configuration, to a lib directory in subfolder of the installation directory.

The CMake code looks like this:

```auto
# libsodium

if (WIN32)
    # https://cmake.org/cmake/help/latest/prop_tgt/MAP_IMPORTED_CONFIG_CONFIG.html#prop_tgt:MAP_IMPORTED_CONFIG_%3CCONFIG%3E
    
    add_library(libsodium SHARED IMPORTED GLOBAL)
    
    target_include_directories(libsodium INTERFACE include)
    
    #SET(LIB_PATH $<IF:$<STREQUAL:$<TARGET_PROPERTY:libsodium,TYPE>,SHARED_LIBRARY>,dynamic/libsodium.dll,static/libsodium.lib>)
    
    set_property(TARGET libsodium APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
    
    set_target_properties(libsodium PROPERTIES 
            IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "CXX" 
            IMPORTED_LOCATION_DEBUG ${CMAKE_CURRENT_SOURCE_DIR}/x64/Debug/v143/dynamic/libsodium.dll
            IMPORTED_IMPLIB_DEBUG ${CMAKE_CURRENT_SOURCE_DIR}/x64/Debug/v143/dynamic/libsodium.lib
            )
    
    set_property(TARGET libsodium APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
    
    set_target_properties(libsodium PROPERTIES 
            IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "CXX" 
            IMPORTED_LOCATION_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}/x64/Release/v143/dynamic/libsodium.dll
            IMPORTED_IMPLIB_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}/x64/Release/v143/dynamic/libsodium.lib
            )
    
    set_target_properties(libsodium PROPERTIES 
            MAP_IMPORTED_CONFIG_MINSIZEREL Release 
            MAP_IMPORTED_CONFIG_RELWITHDEBINFO Release
            )
    
    install(IMPORTED_RUNTIME_ARTIFACTS libsodium
        LIBRARY DESTINATION ${CLIENT_INSTALL_SUBDIR}/lib
        RUNTIME DESTINATION ${CLIENT_INSTALL_SUBDIR}/lib
        )
    
else()
    find_library(libsodium)
endif()

```

I thought simply calling: `install(TARGETS libsodium ...)` would work, but install does not work in imported targets, and I really don’t know why that limitation exists.

Any help is appreciated, 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 26, 2022, 2:05pm UTC](https://discourse.cmake.org/t/install-imported-runtime-artifacts-does-nothing/5123/2 "2022-02-26T14:05:06Z")

</div>

I would suggest that you use [`file(GET_RUNTIME_DEPENDENCIES)`](https://cmake.org/cmake/help/latest/command/file.html#get-runtime-dependencies) or the new [`install(RUNTIME_DEPENDENCY_SET)`](https://cmake.org/cmake/help/latest/command/install.html#runtime-dependency-set) to install your required DLLs.

---

<div class="post-metadata">

**Author:** ![marstaik](https://discourse.cmake.org/user_avatar/discourse.cmake.org/marstaik/32/2230_2.png) [@marstaik](https://discourse.cmake.org/u/marstaik)\
**Post date:** [February 26, 2022, 8:32pm UTC](https://discourse.cmake.org/t/install-imported-runtime-artifacts-does-nothing/5123/3 "2022-02-26T20:32:13Z")

</div>

Using `install(FILES file(GET_RUNTIME_DEPENDENCIES LIBRARIES libsodium) DESTINATION ${CLIENT_INSTALL_SUBDIR}/lib)` does not work either. I get the error:

```auto
CMake Error at src/kn/encryption/cmake_install.cmake:36 (file):
  file Failed to run dumpbin on:

    libsodium
Call Stack (most recent call first):
  src/kn/cmake_install.cmake:57 (include)
  src/cmake_install.cmake:57 (include)
  cmake_install.cmake:42 (include)

FAILED: CMakeFiles/install.util 

```

The library that depends on libsodium in this case, is header only and also an interface, ie:

```auto
add_library(encryption INTERFACE)
target_link_libraries(encryption INTERFACE libsodium)

install(CODE "file(GET_RUNTIME_DEPENDENCIES LIBRARIES encryption)" DESTINATION ${CLIENT_INSTALL_SUBDIR}/lib)

```

also results in:

```auto
CMake Error at src/kn/encryption/cmake_install.cmake:36 (file):
  file Failed to run dumpbin on:

    encryption
Call Stack (most recent call first):
  src/kn/cmake_install.cmake:57 (include)
  src/cmake_install.cmake:57 (include)
  cmake_install.cmake:42 (include)

```

I don’t understand why dumpbin has to be run in the first place. CMake should know about linked dependencies internally from configuration time, why is a library/executable attempting to be analyzed?

---

<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 26, 2022, 9:23pm UTC](https://discourse.cmake.org/t/install-imported-runtime-artifacts-does-nothing/5123/4 "2022-02-26T21:23:25Z")

</div>

> [@marstaik](#):
>
> I don’t understand why dumpbin has to be run in the first place. CMake should know about linked dependencies internally from configuration time, why is a library/executable attempting to be analyzed?

Because `POST_BUILD` exists and it’s also possible to inject libraries through `#pragma comment` on MSVC or raw linker flags in a usage requirement. `/DELAYLOAD` can also change things. On non-Windows, knowing that `libfoo.so` ends up adding a `DT_NEEDED` of `libfoo.so.2` or whatever (if it adds a one; linker scripts can do other things too). It’s easier to just ask what the resulting artifact actually needs instead of internalizing all of the targets (which still misses transitive dependencies too).

That is why this won’t work for `INTERFACE` libraries. You’ll need to run the analysis on `$<TARGET_FILE:libsodium>` or something like that.
