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?
-
5possible duplicate of Canonical list of Xcode Environment Variables– mmmmmmCommented Apr 22, 2013 at 14:37
-
Possible duplicate of How do I print a list of "Build Settings" in Xcode project?– Max MacLeodCommented Jan 11, 2018 at 13:57
3 Answers
The best source is probably Apple's official documentation. The specific variable you are looking for is CONFIGURATION.
-
10I 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 :)– AdamCommented Sep 5, 2010 at 15:49
-
29If 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
-
3I 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.– BrianCommented Feb 14, 2012 at 15:07
-
3Also 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
-
4Apple likes to periodically rearrange all of their documentation and break all existing links. Someone will have to hunt down the new link.– smorganCommented Sep 27, 2016 at 6:04
Here's a list of the environment variables. I think you might want CURRENT_VARIANT
. See also BUILD_VARIANTS
.
-
Ok, so when I use char* cv = getenv("CURRENT_VARIANT"); I get NULL. What am I missing?– BrooksCommented Dec 31, 2013 at 16:06
-
1The other answer is right. This isn't. CONFIGURATION is what they want. Commented Nov 8, 2014 at 2:00
-
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.