114

In Xcode, I know that you can get variables such as PROJECT_DIR to use in some situations, such as a run script build phase. I am wondering if it's possible to get the build type (i.e., Release or Debug). Any ideas?

2

3 Answers 3

161

The best source is probably Apple's official documentation. The specific variable you are looking for is CONFIGURATION.

7
  • 10
    I love the way that Xcode refuses to show that page if you type in "build settings" in a search box - you get the OTHER kind of build setting, with no reference to these variables. Ditto if you put "build variables". Someone should teach Apple how to write a search algorithm :)
    – Adam
    Commented Sep 5, 2010 at 15:49
  • 29
    If you're trying to create a "run script build phase", you can start off this script by typing "env" (without the quotes) as the first line of your bash shell script (or the equivalent command for the shell you're using) and build your project. This will output all of the environment variables that are available to you. You can use this in conjunction with the documentation to make sure you're getting the data that you expected.
    – Ryan H.
    Commented Mar 9, 2011 at 13:47
  • 3
    I think I've wasted half an hour trying to find the docs listing/explaining environment variables available to scripts. I submitted an "enhancement" request asking why they can't just put one of those round question-mark buttons in there with a link to the proper help page. Great suggestion HZC, though I wish it wasn't necessary.
    – Brian
    Commented Feb 14, 2012 at 15:07
  • 3
    Also sad that the basic $PROJECT_DIR is not mentioned anywhere in that official document. I guess it's just a (better named) alias for $SRCROOT. Commented Jul 25, 2014 at 16:27
  • 4
    Apple likes to periodically rearrange all of their documentation and break all existing links. Someone will have to hunt down the new link.
    – smorgan
    Commented Sep 27, 2016 at 6:04
24

Here's a list of the environment variables. I think you might want CURRENT_VARIANT. See also BUILD_VARIANTS.

3
  • Ok, so when I use char* cv = getenv("CURRENT_VARIANT"); I get NULL. What am I missing?
    – Brooks
    Commented Dec 31, 2013 at 16:06
  • 1
    The other answer is right. This isn't. CONFIGURATION is what they want.
    – Baxissimo
    Commented Nov 8, 2014 at 2:00
  • And that's not even the full list ... half the truth
    – Evils
    Commented Feb 27, 2015 at 4:33
9

They're not all documented. For example, you won't find ARCHIVE_PATH, MARKETING_VERSION (the version string set in Xcode) in Naaff's or smorgan's answer. These 2 are very common pieces of information someone would need! Here's a list of all of them I got: https://gist.github.com/ben-xD/c063b0ca2c33684de1eb379bb9d6405d

How I got them

I found the best way was to print them using set, I just wrote this including a method to list all the environment variables available.

Add this to your run script (either Archive post run script, or your build phases run script, etc.):

#!/bin/sh
exec > ${PROJECT_DIR}/environment_variables.log 2>&1
set

Look in environment_variables.log and you'll see them all.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.