I'm using CMake v3.21.0 to invoke Qt's windeployqt during the install stage by the means of the install(CODE) command as follows:
install(
    CODE "
    execute_process(
      COMMAND \"${CMAKE_COMMAND}\" -E
        env PATH=\"${windeployqt_ROOT_DIR}\"
        \"${windeployqt_EXECUTABLE}\"
        # TODO(2021-08-25 by wolters): This is a different path when CPack is`
        # used. How to check for this case and obtain the correct output path?
        --dir \"${CMAKE_INSTALL_PREFIX}/${args_INSTALL_SUFFIX}\"
        --no-quick-import
        --no-system-d3d-compiler
        --no-virtualkeyboard
        --no-compiler-runtime
        --no-webkit2
        --no-angle
        --no-opengl-sw
        --verbose 0
        \"\$<TARGET_FILE:${args_TARGET}>\"
    )
    "
    COMPONENT runtime
  )
This works fine if installing the project:
cmake --build . --config RelWithDebInfo --target install
But when creating a CPack package the files created by windeployqt are not part of the package (ZIP in this case):
cpack -G ZIP -C RelWithDebInfo -D CPACK_COMPONENTS_ALL="runtime"
I know that the issue is the usage of ${CMAKE_INSTALL_PREFIX} in the CODE.
- For the 
installtarget this is correct. - For the 
packagetarget this is not correct. Instead the build directory for the current CPack generator should be used, e.g.${CMAKE_CURRENT_BINARY_DIR}/_CPack_Packages/win64/ZIP/${CPACK_PACKAGE_FILE_NAME}. 
My questions are:
- Is there a way to differentiate between 
installandpackagetarget in theCODEsection? (pseudo-code:if(CMAKE_IS_PACKAGING)) - If there is a way: Is it possible to obtain or dynamically build the directory path to the actual CPack temporary "install" directory?
 
If both problems can be solved the files generated by windeployqt should be part of the packages generated by CPack.