# macOS copy dependency to package

**URL:** <https://discourse.cmake.org/t/macos-copy-dependency-to-package/349>\
**Category:** Code\
**Created:** [December 11, 2019, 10:14am UTC](https://discourse.cmake.org/t/macos-copy-dependency-to-package/349 "2019-12-11T10:14:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![baschdel\_98](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/c68b51/32.png) [@baschdel\_98](https://discourse.cmake.org/u/baschdel_98)\
**Post date:** [December 11, 2019, 10:14am UTC](https://discourse.cmake.org/t/macos-copy-dependency-to-package/349/1 "2019-12-11T10:14:41Z")

</div>

Hello there,  
I have a small problem with c++ cmake on OSX.

I am writing an application that depends on Qt, Curl, and FFmpeg.

- I am able to build the application
- I am able to create a \*.app directory
- I am able to create a \*dmg file vie DragNDrop.

At the moment I am trying to include the dependencies in the \*.app file.  
For this I woulde like to utilize the BundleUtilities.

But to be honest, I am not sureif this is the right way.

At the moment my code looks more ore lss like this:

```auto
install(TARGETS exe-filename
       DESTINATION .
       COMPONENT app)

get_filename_component(CURL_LIB_DIR "${CURL_LIBRARIES}" DIRECTORY)
list(APPEND DIRS ${CURL_LIB_DIR})
foreach(FFMPEG_SINGLE_LIB ${FFMPEG_LIBRARIES})
    get_filename_component(FFMPEG_LIB_DIR "${FFMPEG_SINGLE_LIB}" DIRECTORY)
    list(APPEND DIRS ${FFMPEG_LIB_DIR})
endforeach()
get_target_property(QT_CORE_LIB Qt5::Core LOCATION)
get_filename_component(QT_RUNTIME_DIR "${QT_CORE_LIB}" DIRECTORY)

list(REMOVE_DUPLICATES DIRS)

set(CPACK_DMG_BACKGROUND_IMAGE "${CMAKE_CURRENT_SOURCE_DIR}/res/icon_OSX/CMakeDMGBackground.tif")
set(CPACK_DMG_DS_STORE_SETUP_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/res/icon_OSX/Packaging_CMakeDMGSetup.scpt")
set(CPACK_GENERATOR DragNDrop)

include(CPack)

include(BundleUtilities)
set(MAIN_APP "exe-filename")
install(CODE "fixup_bundle(\"\${MAIN_APP}\" \"\" \"${DIRS}\")")

```

Is this the right way to achive my goal?  
Best regards  
Sebastian

---

<div class="post-metadata">

**Author:** ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)\
**Post date:** [December 16, 2019, 9:29pm UTC](https://discourse.cmake.org/t/macos-copy-dependency-to-package/349/2 "2019-12-16T21:29:12Z")

</div>

The `BundleUtilities` module should be included at install time. See [code in CMake itself](https://gitlab.kitware.com/cmake/cmake/blob/v3.16.1/Source/QtDialog/CMakeLists.txt#L260-264) as an example.

EDIT: The code in CMake itself refers to the BundleUtilities module in a way that works only inside its own build. Project code can use plain `include(BundleUtilities)` for that.
