I'm using Xcode 3.2.6, MacOSX.
I have a globally visible environment setting:
ICU_SRC=~/Documents/icu/source
This really is an environment setting, it's set at login time. When I open up Terminal, it's there.
In my project, under Header Search Paths I've added this:
$(ICU_SRC)/i18n
$(ICU_SRC)/common
These expand correctly when I compile inside the IDE. When I look at the build results, I see this:
-I/Users/eric.grunin/Documents/icu/source/i18n
-I/Users/eric.grunin/Documents/icu/source/common
When I build from the command line, however, it fails. What I see is this:
-I/i18n
-I/common
Here's the command I'm using to compile:
/usr/bin/env -i xcodebuild -project my_project.xcodeproj -target "my_program" -configuration Release -sdk macosx10.6 build
What am I doing wrong?
Edited to add:
Apple explains Setting environment variables for user processes
Sometimes it works better if you specify the env vars before the xcodebuild command, as in
# NOT this
xcodebuild ... options ... SOMEVAR=somevalue
# But this instead works better
SOMEVAR=somevalue xcodebuild ... options ...
This works especially well for PRODUCT_NAME when working with cocoapods.
You need to "connect" xcode build to Xcode using your scheme.
From xcodebuild side : xcodebuild ... options ... yourVAR=yourValue
From Xcode -> Product -> Scheme -> Edit Scheme... -> Arguments -> Environment Variables (name) someKey (Value) $yourVAR
The key is that the name of yourVAR in xcodebuild will be referred from Xcode arguments, by using '$'.
In order to access the environment variable later from code, you need to use
ProcessInfo.processInfo.environment["someKey"]

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With