具有多个.xcconfig文件和cocoapods的复杂Xcode项目

时间:2023-01-27 10:44:24

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.

我正在开发一个iOS项目,我们处于不幸的情况,我们必须使用的一些库有两个版本。用于调试的版本和用于生产的版本。无法使用生产库进行调试。并且同样不可能使用调试库。在生产中。

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.

为了解决这个问题,我们在项目中设置了多个目标(一个用于调试,一个用于生产)。这些目标使用单独的.xcconfig文件(App-Debug.xcconfig和App-Production.xcconfig)为每个目标定义:LIBRARY_SEARCH_PATHS,HEADER_SEARCH_PATHS和OTHER_LDFLAGS。

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.

这一切都很有效,但是手动跟踪所有第三方依赖项是一件痛苦的事。因此我们决定开始使用CocoaPods来管理我们的一些第三方依赖项。

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.

但由于这些“两个版本”库我们无法按预期使用Pods.xcconfig,但需要将其中的设置附加到我们自己的App-Debug.xcconfig和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.

我不确定这样做的正确方法,因为我尝试的所有内容似乎都无法编译,因为无法找到我的pod。

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.

我们可以看到Pods.xcconfig和我们自己的App-Debug.xcconfig都设置了: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.

我需要的是将Pods.xcconfig中声明的值附加到我们在App-Debug.xcconfig中声明的值。

We are using Xcode 4.6 and building for iOS 4.3.

我们正在使用Xcode 4.6并为iOS 4.3构建。

2 个解决方案

#1


15  

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

您的podfile可以支持此功能。你最终应该得到这样的东西

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.

这将生成两个xcconfig文件,每个目标一个。

#2


1  

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).

不要使用两个目标,而是尝试在配置中为XXX_LIBRARY_PATH定义不同的值(遗憾的是在GUI中最简单)。如果您只有两个配置并且命名正确,您甚至可以执行类似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].

一个目标配置不可能将属性附加到另一个目标配置; “继承”严格来说是SDK→Project [Config]→Target [Config]。

#1


15  

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

您的podfile可以支持此功能。你最终应该得到这样的东西

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.

这将生成两个xcconfig文件,每个目标一个。

#2


1  

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).

不要使用两个目标,而是尝试在配置中为XXX_LIBRARY_PATH定义不同的值(遗憾的是在GUI中最简单)。如果您只有两个配置并且命名正确,您甚至可以执行类似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].

一个目标配置不可能将属性附加到另一个目标配置; “继承”严格来说是SDK→Project [Config]→Target [Config]。