16

We build an OS X application, released in a .app bundle. The build management is implemented using CMake. This application depends on both CMake target libraries (possibly imported) and libraries available in the xxx_LIBRARIESvariables populated by Findxxx.cmake scripts. An outline of the CMakeLists.txt could be:

project(OSX_Bundle)

add_executable(${PROJECT_NAME} MACOSX_BUNDLE main.mm )

target_include_directories(${PROJECT_NAME}  PRIVATE
                           ${LibA_INCLUDE_DIRS} )

target_link_libraries(${PROJECT_NAME}
                      ${LibA_LIBRARIES}
                      LibB
                      "-framework Cocoa" )

Now, we need to copy both LibA.dylib and LibB.dylib into the canonical OSX_Bundle.app/Contents/Frameworks. This copy should be done for the app in the build tree, as well as in the install tree. Even though it would appear as a basic task, we cannot find a good resource online explaining the best way(s) of solving this issue.

Ad N
  • 7,930
  • 6
  • 36
  • 80
  • possible duplicate of [CMake: Copy Frameworks into App Bundle](http://stackoverflow.com/questions/6944376/cmake-copy-frameworks-into-app-bundle) – Hasturkun Jul 28 '15 at 10:36
  • 1
    @Hasturkun Thank you for the link. Sadly it seems that fixup_bundle only applies to the install tree (at least that what I am inferring from all the example using it in an `INSTALL` command). – Ad N Jul 28 '15 at 10:38
  • 1
    I haven't used it, but it looks like `FIXUP_BUNDLE` works in place so I think it should work for you (but again, I haven't tested it) – Hasturkun Jul 28 '15 at 10:49
  • I would recommend using bash to grab libraries and adjust install names. – Richard Barber Feb 26 '21 at 17:51

1 Answers1

-2

Many people face this issue. You can try one of this list:

  • CMake post-buld command and invoke "macdeployqt" here; but it may slowdown the build (CMake generator expressions will give you correct path and binary for Xcode/VS as well)
  • or CMake custom command, again with macdeployqt, if you don't want trigger it always, then it can be manually triggered wheen needed
  • it is possible bundle dependencies on install stage as mentioned in above comments
  • it is possible to use CPack, it will give you new 'package' target; after playing with CMake/CPack it may bundle everything needed (it use install stuff mentioned above) and generate a final installer

I guess, the last bullet should fit your needs.

Ľubomír Carik
  • 387
  • 5
  • 11
  • Introducing Qt as a dependency is a big ask. – Rotsiser Mho Aug 26 '19 at 21:44
  • Bundling Qt libs work smooth, the only pain are Qt plugins e.g. QtQuick stuff that is still open/discussed in bugreports after many years... (i.e. it requires custom steps to bundle all stuff inside final binary) – Ľubomír Carik Aug 26 '19 at 23:43
  • This question has nothing to do with Qt, which is why I think introducing it as a dependency to a project just to use *macdeployqt* is not a good solution. – Rotsiser Mho Aug 31 '19 at 12:40
  • Using `macdeployqt` wouldn’t necessarily introduce any Qt dependencies, it does not officially support third-party libs (although sometimes it works). – Richard Barber Oct 28 '19 at 20:39