How to use environment variable in xcconfig #include?
Asked Answered
S

5

6

in my project, I want to refer to an other xcconfig file, located in InDesign SDK. As this SDK may be installed at different locations, depending upon the machine, I prefer to declare an environment variable for locating it.

Nest step is obviously to use variable (aptly named ID_CS5_SDK_DIR) in my xcconfig include directive.

Unfortunatly, when I try the simple

// InDesign sdk project build settings (based on common build settings)
#include "$(ID_CS5_SDK_ROOT)/build/mac/prj/_shared_build_settings/common.xcconfig"

XCode throws me a

 [WARN]AutocatPlugin.xcconfig line 7: Unable to find included file "$(ID_CS5_SDK_ROOT)/build/mac/prj/_shared_build_settings/common.xcconfig"

How can I make it work ?

Sesquioxide answered 14/12, 2011 at 9:49 Comment(1)
dude pay attention to the answer you accept...Buddleia
I
6

I've been trying to do this too and also came to the conclusion that it is not possible.

Incredulity answered 23/2, 2012 at 21:38 Comment(0)
B
3

I once tried to achieve that and came to the conclusion that you can't. I would be happy if someone proves us it's possible though then delete my answer

Buddleia answered 17/2, 2012 at 15:7 Comment(1)
Not directly. But you can reference the variables defined in the xcconfig in your app's info.plist, and then access the info.plist. Saw it here: bogardon.github.io/xcode/environment-variables/2013/05/20/…Briquet
Z
0

It seems like .xcconfig files can only DEFINE and set value to environment variables (which prevail only throughout the build session) but not USE or evaluate environment variables.

Maybe it is because .xcconfig files serve as a base layer of build-settings, and are not parsed.

Zawde answered 2/1, 2017 at 12:51 Comment(0)
C
0

Unfortunately this is not possible, but instead of making one include the other, you can use two different xcconfig files per target. Just select one for the Project and one for the Target.

enter image description here

Cousin answered 31/3, 2018 at 22:19 Comment(0)
O
-4

If you put the environment variable in /etc/config/launchd.conf and then reboot it will be accessible to the .xcconfig file.

Short Instructions for experienced users:

Edit the read-only file /etc/launchd.conf and add 'setenv VARIABLENAME /FOLDER/PATH' to the file, then reboot.

Steps For Inexperienced Users

  1. Open Application/Utilities/Terminal, and enter

    sudo nano /etc/launchd.conf

  2. Create the Environment Variable by adding a line like

    setenv VARIABLENAME FOLDER/PATH

    and then pressing ENTER.

  3. Save the file using Ctrl-O, Ctrl-M, (Possibly Ctrl-Y to overwrite), then Ctrl-X to exit the editor.
  4. (Optional) type cat /etc/launchd.conf to see that your changes are present
  5. Restart your computer. (Logoff doesn't work)
  6. You can now access the variable in your .xcconfig file as

    $(VARIABLENAME)

Notes:

  • This creates a GLOBAL environment variable, accessible to all users. It probably doesn't make sense to set this to something in your home directory (e.g ~/MyFolder). If you do this, however, you need to use the full pathname, such as /Users/MyUserName/MyFolder).

References:

Orchidaceous answered 12/2, 2014 at 23:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.