2 Replies
      Latest reply on Feb 4, 2020 4:51 PM by jonprescott
      flarosa Level 1 Level 1 (0 points)



        I want to make a build script that takes different actions based on a preprocessor macro. For example, I tried to write it this way:


        if [ "${myFlag}" = "1" ]; then


        Where "myFlag" is a preprocessor macro that I defined in the build settings.


        It doesn't appear to work the way I wrote it. Is there a way to do this?

        • Re: How to access preprocessor macros from build script?
          john daniel Level 4 Level 4 (600 points)

          Did you try omitting the braces?

          • Re: How to access preprocessor macros from build script?
            jonprescott Level 2 Level 2 (90 points)

            You need to omit the braces.


            When you say "preprocessor macros", are you setting up a user-defined environment build setting, or are you actually assigning values to the "Preprocessor Macros" build setting?  If it's the latter, I don't think pre-processor macro definitions are available to  run scripts except through the GCC_PREPROCESSOR_MACROS environment variable which is set from the build settings.  If you are setting the value for "myflag" in the build settings via the GCC_PREPROCESSOR_MACROS (the "Preprocessor Macros" build setting), you'll have to parse the whole macro definition to find "myflag"


            You can set user-defined environment variables for Xcode via .xcconfig files (look up "xcconfig" files in Xcode documentation, and/or the Internet).