3

We develop an open source framework that can be built with various preprocessor flags to enable/disable certain features. It is crucial that these features are only compiled when they are actually needed (by the framework user) as they may have App Store submission implications. It's not an option to configure the features at runtime.

The framework comes as a standard iOS framework, i.e., it's dynamically linked and embedded within the host app, and therefore has its own build settings that are separate from the host app's.

To allow for the above-mentioned configuration, the framework project uses an xcconfig file from its root directory that includes a hook to an optional file outside of the framework directory:

#include? "../FrameWorkConfigurationFlags.xcconfig"

This allows users to provide a configuration file outside of the framework directory, which is important if you use git submodules, for instance.

We also provide a sample app that links/embeds the framework (via Xcode subprojects) and needs to provide a configuration, but lives in the same directory/repository as the framework, and thus cannot use the hook.

HostAppDir
|-- FrameWorkConfigurationFlags.xcconfig
`-- Framework
    |-- ConfigurationWithHook.xcconfig
    `-- SampleApp
        `-- SampleConfigurationFlags.xcconfig

Any creative ideas how to solve this problem? A few things we have considered:

  • Adding a second hook to a path within the framework directory/repository, which doesn't work because the sample app's configuration would always be used if the user checks out the framework including the sample app

  • Maybe there's an environment variable that can be used to detect the source directory of the host app? Something along the lines of #include? "$(SRCROOT)/FrameWorkConfigurationFlags.xcconfig", but where $(SRCROOT) is not the framework's directory, but the host app's. It seems there's special treatment for <DEVELOPER_DIR>, but I couldn't use general environment variables in include paths either.

  • We could refactor our sample app to use CocoaPods to check out and embed the framework, and ignore the local copy that is already there, but we prefer not to require any additional technologies to use the sample app

  • Write a custom build script phase...

hagi
  • 11,503
  • 3
  • 35
  • 48

0 Answers0