Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using CMake to copy .frameworks to iOS app bundle

A library I'm using recently switched to distribution as a .framework.

In my existing CMake file, I've been successful at getting it to link with my iOS app, but am getting:

dyld: Library not loaded: @rpath/Pizza.framework/Pizza
  Referenced from: /var/mobile/Containers/Bundle/Application/D71ED298-C287-4B2F-8AFA-710A14C06D75/pizzashop.app/pizza
  Reason: image not found

when I install it from Xcode. If I manually add it to my xcode project, in the "embedded binaries" section then I'm good (see image below)

enter image description here

So I've concluded that the problem is getting the .framework into my app bundle. I've come across this question and looked at the linked QT example, but I'm still trying to orient myself here as I'm finding the syntax a bit opaque.

Is CMake's BundleUtilities what I want to use here? In looking at the BundleUtilities example I'm a bit lost:

set(APPS ...)  # paths to executables
set(DIRS ...)   # directories to search for prerequisites
INSTALL(CODE "
   include(BundleUtilities)
   fixup_bundle(\"${APPS}\"   \"\"   \"${DIRS}\")
   " COMPONENT Runtime)

Is this OSX-specific or can I apply it similarly to iOS?

like image 363
John Carter Avatar asked Jun 08 '16 03:06

John Carter


1 Answers

We didn't end up finding an ideal solution, and ended up doing things a bit more manually than preferred:

  1. We added a custom command we run after the build is complete, but before it is packaged (see CMake's add_custom_command).

  2. The custom command does the following:

    • creates a Frameworks directory under our app bundle folder (make sure it's somewhere where it will get copied in your packaging process).
    • we use cp -aH to copy all frameworks into this Frameworks directory
    • we then re-sign each framework in this directory using: codesign --force --verbose Computers.framework --sign "$2"
  3. Add the Frameworks directory to your search paths:

set_target_properties(${EXE_NAME} PROPERTIES 
        XCODE_ATTRIBUTE_LD_RUNPATH_SEARCH_PATHS "@executable_path/Frameworks")
like image 122
John Carter Avatar answered Sep 20 '22 07:09

John Carter