RUNTIME_DEPENDENCIES cannot find dll

Hi,

I’m using RUNTIME_DEPENDENCIES with CMake 3.21 as follow:

install(TARGETS MyApp
  RUNTIME_DEPENDENCIES
    PRE_EXCLUDE_REGEXES "api-ms-" "ext-ms-"
    POST_EXCLUDE_REGEXES ".*system32/.*\\.dll"
)

But it says "file Could not resolve file qt6core.dll`. What is going wrong here? MyApp is target linking to Qt6Core, so the library should be found (Qt6 is in my PATH on Windows). Why is it not found?

Note: This also happens when using the “old” code:

install(CODE "set(DEPENDENCY_PATHS \"${DEPENDENCY_PATHS}\")")
install(CODE [[
  file(GET_RUNTIME_DEPENDENCIES
    LIBRARIES "$<TARGET_FILE:BeansApp>"
    RESOLVED_DEPENDENCIES_VAR _r_deps
    UNRESOLVED_DEPENDENCIES_VAR _u_deps
    DIRECTORIES ${DEPENDENCY_PATHS}
    PRE_EXCLUDE_REGEXES "api-ms-" "ext-ms-"
    POST_EXCLUDE_REGEXES ".*system32/.*\\.dll"
  )
  foreach(_file ${_r_deps})
    file(INSTALL
      DESTINATION "${CMAKE_INSTALL_PREFIX}/bin"
      TYPE SHARED_LIBRARY
      FILES "${_file}"
    )
  endforeach()
  list(LENGTH _u_deps _u_length)
  if("${_u_length}" GREATER 0)
    message(WARNING "Unresolved dependencies detected!")
  endif()
]])

You need to include the directory containing qt6core.dll in the DIRECTORIES argument.

Why is this necessary? The QT Directory is on the PATH and actually found by find_package. The qt6 target is then also linked to my target. So CMake really should have all information needed to figure this out. Either by searching the path or by just using the lib that it already found.

If I really have to specify DIRECTORIES, I don’t quite see the use of
GET_RUNTIME_DEPENDENCIES. Then I could just as well list the libraries manually?

I’m not sure how I would set DIRECTORIES either. The Qt6 lib is in the PATH or specified via CMAKE_PREFIX_PATH. I have no idea where is actually is on different systems. My primary goal with RUNTIME_DEPENDCIES was to automate this in a generic way without relying on hardcoded paths and such stuff.

DIRECTORIES is more needed on Windows than on Linux and Mac because it has no equivalent to RPATH. Linux rarely needs DIRECTORIES (and warns you if it finds something in a DIRECTORIES argument), and on Mac it isn’t even used at all.

We deliberately made the decision to not consider the PATH variable in file(GET_RUNTIME_DEPENDENCIES), because setting the PATH from outside the project could change the results of it. You can add $<TARGET_DIR:qt6core> to the DIRECTORIES argument, which should allow it to find it.

1 Like

I think I do understand why this is not happening automatically. As the command is evaluated at a different time, where target information is not available.

But I wonder why it’s not done at some other time. CMake knows in general my target and it dependencies and could set the DIRECTORIES Argument for instance automatically.