# CPack with externally created .app bundle (macOS)?

**URL:** <https://discourse.cmake.org/t/cpack-with-externally-created-app-bundle-macos/6152>\
**Category:** Code\
**Created:** [July 27, 2022, 1:57am UTC](https://discourse.cmake.org/t/cpack-with-externally-created-app-bundle-macos/6152 "2022-07-27T01:57:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![SamuelMarks](https://discourse.cmake.org/user_avatar/discourse.cmake.org/samuelmarks/32/1619_2.png) [@SamuelMarks](https://discourse.cmake.org/u/SamuelMarks)\
**Post date:** [July 27, 2022, 1:57am UTC](https://discourse.cmake.org/t/cpack-with-externally-created-app-bundle-macos/6152/1 "2022-07-27T01:57:21Z")

</div>

I’ve manually done lots that CMake+CPack are meant to do for me, here are the summary of my hacks, hidden behind an `if(BUILD_APPLE_BUNDLE)` `option` flag:

```cmake
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY
     "${CMAKE_BINARY_DIR}/${EXEC_NAME}.app/Contents/PlugIns")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
set_target_properties(
            "${EXEC_NAME}"
            PROPERTIES
            MACOSX_BUNDLE_NAME "${EXEC_NAME}"
            MACOSX_BUNDLE_VERSION "${PROJECT_VERSION}"
            MACOSX_BUNDLE_GUI_IDENTIFIER "org.${EXEC_NAME}.gui"
            MACOSX_BUNDLE_ICON_FILE "Icon.icns"
            MACOSX_BUNDLE_INFO_PLIST "${CMAKE_SOURCE_DIR}/cmake/Info.plist.in"
            MACOSX_BUNDLE "TRUE"
            # MACHO_COMPATIBILITY_VERSION "12.0.0"
            RESOURCE "${RESOURCE_FILES}"
            XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ""
            XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED NO
            XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT dwarf
            XCODE_ATTRIBUTE_GCC_INLINES_ARE_PRIVATE_EXTERN YES
            XCODE_ATTRIBUTE_CLANG_LINK_OBJC_RUNTIME NO
)
add_custom_command(
        TARGET "${EXEC_NAME}" POST_BUILD
        COMMAND install_name_tool
                -rpath "${CMAKE_BINARY_DIR}/${EXEC_NAME}.app/Contents/PlugIns" '@executable_path/../PlugIns'
                "${CMAKE_BINARY_DIR}/${EXEC_NAME}.app/Contents/MacOS/${EXEC_NAME}"
        WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
        COMMENT "Replace library search path from absolute to relative"
)

```

Which works great (finally!). Unfortunately I haven’t figured out to make it play nicely with CPack.

Before I started building my own macOS .app bundles “manually” I did have this code in place:

```cmake
install(TARGETS "${EXEC_NAME}" "${PROJECT_NAME}_lib"
            # TYPE "RUNTIME"
            RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
            LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
            ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}/static"
            BUNDLE DESTINATION "${CMAKE_INSTALL_BINDIR}/${EXEC_NAME}.app"
            COMPONENT "${PROJECT_NAME}")

```

But now that [obviously] puts my .app within another .app; which doesn’t work.

Can I get some sort of trick like this working?

```cmake
install(DIRECTORY "${CMAKE_BINARY_DIR}/${EXEC_NAME}.app" DESTINATION .)

```

Would be great to generate .dmg and .pkg (otherwise I’ll have to manually generate those also!!!)

---

<div class="post-metadata">

**Author:** ![rcoup](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rcoup/32/2091_2.png) [@rcoup](https://discourse.cmake.org/u/rcoup)\
**Post date:** [December 14, 2022, 11:46am UTC](https://discourse.cmake.org/t/cpack-with-externally-created-app-bundle-macos/6152/2 "2022-12-14T11:46:40Z")

</div>

@SamuelMarks did you ever figure out a solution for this? I have an externally created `My.app` bundle (via PyInstaller FWIW) I want CMake to install & CPack to package.
