How to get XCode to use bash environment variables.

Discussion in 'Programmer Help' started by phil.pellouchoud@gmail.com, Jul 11, 2007.

  1. Guest

    I would like to get XCode to use bash environment variables.

    For example in:

    Project -> Edit Project Settings -> [ Build ] -> Header Search Paths

    I would like to be able to do something like this:

    $(mypath)/include

    However, when I type that in there, all I see is "/include" - it's
    pretty bizarre. If I bring up a terminal window, and do a "set" (with
    no arguments), I can see my environment variable (mypath).

    I saw something on a wxWiki: http://www.wxwidgets.org/wiki/index.php/Setting_Environment_Variable_For_XCode

    Which described something similar to what I wanted to do, but it looks
    like if I do that, I can't 1.) script it (i.e. I want to have a
    setup.sh that developers can simply run to setup) and 2.) have
    environment variables depend on other environment variables (i.e.
    mypath=$(myotherpath)/mypath).

    Does anyone have ideas on how I can do this?

    Thanks in advance,

    -phil

    {D85068A3-65DA-4661-933C-AA34590E10F5}
     
    , Jul 11, 2007
    #1
    1. Advertisements

  2. Guest

    The reason to do this is because I would like to have things based on
    environment variables which I can easily change, rather than having
    tons of projects with hardcoded paths, such that when I need to change
    the path of something, I'll have to change it in every single project.

    For example - suppose I am using a third party library called "foo",
    so then the header file is stored in ~/thirdparty/foo/1.0/include.
    Suppose I have a bunch of projects that all use this third party
    library. The change that could occur is that I get 1.1 of foo (they
    fixed some bugs, etc...), so I put that in "~/thirdparty/foo/1.1/
    include". If I hardcode all the paths in the projects, then I have to
    go into every project and update the header directories to point to
    the 1.1 directory - no fun. If I had an environment variable call
    "$foo_include" then it would simply be a matter of changing that
    environment variable to point to the new location.

    -phil
     
    , Jul 12, 2007
    #2
    1. Advertisements

  3. David Stone Guest

    An alternative is to use symbolic links. So "~/thirdparty/foo/include"
    would actually point at "~/thirdparty/foo/1.0/include" until version
    1.1 came out, when the install script changes it to point at
    "~/thirdparty/foo/1.1/include"

    This has the added benefit of making roll-backs easier if it turns out
    that version 1.1 is buggier than 1.0...
     
    David Stone, Jul 12, 2007
    #3
  4. Guest

    I did try to do this by simply creating a setup.xcconfig file and
    adding "HEADER_SEARCH_PATHS = " into it and then went to project ->
    edit project settings -> "Based on: " setup.xcconfig and it still
    didn't work...

    -phil
     
    , Jul 15, 2007
    #4
  5. ohad New Member

    Joined:
    Oct 20, 2015
    Messages:
    1
    Likes Received:
    0
    A couple of comments for future readers (apologies for the resurrection, but this post comes up high in related searches):
    1. bash environment variables (export FOO=BAR) will work if XCode is started from the same bash session (open -a xcode)
    2. In order to set environment variables that are available to GUI aplications, starting from Mountain Lion launchctl should be used: http://codepulsive.blogspot.com.au/2013/11/setting-environment-variables-in-os-x.html
    3. In order to use environment varialbes in XCode 7, the following command must be issued: defaults write com.apple.dt.Xcode UseSanitizedBuildSystemEnvironment -bool NO
     
    ohad, Oct 20, 2015
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.