Slicer packaging Qt5 libraries link

Operating system: MACOS 10.13.5
Slicer version: 27287
Expected behavior: Launch Slicer
Actual behavior:

I have compiled Slicer r 27287 successfully on MACOS high Sierra 10.13.5
The packaging seems to be working after the following fixes are introduced, otherwise errors such as appear for Qt libraries:

warning: cannot resolve item '@rpath/QtMultimedia.framework/Versions/5/QtMultimedia'

  possible problems:
    need more directories?
    need to use InstallRequiredSystemLibraries?
    run in install tree instead of build tree?

The fixes are
Before calling configure_file in SlicerCPack.cmake line 140 (this is to get the location of Qt5 libraries):

  get_target_property(Qt5_location Qt5::Widgets LOCATION)
  string(FIND ${Qt5_location} "/QtWidgets" length)
  string(SUBSTRING ${Qt5_location} 0 ${length} Qt5_location)

configure_file(
    "${Slicer_SOURCE_DIR}/CMake/SlicerCPackBundleFixup.cmake.in"
    "${slicer_cpack_bundle_fixup_directory}/SlicerCPackBundleFixup.cmake"
    @ONLY)

And in the SlicerCPackBundleFixup.cmake.in in line 314 (This is to add the location):

set(libs_path ${libs_path} @Qt5_location@)

fixup_bundle(
    "${app_dir}"
    "${libs}"
    "${libs_path}"
    )

The following error appears now:

dyld: Library not loaded: @rpath/Frameworks/QtMultimedia.framework/Versions/5/QtMultimedia
  Referenced from: /Users/aaaa/Slicer/Slicer-install/Slicer.app/Contents/MacOS/Slicer
  Reason: no suitable image found.  Did find:
    /Users/aaaa/Slicer/Slicer-install/Slicer.app/Contents/MacOS/../Frameworks/QtMultimedia.framework/Versions/5/QtMultimedia: file too short
[1]    9262 abort      /Users/aaaa/Slicer/Slicer-install/Slicer.app/Contents/MacOS/Slicer

Does any body know how to fix the packaging?

Thank you in advance.

Try this solution

@juanprietob Qt5 needs to be built with -no-rpath right now. See this build script.

That may work locally, but it is not a solution for packaging; users should not need to set any environment variables.