具有多个 .xcconfig 文件和 cocoapods 的复杂 Xcode 项目
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15258343/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
complex Xcode project with multiple .xcconfig files and cocoapods
提问by cvknage
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:
我们的 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:
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:
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.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 构建。
采纳答案by Patrick Tescher
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 文件,每个目标一个。
回答by tc.
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]。