xcodemacosxcodebuildinstall-name-tool

XCodebuild specifying target and linking a framework


I have a project in which I need to produce two executables, one in 64-bit (x64_86) and the other in 32-bit (i386); they cannot be combined.

The project includes linking to a 3rd party framework.

Compilation in XCode works without issue.

When using xcodebuild on its own (no parameters passed), the 64-bit binary is built as expected and the 3rd party framework is linked in with the correct reference. Using otool -L shows

@rpath/Frameworks/thirdpartybundle.framework/Versions/A/thirdpartybundle

However, when I compile the 32-bit binary, the referenced framework is wrong and otool -L shows this: -

@rpath/Frameworks/mytool32.framework/Versions/A/mytool32

Where 'mytool32' is the product name passed to xcodebuild. I've tried building the 32 bit versions with the following commands: -

xcodebuild -project mytool.xcodeproj -scheme mytool VALID_ARCHS=i386 CURRENT_ARCH=i386 ONLY_ACTIVE_ARCH=NO ARCHS=i386 PRODUCT_NAME=mytool32

And I've also tried this: -

xcodebuild -project mytool.xcodeproj -destination 'platform=OS X,arch=i386' -target mytool PRODUCT_NAME=mytool32

Either way, they both produce a binary with the wrong path to the framework, substituting the product name instead of the framework name.

How can I build the 32-bit version using xcodebuild, specifying the product name, but with the correct paths to the third party framework?


Solution

  • After experimenting, the easiest method to produce the two executables (one 32 and one 64 bit) for using with xcodebuild is to use XCode to create a second target, then copy the code from the first target to be used by the second, before using xcodebuild.

    This allows setting the build settings for each target independently, which can then be used with xcodebuild.

    Assuming we have two targets; app_x64 (64-bit with product name set to app) and app_x32 (32-bit with product name set to app32), we can build both with xcodebuild: -

    xcodebuild -target app_x64
    xcodebuild -target app_x32
    

    This produces the required executables. If using a 3rd party framework, just ensure to set up the dependencies for both targets.