How to append values in xcconfig variables?

前端 未结 8 727
借酒劲吻你
借酒劲吻你 2020-12-12 21:58

I\'m using Xcode and .xcconfig files. I\'m trying to append some values in the preprocessor definitions, but I simply can\'t make it work.

I tried the following (as

相关标签:
8条回答
  • 2020-12-12 22:48

    For reasons stated in other answers to this question, you can't inherit values easily.

    I recommend defining your settings in cascade. Let's assume APP is your project prefix and make this simple defining only a few CFLAGS:

    platform.xcconfig:

    APP_PLATFORM_CFLAGS = -DMAS=1
    

    project.xcconfig:

    #include "platform.xcconfig"
    APP_PROJECT_CFLAGS = -DBETA=1
    

    target-one.xcconfig:

    #include "project.xcconfig"
    APP_TARGET_CFLAGS = -DSUPER_COOL=1
    #include "merge.xcconfig"
    

    target-two.xcconfig:

    #include "project.xcconfig"
    APP_TARGET_CFLAGS = -DULTRA_COOL=1
    #include "merge.xcconfig"
    

    merge.xcconfig:

    OTHER_CFLAGS = $(inherited) $(APP_PLATFORM_CFLAGS) $(APP_PROJECT_CFLAGS) $(APP_TARGET_CFLAGS)
    

    Then, you'll base each of your targets build configurations on target-xxx.xcconfig. A real project will use more complex setups, using a configuration file for the project and a different one for the target, but you get the idea.

    Also, remember that $(inherited) refers to higher level in the hierarchy, not earlier. For instance, it inherits from Project level at Target level. Not sure if this apply to Xcode 4 too.

    This is a simplification of GTM, go there to learn more.

    0 讨论(0)
  • 2020-12-12 22:49

    I think I've stumbled on a slightly better approach while trying to integrate the Cocoapods xcconfig files into my own. I like to set the following in my projects

    GCC_PREPROCESSOR_DEFINITIONS = CONFIGURATION_$(CONFIGURATION)
    

    Unfortunately this conflicts with the definitions that comes with the Pods.xcconfig. As is stated elsewhere $(inherited) doesn't work as expected. What does work is the following

    GCC_PREPROCESSOR_DEFINITIONS[config=*] = CONFIGURATION_$(CONFIGURATION) $(inherited)
    

    UPDATE:

    If you need to override a setting for a particular configuration then you'd be tempted to write something like

    GCC_PREPROCESSOR_DEFINITIONS[config=*] = CONFIGURATION_$(CONFIGURATION) $(inherited)
    GCC_PREPROCESSOR_DEFINITIONS[config=Debug] = DEBUG=1 CONFIGURATION_$(CONFIGURATION) $(inherited)
    

    Sadly this won't work BUT putting the second declaration into a file that only get's loaded by the Debug configuration will properly override setting.

    0 讨论(0)
提交回复
热议问题