Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

complex Xcode project with multiple .xcconfig files and cocoapods

I am working on an iOS project where we are in the unfortunate situation that some of the libraries we must use comes in two versions. A version for debug, and a version for production. It is not possible to debug with the production lib. and it is likewise not possible to use the debug lib. in production.

To solve this problem we have set up multiple targets (one for debugging and one for production) in the project. These targets use separate .xcconfig files (App-Debug.xcconfig and App-Production.xcconfig) to define the: LIBRARY_SEARCH_PATHS, HEADER_SEARCH_PATHS & OTHER_LDFLAGS for each target.

This all works just great, but it is becomming a pain to keep track of all our third party dependencies manually. Hence we decided to start using CocoaPods to manage some of our third party dependencies.

But the because of these "two version" libraries we can't use the Pods.xcconfig as intended, but need to append the settings from it to our own App-Debug.xcconfig and App-Production.xcconfig.

I am not sure of the right way to do this, as everything I try, seems to not compile because my pods can't be found.

Our Pods.xcconfig:

ALWAYS_SEARCH_USER_PATHS = YES
HEADER_SEARCH_PATHS = ${PODS_HEADERS_SEARCH_PATHS}
LIBRARY_SEARCH_PATHS = "$(PODS_ROOT)/TestFlightSDK"
OTHER_LDFLAGS = -ObjC -lTestFlight -lz -framework SystemConfiguration -framework UIKit
PODS_BUILD_HEADERS_SEARCH_PATHS = "${PODS_ROOT}/BuildHeaders" "${PODS_ROOT}/BuildHeaders/AFNetworking" "${PODS_ROOT}/BuildHeaders/TestFlightSDK"
PODS_HEADERS_SEARCH_PATHS = ${PODS_PUBLIC_HEADERS_SEARCH_PATHS}
PODS_PUBLIC_HEADERS_SEARCH_PATHS = "${PODS_ROOT}/Headers" "${PODS_ROOT}/Headers/AFNetworking" "${PODS_ROOT}/Headers/TestFlightSDK"
PODS_ROOT = ${SRCROOT}/Pods

App-Debug.xcconfig:

#include "Config-XXX.xcconfig"
#include "Config-Tesseract.xcconfig"
#include "Config-AppMeasurement.xcconfig"
#include "Config-Libxml2.xcconfig"
#include "Config-Frameworks.xcconfig"

LIBRARY_SEARCH_PATHS = $(inherited) $(XXX_LIBRARY_SEARCH_PATH_DEBUG) $(TESSERACT_LIBRARY_SEARCH_PATH) $(APPMEASUREMENT_LIBRARY_SEARCH_PATH)

HEADER_SEARCH_PATHS = $(inherited) $(TESSERACT_HEADER_SEARCH_PATH) $(LIBXML2_HEADER_SEARCH_PATH) $(XXX_HEADER_SEARCH_PATH)

OTHER_LDFLAGS = $(inherited) -lz -lxml2 -lstdc++ -all_load -ObjC -lXXXLibrary $(APPLE_FRAMEWORKS)

App-Production.xcconfig:

#include "Config-XXX.xcconfig"
#include "Config-Tesseract.xcconfig"
#include "Config-AppMeasurement.xcconfig"
#include "Config-Libxml2.xcconfig"
#include "Config-Frameworks.xcconfig"

LIBRARY_SEARCH_PATHS = $(inherited) $(XXX_LIBRARY_SEARCH_PATH_PRODUCTION) $(TESSERACT_LIBRARY_SEARCH_PATH) $(APPMEASUREMENT_LIBRARY_SEARCH_PATH)

HEADER_SEARCH_PATHS = $(inherited) $(TESSERACT_HEADER_SEARCH_PATH) $(LIBXML2_HEADER_SEARCH_PATH) $(XXX_HEADER_SEARCH_PATH)

OTHER_LDFLAGS = $(inherited) -lz -lxml2 -lstdc++ -all_load -ObjC -lXXXLibrary $(APPLE_FRAMEWORKS)

Config-XXX.xcconfig:

XXX_LIBRARY_SEARCH_PATH_DEBUG = "$(SRCROOT)/External/XXX"
XXX_LIBRARY_SEARCH_PATH_PRODUCTION = "$(SRCROOT)/External/XXX/LibProd"

XXX_HEADER_SEARCH_PATH = "$(SRCROOT)/External/XXX/headers"

As we can see both the Pods.xcconfig and our own App-Debug.xcconfig sets the: LIBRARY_SEARCH_PATHS, HEADER_SEARCH_PATHS & OTHER_LDFLAGS.

What I need is to have the values declared in Pods.xcconfig appended to the values we declare in App-Debug.xcconfig.

We are using Xcode 4.6 and building for iOS 4.3.

like image 374
cvknage Avatar asked Mar 06 '13 21:03

cvknage


2 Answers

Your podfile can support this. You should end up with something like this

platform :ios, "5.0"
link_with ['App', 'App-Debug'] 

pod 'Shared-Pod'

target :App, :exclusive => true do
  pod 'Normal-Pod'
end

target :App-Debug, :exclusive => true do
  pod 'Debug-Pod'
end

This will generate two xcconfig files, one for each target.

like image 100
Patrick Tescher Avatar answered Nov 06 '22 22:11

Patrick Tescher


Instead of using two targets, try defining different values for XXX_LIBRARY_PATH in the configuration (easiest in the GUI, sadly). If you only have two configurations and they are named appropriately, you can even do something like XXX_LIBRARY_PATH = FooPath/$(CONFIGURATION).

It is not possible for one target config to append properties to another; the "inheritance" is strictly SDK → Project[Config] → Target[Config].

like image 1
tc. Avatar answered Nov 06 '22 22:11

tc.