How do I reference a dependent project built with a different configuration in Xcode?

微笑、不失礼 提交于 2019-12-05 04:06:46

问题


I have two Xcode projects: Super and Sub. Super has a custom configuration: Enterprise. Sub only has the default configurations: Debug and Release. Super has a target dependency on Sub. When I build Super with the Enterprise configuration, Sub builds with its default configuration: Release. This yields the following hierarchy:

Build
|-Products
  |-Enterprise-iphoneos
    |-Super.app
  |-Release-iphoneos
    |-libSub.a
    |-Sub
      |-Sub.h

Clang fails to build because libSub.a and Sub/Sub.h is normally in the same directory as Super.app, but instead is in a different directory because Sub built with the Release configuration instead of Enterprise. I control both projects, so I could easily add an Enterprise configuration to Sub, but I feel like there must be a magical incantation of Xcode Build Settings to make this work.


回答1:


I have solved exactly the same problem by using Xcode Configuration Files in my parent project - typically your application.

These are the steps I took:

  1. Create a Base Configuration file in Xcode via New > Other > Configuration File.

  2. Write your base xcconfig file, mine looks a bit like this:

    /// Configure Search Paths
    HEADER_SEARCH_PATHS = "$(BUILT_PRODUCTS_DIR)/include" "$(BUILT_PRODUCTS_DIR)/usr/local/include"
    LIBRARY_SEARCH_PATHS = "$(SRCROOT)/../Externals/Libraries/GoogleAnalytics"
    
    /// Linker flags
    OTHER_LDFLAGS=-ObjC -all_load
    
  3. The thing to note here, is that $(BUILT_PRODUCTS_DIR) is the concatenation of:

    $(BUILD_DIR)/$(CONFIGURATION)-$(PLATFORM_NAME)
    
  4. Write a specialised configuration for a custom configuration. I created an Ad Hoc configuration which duplicated Release, therefore my search paths now look like this:

    #include "BaseConfig.xcconfig"
    
    /// Ad Hoc search paths
    HEADER_SEARCH_PATHS = "$(BUILD_DIR)/Release-$(PLATFORM_NAME)/include" "$(BUILD_DIR)/Release-$(PLATFORM_NAME)/usr/local/include"
    LIBRARY_SEARCH_PATHS = "$(BUILD_DIR)/Release-$(PLATFORM_NAME)" "$(SRCROOT)/../Externals/Sources/GoogleAnalytics"
    

Then in your application's project's Info tab select your configurations, to use the Base Configuration for Debug and Release, and then the special one for your custom configuration.



来源:https://stackoverflow.com/questions/15347875/how-do-i-reference-a-dependent-project-built-with-a-different-configuration-in-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!