How to compile a project with app and library in the same workspace with different configuration names?

前端 未结 3 1211
渐次进展
渐次进展 2020-12-04 13:25

I am developing an app and I am using an open source component.

I have a workspace containing both MyApp.xcodeproj and Component.xcodeproj. My app

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-04 13:59

    You can get your project to compile with some tweaks to your app’s settings.

    I suggest you to modify all settings at the project level so that all your targets can inherit these settings.

    1. Add a new DEFAULT_CONFIGURATION user-defined setting and define your configuration mapping. This is how it should look like:

      Default Configuration Screenshot

    2. Set FRAMEWORK_SEARCH_PATHS to $(BUILD_DIR)/$(DEFAULT_CONFIGURATION)-$(PLATFORM_NAME) for all configurations, add Any OS X SDK variants and set the value to $(BUILD_DIR)/$(DEFAULT_CONFIGURATION). Set HEADER_SEARCH_PATHS to $(FRAMEWORK_SEARCH_PATHS)/include and LIBRARY_SEARCH_PATHS to $(FRAMEWORK_SEARCH_PATHS). This is how it should look like:

      Search Paths Screenshot

      This step is quite tedious, it can be automated with the xcproj tool and by running this script in your project directory. Edit your configurations mapping as needed.

      #!/bin/bash
      
      CONFIGURATIONS=( "App Store:Release" "In House:Release" "Debug:Debug" )
      
      for CONFIGURATION in "${CONFIGURATIONS[@]}"; do
          xcproj --configuration "${CONFIGURATION%%:*}" write-build-setting DEFAULT_CONFIGURATION "${CONFIGURATION#*:}"
      done
      
      xcproj write-build-setting 'FRAMEWORK_SEARCH_PATHS' '$(BUILD_DIR)/$(DEFAULT_CONFIGURATION)-$(PLATFORM_NAME)'
      xcproj write-build-setting 'FRAMEWORK_SEARCH_PATHS[sdk=macosx*]' '$(BUILD_DIR)/$(DEFAULT_CONFIGURATION)'
      
      xcproj write-build-setting 'HEADER_SEARCH_PATHS' '$(FRAMEWORK_SEARCH_PATHS)/include'
      xcproj write-build-setting 'LIBRARY_SEARCH_PATHS' '$(FRAMEWORK_SEARCH_PATHS)'
      
    3. If the component is distributed as a static library, you are done here. If the component comes as a framework you have to update its path reference by editing your project.pbxproj file in a text editor. In the PBXFileReference section (under /* Begin PBXFileReference section */) find Component.framework and update its path like this:

      name = Component.framework; path = "../$(DEFAULT_CONFIGURATION)/Component.framework"; sourceTree = BUILT_PRODUCTS_DIR; };
      

      Also make sure that the sourceTree is set to BUILT_PRODUCTS_DIR, i.e. relative to built products. Once you edited the project file, this should look like:

      Location Screenshot

    Your project should now build as expected.

提交回复
热议问题