2

QUICK VERSION: I have a library of code that I'm creating a Cocoapods spec file for. It needs different compiler flags based on the architecture. Is that possible?

Explanatory background: One of the library's files contains some ARM NEON intrinsics code. For armv7 & armv7s the flags are:

s.compiler_flags = '-mfloat-abi=softfp', '-mfpu=neon', '-mcpu=cortex-a9'

The last flag causes a (totally reasonable) compile error on arm64.

Xcode supports per-architecture flags in the Build Settings area, so this has been building fine, until now when a podspec wrapper is required.

Is there a way to configure a CocoaPods spec with per-architecture flags?

Graham Perks
  • 23,007
  • 8
  • 61
  • 83

1 Answers1

1

One solution, I found via Can you set architecture specific Build Settings in an .xcconfig file in Xcode 4.3?, use xcconfig:

# Common flags
s.compiler_flags = '-mfloat-abi=softfp', '-mfpu=neon'

# Per-arch flags
s.xcconfig = { 'OTHER_CFLAGS[arch=armv7]'  => '$(inherited) -mcpu=cortex-a9' ,
               'OTHER_CFLAGS[arch=armv7s]' => '$(inherited) -mcpu=cortex-a9'}

Minor CocoaPods bug here, the $(inherited) flag double up the parameters in the Pods.xcconfig:

OTHER_CFLAGS[arch=armv7] = $(inherited) -mcpu=cortex-a9 $(inherited) -mcpu=cortex-a9
OTHER_CFLAGS[arch=armv7s] = $(inherited) -mcpu=cortex-a9 $(inherited) -mcpu=cortex-a9

I wonder if there's a more spec-friendly way to do this via the actual compiler-flags flag?

Community
  • 1
  • 1
Graham Perks
  • 23,007
  • 8
  • 61
  • 83