There is a more reliable way to do this.
When you run the โRun Scriptโ build phase, Xcode lists all the pre-processor definitions that were made using the Project Build Options , inside one environment variable called GCC_PREPROCESSOR_DEFINITIONS .
For the definitions that you need to access from the script, define them in the Project Build Options . If you move them from the source code, but you need to maintain the reliability of your source (for example, you also compile this source outside the Xcode project), you can additionally save the source definitions wrapped in #ifndef / #endif - thereby making them passive values โโby by default.
Now, to get them as Script variables, simply evaluate the contents of GCC_PREPROCESSOR_DEFINITIONS in the "Run Script" build phase, for example:
eval "${GCC_PREPROCESSOR_DEFINITIONS}"
If you want to make sure that the script has a default value for one or more specific variables, define them above this estimate.
source share